Thread: how come... (bmp loading)

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    how come... (bmp loading)

    When I use same technnique to load a bmp to my modeless child window as i do to the main window it doesnt appear?

    Code:
    BOOL CALLBACK AboutWndProc(HWND About,UINT msg,WPARAM wParam,LPARAM lParam)
    {
        static HBITMAP AboutImg = NULL;
         
        switch(msg)
        {
             case WM_CLOSE:
                  ShowWindow(About,SW_HIDE);
                  break;
             
             case WM_DESTROY:
                  ShowWindow(About,SW_HIDE);
                  break;
                  
             case WM_CREATE:
                  AboutImg = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(ABOUT_IMAGE));
                  if(AboutImg == NULL)
                  {
                      MessageBox(NULL,"About image couldn't be loaded","Error",MB_OK);
                  }
             break;
             
             case WM_PAINT:
                  {
                     BITMAP bm;
                     PAINTSTRUCT ps;
                     
                     HDC hdc = BeginPaint(About,&ps);
                     
                     HDC hdcMem = CreateCompatibleDC(hdc);
                     HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem,AboutImg);
                     
                     GetObject(AboutImg,sizeof(bm),&bm);
                     
                     BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,hdcMem,0,0,SRCCOPY);
                     
                     SelectObject(hdcMem,hbmOld);
                     DeleteDC(hdcMem);
                     
                     EndPaint(About,&ps);
                  }
             break;
             
             default:
                  return FALSE;
        }
        
        return TRUE;
    }
    basically what im trying to accomplish is loading my bitmap to my child window.

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Well what happens? Does the MessageBox appear? Are the values for bm.bmWidth and bm.bmHeight valid?

    P.S. Bear in mind that when WM_DESTROY is called your window is in the process of being destroyed. Hiding it won't do anything.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    I know =P, well, I figured by doing GetObject(AboutImg,sizeof(bm),&bm) would get the width and height etc. of my bmp. It works fine when doing so to the parent window.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Drawing code looks OK. If the image is loading and returning valid sizes then all looks good.

    My bet is that the image never gets loaded, Check it is not NULL in the WM_PAINT.

    If you are not creating the dialog with CreateWindow(Ex) then add a WM_INITDIALOG handler.

    case WM_CREATE://called from CreateWindow or CreateWindowEx
    case WM_INITDIALOG: //called from DialogBox functions

    //ect

    break;

    >>Bear in mind that when WM_DESTROY is called your window is in the process of being destroyed

    As the default msg processing is not called ( DefWindowProc() ) nor is DestroyWindow() in the WM_CLOSE handler, a WM_DESTROY msg should not be sent.


    You should be calling DefWindowProc() for any msgs you do not process. ie non client draws, sizes ect ect....

    ie

    default:
    return DefWindowProc(About, msg, wParam, lParam);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    thanks

    YES!!! that was it, WM_INITDIALOG. Thanks for the tip to =P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BMP Loading Structs
    By IdioticCreation in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2007, 12:42 PM
  2. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  3. bmp file loading
    By linuxdude in forum Game Programming
    Replies: 9
    Last Post: 08-06-2004, 01:05 PM
  4. Loading BMP to a DirectDrawSurface
    By phatslug in forum Game Programming
    Replies: 1
    Last Post: 07-18-2002, 04:15 PM
  5. Loading BMP without WM_PAINT?
    By SyntaxBubble in forum Windows Programming
    Replies: 3
    Last Post: 01-10-2002, 10:59 PM