Thread: Device Context's, & CDC*, cannot obtain hDC Value.

  1. #1
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719

    Device Context's, & CDC*, cannot obtain hDC Value.

    I have been working on loading Bitmaps from files. I can load the Bitmaps into a temporary Device Context then BitBlt from that DC to the main Windows DC... which works, but now I am having trouble finding the hDC from a PictureBox. So lets say that I want to get the DC from my PictureBox and it is binded to a variable called m_Picture. To obtain the DC(I believe) is m_Picture.GetDC() however GetDC in MFC is CDC* which I do not know how to use. CDC* is also what is used for m_Picture.GetWindowDC. Usually GetDC has a return value which uses an HDC, but CDC cannot work with a return operator '='. I have gotten this far from MSDN, but now I am stuck. If anyone knows how to obtain an hDC value I should be fine from there.

  2. #2
    Registered User Liam Battle's Avatar
    Join Date
    Jan 2002
    Posts
    114
    Just setup a pointer to the DC when you created the bitmap picture, then any time you need it you have a pointer to it.
    is that what you want?

    you can obtain any information or change information through that pointer variable you setup.
    LB0: * Life once school is done
    LB1: N <- WakeUp;
    LB2: N <- C++_Code;
    LB3: N >= Tired : N <- Sleep;
    LB4: JMP*-3;

  3. #3
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719

    Um... Not quite.

    I already have a pointer to my temporary hDC containing the bitmap. Okay, this is how you draw a Bitmap to the Main Windows Screen
    Code:
    HDC hDC;
    HANDLE hBitmap;
    HWND fWindow;
    hDC = CreateCompatibleDC(NULL);
    HDC oHand;
    
    hBitmap = LoadImage(0,"C:\\Documents and Settings\\Xei\\Desktop\\Exclusion.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    SelectObject(hDC,hBitmap);
    BitBlt(GetDC(0),0,0,5000,5000,hDC,0,0,SRCCOPY);
    
    DeleteDC(hDC);
    That will draw a bitmap from a Console application. Now I am trying to do this in MFC, and draw the Bitmap on a PictureBox. So this code is valid for MFC:

    Code:
    hBitmap = LoadImage(0,"C:\\Documents and Settings\\Xei\\Desktop\\Exclusion.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    SelectObject(hDC,hBitmap);
    The line of error is BitBlt Parameter 1. It requires a hDC value. My PictureBox(m_Picture) does not have a variable for hDC such as m_hDC, however it does have m_hWND. We can retreive hDC from the API call GetWindowsDC or GetDC, however in MFC the call is no longer HDC GetDC(hWnd), it is now CDC* GetDC(); now in a CDC variable there is a m_hDC, but I do not know how to obtain this hDC from the picturebox. The following code is an invalid attempt at getting a hDC from my picturebox:

    Code:
    CDC blah;
    blah = m_Picture.GetDC();
    
    //Compile Error: "error C2582: 'CDC' : 'operator =' function is unavailable"
    So this is where I am stuck... I cannot obtain a hDC from a PictureBox.
    Last edited by Xei; 05-14-2002 at 07:07 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My progress.. thnx to Cprogramming forumites
    By csonx_p in forum Windows Programming
    Replies: 6
    Last Post: 05-21-2008, 01:17 AM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. My first "real" windows app
    By JoshR in forum Windows Programming
    Replies: 2
    Last Post: 07-28-2005, 07:40 AM
  4. Replies: 4
    Last Post: 06-30-2004, 03:11 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM