Having Trouble Opening My Dialog Box

This is a discussion on Having Trouble Opening My Dialog Box within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to open a dialog box from a resource file inside my WndProc function. The problem is WndProc does ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    Having Trouble Opening My Dialog Box

    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?

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    The first parameter of WinMain is HINSTANCE.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Assuming you're not messing with DLLs, where you need the HINSTANCE, use GetModuleHandle(0).

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    It's also passed with WM_CREATE via the CREATESTRUCT pointer

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    Not Exactly Sure Still

    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 09:04 AM. Reason: Had hWnd instead of hInstance at the point of the problem.

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    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.

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    What do you mean?

    Do you mean that I should make WndProc have 5 things in it?
    I don't think you can do that.

  8. #8
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    Nevermind. I get it and it worked. Thanks.

  9. #9
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Quote Originally Posted by ElWhapo
    Look dude, I get that hInstance is in WinMain
    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.

    I'm glad to see you managed to get it working. Good luck in all your endeavors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bypassing Print Dialog Box
    By leojose in forum Windows Programming
    Replies: 0
    Last Post: 10-13-2005, 06:44 AM
  2. Add a dialog box to a tab
    By axr0284 in forum Windows Programming
    Replies: 0
    Last Post: 01-10-2005, 07:38 AM
  3. opening a dialog window from inside a dialog window
    By uvacow in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2002, 08:27 AM
  4. Simple Dialog Box (noob)
    By tegwin in forum Windows Programming
    Replies: 6
    Last Post: 06-30-2002, 06:04 PM
  5. User Input without Dialog box?
    By Isometric in forum Windows Programming
    Replies: 2
    Last Post: 11-22-2001, 01:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21