Winapi LoadBitmap() is not loading images from my resources

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.

Answers


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


Need Your Help

Event for marker position change

android android-maps android-maps-v2

I'm using the new Google Maps for Android v2.

C - main() command line parameters

c command-line parameters main

This is a really basic question but I can't find a definitive answer anywhere.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.