HDC and CDC

I am attempting for the first time to use CreateDibSection and am puzzled as
to how to use HDC within the MFC framework.  I can't see that CDC returns a
handle, so I am wondering if these two are mutually exclusive.  Is there a
bridge between the handle and the class?


0
srussell2458 (497)
5/7/2004 11:40:10 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
747 Views

Similar Articles

[PageSpeed] 15

"Steve Russell" <srussell@removethisinnernet.net> wrote in message
news:uQoa24INEHA.624@TK2MSFTNGP11.phx.gbl...
> I am attempting for the first time to use CreateDibSection and am puzzled
as
> to how to use HDC within the MFC framework.  I can't see that CDC returns
a
> handle, so I am wondering if these two are mutually exclusive.  Is there a
> bridge between the handle and the class?

For all intents and purposes a CDC is an HDC.
-- 
Jeff Partch [VC++ MVP]


0
jeffp (1711)
5/8/2004 1:54:53 AM
Okay.  I was using a CDC pointer, and that's what was failing.  Thanks,
Jeff!
-----------------
> For all intents and purposes a CDC is an HDC.
> -- 
> Jeff Partch [VC++ MVP]
>
>


0
srussell2458 (497)
5/8/2004 2:13:38 AM
Steve Russell wrote:
> I am attempting for the first time to use CreateDibSection and am puzzled as
> to how to use HDC within the MFC framework.  I can't see that CDC returns a
> handle, so I am wondering if these two are mutually exclusive.  Is there a
> bridge between the handle and the class?
> 
> 

Hi Steve,

CDC is MFC's wrapper around HDC and (most of) the functions that use 
HDCs.  A CDC contains an HDC in its m_hDC member.

For DIB sections in MFC I found this CDIBSectionLite class by Chris 
Maunder to be a big help:

http://www.codeguru.com/Cpp/G-M/bitmap/article.php/c1737/

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
5/8/2004 3:20:19 AM
Thank you very much, Scott.  DIBSection is what I'm working hard on right
now.  I'll definitely check out the article.
---------------------
> Hi Steve,
>
> CDC is MFC's wrapper around HDC and (most of) the functions that use
> HDCs.  A CDC contains an HDC in its m_hDC member.
>
> For DIB sections in MFC I found this CDIBSectionLite class by Chris
> Maunder to be a big help:
>
> http://www.codeguru.com/Cpp/G-M/bitmap/article.php/c1737/
>
> -- 
> Scott McPhillips [VC++ MVP]
>


0
srussell2458 (497)
5/8/2004 4:13:39 AM
Reply:

Similar Artilces:

CDC::m_hAttribDC
Hi, I still have to see a purpose for this data member. With the exception of CMetafileDC, m_hDC is always equals to m_hAttribDC. In my applications, all it does is adding overhead in all the functions that first check if (m_hDC == m_hAttrib) and then check if ( m_hAttrib != NULL). Does someone has a concrete example of where m_hAttribDC is actually helpful? Thank you, olanglois, The attribute DC is also used for print previews. I assume you are doing something really bizarre if you often need to check equality the way you describe. Johan Rosengren Abstrakt Mekanik AB <olanglois@s...

how to get hwnd from hdc
Hi, I know how to get a HDC from HWND, but I am given a HDC from window media player and I want to correlate the mouse position with objects on my HDC. In order to use ScreenToClient I need the HDC's hwnd. How is that possible? If I use GetActiveWindow, I have an offset equal to the media player's menu and button panes. -- ------------------------------------------------------------------------- Music, Recipes, Photos, and more: http://www.sequoiagrove.dk "You don�t frighten us, English pig-dogs! Go and boil your bottoms, sons of a silly person. I blow my nose at you, so...

CDC: buffering
Hello, I presently work on an application which visualises measured data (that are read from a file). This works fine, but when the window of my program has to be redrawn, the displayed data get lost (of course). Since the amount of these data is very high, I could not re-read all data after calling OnDraw, so I need some sort of buffering (of the displayed values). I guess this buffering can be realised by means of the method CreateCompatibleDC, but I don't know how??????? Maybe someone can give me a few advices.... Thanks, Eddi Joseph M. Newcomer wrote: > What I did in thi...

