can someone show me LoadImage function?

Oct 24, 2011 at 3:09pm
can someone please tell me how to use the LoadImage in WinAPI?
I just want to display a bitmap image on the screen
I tried looking up this function but all the code seems so complicated as i am a beginner at all this.
Is there a simple version for displaying bitmaps?
thanks
Last edited on Oct 24, 2011 at 3:09pm
Oct 24, 2011 at 4:25pm
If you want to make a game, see SFML. If you want a more serious GUI application, see Qt, wxWidgets, GTK+ or FLTK (using these will be harder than SFML though). WinAPI is a pain to use.
Oct 25, 2011 at 4:09pm
sorry i don't have a choice what im using. its for a class project and we're doing WinAPI
Oct 25, 2011 at 4:42pm
Oh. Could you then specify what exactly you need? Are you asking about how to call LoadImage or how to draw the image too (what do you want to use it for?) ? Have you had any attempts that failed for unknown reasons?
Oct 25, 2011 at 10:21pm
Assuming you're using pure win32 and GDI and you want to display the bitmap in a window you created then you basically have the following steps: load the bitmap, create a device context(DC), insert the bitmap into the DC in order to perform a bit block operation on it, get a handle to the destination DC, perform a bit block copy of the entire bitmap from the source DC to the destination DC. Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
     static HBITMAP bmpSource = NULL;
     static HDC hdcSource = NULL;
	
     PAINTSTRUCT ps;
     HDC hdcDestination;

     if (Msg == WM_CREATE)
     {
          bmpSource = (HBITMAP)LoadImage(NULL, L"c:\\filename.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
          hdcSource = CreateCompatibleDC(GetDC(0));
          SelectObject(hdcSource, bmpSource);
          return 0;
     }
     else if (Msg == WM_PAINT)
     {
          hdcDestination = BeginPaint(hWnd, &ps);
          BitBlt(hdcDestination, 0, 0, 500, 500, hdcSource, 0, 0, SRCCOPY);
	  EndPaint(hWnd, &ps);
	  return 0;
     }

     return DefWindowProc(hWnd, Msg, wParam, lParam);
}
Topic archived. No new replies allowed.