I'm trying to open a dialog box from a resource file inside my WndProc function. The problem is WndProc does not have a hInstance and you need hInstance to open a dialog box. Any suggestions?
I'm trying to open a dialog box from a resource file inside my WndProc function. The problem is WndProc does not have a hInstance and you need hInstance to open a dialog box. Any suggestions?
The first parameter of WinMain is HINSTANCE.
Assuming you're not messing with DLLs, where you need the HINSTANCE, use GetModuleHandle(0).
It's also passed with WM_CREATE via the CREATESTRUCT pointer
Look dude, I get that hInstance is in WinMain, but I'm trying to use it in WndProc. As for the other suggestions, I really don't know what I'm doing, so I didn't understand them. Here is my code maybe you could give me an example. Thank you so much.
Code:LRESULT CALLBACK WndProc (HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch(iMsg) { case WM_DESTROY: { PostQuitMessage(0); break; } case WM_COMMAND: { if(LOWORD(wParam) == IDM_QUIT) { PostQuitMessage(0); break; } if(LOWORD(wParam) == IDM_HELP) { DialogBox(hInstance, \\ I NEED THE HINSTANCE THERE, BUT ITS NOT IN WNDPROC MAKEINTRESOURCE(IDD_HELP), NULL, (DLGPROC)DlgProc ); break; } break; } } return DefWindowProc (hWnd, iMsg, wParam, lParam); }
Last edited by ElWhapo; 12-28-2004 at 10:04 AM. Reason: Had hWnd instead of hInstance at the point of the problem.
In simple programs, the simplest way is to create a global HINSTANCE variable and copy the parameter into it when your WinMain() starts. Then your WinProc() will be able to see the instance handle.
There are better ways.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
Do you mean that I should make WndProc have 5 things in it?
I don't think you can do that.
Nevermind. I get it and it worked. Thanks.
Touchy, touchy. Take it easy, "dude." I am not a clairvoyant; I can't determine how inept one may or may not be at solving a problem based solely on their username (on second thought...). If someone doesn't answer your question adequately, just say so. It's completely unnecessary for you to react to someone's attempt to provide you with assistance with such negativity.Originally Posted by ElWhapo
I'm glad to see you managed to get it working. Good luck in all your endeavors.