HDC
Env: WindowsXP, VC++6.0 Who can kindly tell me the different about using hDC1 or hDC2 inside OnDraw() below. CView::OnDraw(CDC* pDC) { HDC hDC1 = pDC->m_hDC; HDC hDC2 = ::GetDC(m_hWnd); } TIA William William wrote: > Env: WindowsXP, VC++6.0 > > Who can kindly tell me the different about using hDC1 or hDC2 inside > OnDraw() below. > > CView::OnDraw(CDC* pDC) > { > HDC hDC1 = pDC->m_hDC; > HDC hDC2 = ::GetDC(m_hWnd); > } > > TIA > William The DC passed to OnDraw is special in several ways. It is normally a CPaintDC, which i...

DrawTextW( hdc, strText, -1, rectB, DT_SINGLELINE); #2
Hi, I have a peice of a code for loading a icon and draw the text below the icon on the same button... i was sucessful in loading an icon but when tried with the DrawText() to insert a text, its not working and the problem is with the hdc parameter of DrawText function. void CNewButtonDlg::CallButton() { CString strText(""); //To place the text on the button RECT rectA = {180, 20, 270, 90}; //left, top, right, bottom //To nullify the error that parameter must be a LPRECT and not RECT type i have done so LPRECT rectB = &rectA; CDC my_newButto...

CDC
Hello, My current application reads measuring data from a file and draws a diagram. Since I don't want to lose this diagram in case the window has to be re-drawn, I draw it to an "in-memory bitmap" and copy this bitmap to the screen. I use the following code for the creation of the bitmap: CDC m_MemDC; CBitmap m_Bitmap; CDC *dc = GetDC(); m_MemDC.CreateCompatibleDC(dc); m_Bitmap.CreateCompatibleBitmap(dc, rect.Width(), rect.Height()); m_MemDC.SelectObject(m_Bitmap); Unfortunately, the colors used to display the data, differ from their expected values. For example, if I w...

HDC to HDIB
I need to convert hdc to hdib data of 256 colors of size 180*120 But i didn't get output as required plz help me { BITMAPINFO Binf; BITMAPINFOHEADER bi;int ki; HDC hMemDC = CreateCompatibleDC(hDC); int DCWidth = GetDeviceCaps( hDC, HORZRES ); int DCHeight = GetDeviceCaps( hDC, VERTRES ); StretchBlt(hMemDC,0,0,180,120,hDC,0,0,DCWidth,DCHeight,SRCCOPY); bi.biSize = sizeof(BITMAPINFOHEADER);//40; bi.biWidth = 180;//Let it be constant width for our saving bitmaps bi.biHeight = 120;//Let it be constant height for our saving bitmaps bi.biPlanes = 1; bi.biBitCount = 8; bi.b...

CDC::GetTextExtent question
Hi, I have a function that is to resize a status bar text pane when setting text dynamically. GetTextExtent() seems to think the text is almost twice as wide as it actually is so it leaves too much white space. How come? This is my func.: BOOL CMainFrame::SetStatusText(UINT nID, LPCTSTR lpszText) { int index = m_wndStatusBar.CommandToIndex(nID); if (index < 0) return FALSE; UINT nIDRet, nStyle; int cxWidth; m_wndStatusBar.GetPaneInfo(index, nIDRet, nStyle, cxWidth); ASSERT( nID == nIDRet ); CSize sz(cxWidth, 0); CDC* pDC = m_wndStatusBar.GetDC(); if (pDC) { sz = pDC->...

get font from HDC
Hi, I would like to modify a function used to render some HTML and use the font I have choosen : // C functions int __stdcall DrawHTML( HDC hdc, // handle of device context LPCTSTR lpString, // address of string to draw int nCount, // string length, in characters LPRECT lpRect, // address of structure with formatting dimensions UINT uFormat // text-drawing flags ) { .... /* get the "default" font from the DC */ SavedD...

which CDC
Hello, I am a bit confused as to which dc to call in the following situation. I have a dialog app with a static control on it that I am using to paint a graph on. I am doing the drawing in the lbuttondown function in the dialog class. My qestion is how do I call the device context to paint on the static control. Do I use the CClientDC dc(this); to get the device context of the dialog and do the drawing using this dc, or do I call CClinetDC dc(&m_myStaticControl); or dc = m_myStaticControl.GetDC(); to get the dc of the control, and use it to do the drawing? Are all these ...

HDC and CDC
I am attempting for the first time to use CreateDibSection and am puzzled as to how to use HDC within the MFC framework. I can't see that CDC returns a handle, so I am wondering if these two are mutually exclusive. Is there a bridge between the handle and the class? "Steve Russell" <srussell@removethisinnernet.net> wrote in message news:uQoa24INEHA.624@TK2MSFTNGP11.phx.gbl... > I am attempting for the first time to use CreateDibSection and am puzzled as > to how to use HDC within the MFC framework. I can't see that CDC returns a > handle, so I am wonderin...

HDC Clipping issues
Hi, I am drawing some things in my view. I wish to draw stuff all over the client window, then set a clip rect, such as draw a line from one corner of the screen to another, but make sure that what I draw is only visible on a portion of the view. CMyView::OnDraw(CDC* pDC) { CMyDrawRoutines d; d.BeginDraw(pDC->m_hDC); d.DrawSomeStuffInEntireClientWindow(); CRect rc; GetClientRect(&rc); rc.DelfateRect(100,100,100,100); CRgn rgn; rgn.CreateRectRgnIndirect(&rc); d.SelectClipRgn(&rc); d.MoveTo(0,0); d.LineTo(rcClient.right, rcClient...

CDC/HDC????
I am trying to develop a print screen utility for a windows CE program. I am writing it in Embedded VC++ and running into some weirdness. My plan of action is to use GetClientRect() to find the location of the window, then loop through each pixel in that region and perform a GetPixel() to get the RGB value. My problem is that I need a HDC in order to perform GetPixel(). I used GetActiveWindow() to get an HWND, then used FromWindow() to get a CWnd pointer. I then tried the following line to get an HDC. HDC hdc=pWnd->GetWindowDC(); When I compile though I get the following error. erro...

Get BItmap From HDC
I'm stuck with getting CBitmap object from HDC. I'm using ecw SDK to view ecw files, and I need my soft to return CBitmap object of this .ecw file. in SDK there is a method: DrawImage( HDC DeviceContext, LPRECT pClipRect, IEEE8 dWorldTLX, IEEE8 dWorldTLY, IEEE8 dWorldBRX, IEEE8 dWorldBRY ); wich works just fine, it draws picture into givet device context. DrawImage(hdc, &m_Rect, m_dTLX, m_dTLY, m_dBRX, m_dBRY); CBitmap bitmap; CBitmap * bmp=bitmap.FromHandle((HBITMAP)hdc); is this right?? if DrawImage method drawed picture into HDC already?. If you have an HDC, and it has a bi...

how to make a cdc from a hdc ?
I have a HDC, is it possible to make a CDC from it? thanks, bn You can do this: CDC cDC; cDC.Attach(hdc); tankc "bn" <b@b.com> wrote in message news:%23tSzyNJ$EHA.3372@TK2MSFTNGP10.phx.gbl... > I have a HDC, is it possible to make a CDC from it? > > thanks, > bn > > tthere aretwo ways CDC dc; dc.Attach(hdc); //do ur stuff dc.Detach(); or CDC dc=CDC::FromHandle(hdc); //no need to detach. "bn" wrote: > I have a HDC, is it possible to make a CDC from it? > > thanks, > bn > > > The second one sho...

which factors is the speed of CDC::BitBlt depending on?
hi! i am writing an image processing software where i have 1/60th of a secound to process the newly acquired image inclusively displaying it on screen. on my developer pc (an old pentium III 866MHz + gforce II) it takes me about 4.6 ms to update the image which is ok - on the customer's pc (pentium IV 2.5GHz + gforce IV)it takes about 9.7 ms (which is not ok at all)... it seems that i am not able to figure out which factors the speed of CDC::BitBlt is depending on: i tried to exchange the gaphics device, the operating system, the monitor, the pc itself. i also tried to change the bios ...

Rookie Q: Release HDC?
Hi, Imagine a little class like this: class CMyClass { public: CMyClass(HDC hDC) { m_hDC = hDC; } HDC GetHDC() { return m_hDC; } private: HDC m_hDC; } Now, in my CMyApp::OnView I do this: void CMyApp::OnView(CDC* pDC) { CMyClass mc(pDC->m_hDC); } Now, HDC is just an UINT, and all I am passing is this number. I shouldn't have to do any relasing of anything, do I? Or does my CMyClass class destructor have to do a DeleteObject(m_hDC) or something? Lisa The HDC is part of the CDC class. Be sure not to delete it, or even store it (except i...

why i can not use CDC::TransparentBlt
I am using VC 6.0 sp6 the sdk is the most latest but when i use CDC::TransparentBlt the complier report error the error message is: G:\myproject\game004\Man.cpp(72) : error C2039: 'TransparentBlt' : is not a member of 'CDC' d:\program files\microsoft visual studio\vc98\mfc\include\afxwin.h(636) : see declaration of 'CDC' Error executing cl.exe. Exactly what error do you get? -- Regards, Nish [VC++ MVP] http://www.voidnish.com http://blog.voidnish.com "howyougen" <take..care@tom.com> wrote in message news:OpvMMsFjFHA.132@TK2MSFTNGP10.p...

CDC problems
Ok this is really starting to mess things up for me and ive searched the msdn library until my head hurts, so ive decided to ask you guys. Theres two things im having problems with: 1) Copying an image to a temporary CDC, then stretching it onto another CDC. For example this code generates runtime errors for me (while if i use this->GetDC() it does not): CImage cImg; CDC dcImg, dcTemp; dcImg.Attach(cImg.GetDC()); dcTemp.CreateCompatibleDC(this->GetDC()); dcTemp.StretchBlt(0, 0, 250, 250, &dcImg, 0, 0, 100, 100, SRCCOPY); 2) this->GetDC() will not let me change the brush, p...

How do I tell what HDC has a HBITMAP selected?
How do I tell which HDC has a specific HBITMAP selected? I am using the ImageList_GetImageInfo() function to get direct access to the HBITMAP in the imagelist. The problem is the system keeps this bitmap selected into a memory DC, so I can't select it into my DC to perform a BitBlt from it. There is a KB article that tells me to use the CopyImage function. CopyImage is terribly slow. Any ideas? ...

CDC::SelectClipRgn
Hi, I have to draw a line (using MoveTo and LineTo) that has to be clipped to a portion of the screen. The starting and ending coordinates are on opposite ends outside the visible area. Clipping it does the trick of showing only a portion of the line within the area it is supposed to draw in. When using a printer DC to print (standard print preview of an MDI application) the clipping doesn't seem to work, so the line gets drawn all over the place.. even outside the paper boundaries in print-preview. What can I do about this? It would be quite a hassle to have to calculate the 'inte...

Load Tif file in memory hDC
How do I load a TIF file in memory hDC and save it back to another file after some processing using DrawText. I want to use the memory hDC because I dont want to display the image. Is there an example for doing this. Asfar wrote: > How do I load a TIF file in memory hDC and save it back to another file > after some processing using DrawText. > > I want to use the memory hDC because I dont want to display the image. > > Is there an example for doing this. > > I am using Cximage to do this. See here http://www.codeproject.com/bitmap/cximage.asp ...

Rotating text in a CDC
Is it possible to rotate text in a simple way inside a CDC object? I added the next code in OnPaint for a CWnd object, but the text still appears "normal". I tried setting the lfEscapament and lfOrientation to 1, 9, 90, etc (both simultaneously), but nothing worked. void CMyWnd::OnPaint() { CPaintDC dc(this); // device context for painting ..... CFont *pOldFont,*pCurFont,*pNewFont; pNewFont = new CFont(); // Load the present font from the DC pCurFont = dc.GetCurrentFont(); // Just change the orientation LOGFONT logFont; pCurFont->GetLogFont(&logFont); logFo...

CDC Class
I am using the CDC Class to print some data out that does not utilize the CView class. The data is also tab delimited. One thing I ran across is that if I spread the data way out based on the tabs it truncates. I have searched MSDN and I am sure I missed it. Is there a way to set the device to "wrap" then set it back to "wrap"? Bob You can not make DC wrap your output. But you can make DrawString function wrap the line with DT_WORDBREAK flag. To figure out where to print next line, call DrawText with DT_CALCRECT flag to know the height of the printed string. &qu...

DrawTextW( hdc, strText, -1, rectB, DT_SINGLELINE);
Hi, I have a peice of a code for loading a icon and draw the text below the icon on the same button... i was sucessful in loading an icon but when tried with the DrawText() to insert a text, its not working and the problem is with the hdc parameter of DrawText function. void CNewButtonDlg::CallButton() { CString strText(""); //To place the text on the button RECT rectA = {180, 20, 270, 90}; //left, top, right, bottom //To nullify the error that parameter must be a LPRECT and not RECT type i have done so LPRECT rectB = &rectA; CDC my_newButto...