Ok, I assume you already can create a window and have all that figured out. To draw an image onto a window is relatively simple. First your going to get a handle to an image file using the LoadImage function:
HANDLE hImage = LoadImage(NULL, "C:\\test.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
Coolness? Now you have to get a device context for the window. Now basically a device context (or a DC) is a handle to an area of memory that represents an image. So to draw something to a window, we need its DC, because we're simply writing to the section of memory that represents its appearance. So heres how to get your window's DC:
HDC hWindowDC = GetDC(hWndMain);
Pretty simply huh? hWndMain is the handle to whatever window you want the DC of. Now we have a place in memory to write to, but we need a DC to load the bitmap file onto:
HDC hImageDC = CreateCompatibleDC(hDC);
So what we did is just create a new DC that's compatible with the window's DC (meaning it is the same colordepth, etc). Now we need to find out more about our bitmap file, such as its width and height, so we can use it to copy it to the window. We do that like this:
BITMAP Bitmap;
GetObject(hImage, sizeof(BITMAP), &Bitmap);
Ok so now Bitmap has a wealth of info on our bitmap. Now lets load the image file into our DC (basically we're copying the image from the HardDrive into memory):
SelectObject(hImageDC, hImage);
So now we have the window in one DC and the image in the other so let's copy using my favorite function:
BitBlt(hDC, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight, hImageDC, 0, 0, SRCCOPY);
Now, if you don't plan to redraw the image, we need to delete the image from memory by deleting its DC:
DeleteDC(hImageDC);
Also, another thing about DC's is that other programs can't access them when your program has control. That is when you called GetDC to get your windows DC, you took control of that DC. So if you don't give up control when you're done, windows will not be able to draw your window, and that sucks. So lets release the window's DC:
ReleaseDC(hWndMain, hWindowDC);
So now we gave control back to windows and windows is happy. If you have any questions about the functions used, look them up on msdn. I would suggest you at least look up BitBlt (If you're not familliar with it) so you know how to draw it in different ways and positions. So here's the whole thing with an added line that checks to see if the file exists basically. That is if LoadImage returns a NULL handle, the specified file probably doesn't exist, so no need to try and do the rest:
Code:
HANDLE hImage = LoadImage(NULL, "C:\\test.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (hImage){
HDC hWindowDC = GetDC(hWndMain);
HDC hImageDC = CreateCompatibleDC(hDC);
BITMAP Bitmap;
GetObject(hImage, sizeof(BITMAP), &Bitmap);
SelectObject(hImageDC, hImage);
BitBlt(hDC, 0, 0, Bitmap.bmWidth, Bitmap.bmHeight, hImageDC, 0, 0, SRCCOPY);
DeleteDC(hImageDC);
ReleaseDC(hWndMain, hWindowDC);
}