Drawing an icon help :)

Hi, Ive got this:

1
2
3
4
5
6
7
8
9
10
11
case IDYES: 
				HICON hIcon;
				hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1));
				HDC handleDeviceContext; 
				PAINTSTRUCT PaintSt;
				handleDeviceContext = BeginPaint(hWnd, &PaintSt);
				SetBkMode(handleDeviceContext, TRANSPARENT);
				DrawIcon(handleDeviceContext, 250, 250, hIcon);
				EndPaint(hWnd, &PaintSt);
				return 0;
			}


When i click yes on the messagebox an icon is supposed to display, but it doesnt, i just see a blank window, what am i doing wrong?
I see at least two problems here:

1.
hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1))
- With NULL as the first parameter, the LoadIcon function tries to load a standard windows icon.
If you want to load an icon from your resource you have to provide the HINSTANCE handle of your
program.

2.
1
2
3
4
PAINTSTRUCT PaintSt;
handleDeviceContext = BeginPaint(hWnd, &PaintSt);
//other code
EndPaint(hWnd, &PaintSt);

The BeginPaint and Endpaint functions should only be used in conjunction with a WM_PAINT message.
Use the GetDC and ReleaseDC functions when painting outside of a WM_PAINT message handler.
(*But if you want the icon to stay onscreen- you may want to consider moving code into the WM_PAINT handler*).


*EDIT*
This should really have been in the Windows forum
Last edited on
I have done what you said. I have a new problem, my mouse is going crazy (like as if its redrawing itself).
Last edited on
So im getting wm_paint messages constantly.
Ah, i know why, it is because in the wm_paint message I have include a MessageBox function which also sends the wm_paint message :D
Topic archived. No new replies allowed.