Thread: Cant get an image to show on my HDC

  1. #1
    Registered User
    Join Date
    Nov 2002

    Cant get an image to show on my HDC

    I cant seem to get a BITMAP to show on my HDC
    //Win32 Bitmap stuff
    HANDLE hImage;
    HWND button_hWnd;
    HDC hdc;
    HDC c_hdc;
    BITMAP Bitmap;
    SIZE ImageSize;
    hImage = LoadImage(hInstance,"Test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
       if(hImage != INVALID_HANDLE_VALUE)
    	   MessageBox(NULL,"Loaded Test.bmp","",0);
       hdc = GetDC(hWnd);
       c_hdc = CreateCompatibleDC(hdc);
       GetObject(c_hdc,sizeof(BITMAP),&Bitmap); = Bitmap.bmWidth; = Bitmap.bmHeight;
    in the Wndproc WM_PAINT message

    case WM_PAINT:
    		hdc = BeginPaint(hWnd, &ps);
    		// TODO: Add any drawing code here...
    		EndPaint(hWnd, &ps);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > hImage = LoadImage(hInstance,"Test.bmp",IMAGE_BITMAP,0,0,LR _LOADFROMFILE);
    But is this done in a different WM_MESSAGE case?

    If so, you need to make things like c_hdc to be static variables, so they're preserved from one call to your winproc to the next.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2002
    no its done straight after the main window is created

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Newport, South Wales, UK
    Fixing your error checking, INVALID_HANDLE_VALUE is a backwards compatible value used only with CreateFile. If LoadImage fails, it retuns NULL.

    Also, when you perform SelectObject, you're pushing a 1x1 monochrome bitmap (included free with the memory DC) into the ether. This is bad. Store the return value and put it back before EndPaint.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 07-01-2011, 12:29 PM
  2. Replies: 4
    Last Post: 03-13-2010, 05:10 AM
  3. I can't make bmp image files show up in an SDL window
    By Lucas89 in forum Game Programming
    Replies: 5
    Last Post: 05-25-2009, 01:04 PM
  4. Problems with Image Magick [Unable to Quantisize Image]
    By Maragato in forum C Programming
    Replies: 1
    Last Post: 09-18-2006, 10:41 PM
  5. show() method does not show...
    By kocika73 in forum C++ Programming
    Replies: 12
    Last Post: 04-09-2006, 09:27 PM