Question

In my .rc file I have add line:

IMG BITMAP "myIMG.bmp" //add to resources

Prototype in .cpp file:

HBITMAP     Image;

after ShowWindow() I load it in to memory with:

Image=LoadBitmap(hInstance,"IMG");

On WM_CREATE: I load it on to the screen and clear it out:

HDC GetDC (hdc);    
HDC newhdc = CreateCompatibleDC(hdc);   
SelectObject(newhdc,Image);
BitBlt(hdc,30,70,491,302,newhdc,0,0,SRCCOPY);
DeleteDC(newhdc);
DeleteObject(Image);
ReleaseDC(hwnd,hdc);

Thanks to @BeneGal question (founded here) I have created a MB that tells if the img is not loaded:

if(Image == NULL) {
MessageBox(NULL, "NO IMAGE LOADED!", "Error!",  MB_ICONEXCLAMATION | MB_OK);
}

When I paste the above code right after ShowWindow() the MB don't appear, when I paste it on WM_CREATE: it appears. Don't know why.

edit: Well actually I forgot to tell that image does not appear on my window and that is the main problem.

Was it helpful?

Solution

Load your bitmap in WM_CREATE use it in WM_PAINT. Keep track of return objects by SelectObject and don't delete object which are still selected in HDC. Do something like that http://www.winprog.org/tutorial/bitmaps.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top