Thread: Problem With Vc++7 And Dialog Boxes...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    100

    Problem With Vc++7 And Dialog Boxes...

    I'm writing a win32 app in Win API, using VC++ 7.0.

    So I made my dialog box in the resource editor... and put this code in my main.cpp

    Code:
    BOOL CALLBACK MainDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
    	switch(Message) {
      case WM_INITDIALOG:
    
      	return TRUE;
      case WM_COMMAND:
      	switch(LOWORD(wParam)) {
    
        }
    	}
    	return TRUE;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    	MSG Msg;
    
    	HICON hMyIcon = LoadIcon(hInstance, "icon1.ico");
    	DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MAIN), 0, MainDlgProc);
    
    	while(GetMessage(&Msg, NULL, 0, 0) > 0)
    	{
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
    	}
    
    	return Msg.wParam;
    }
    But the dialog box shows up with some parts transparent and just screwed up, and i cant interact with it, and I have to ctrl+alt+del to quit

    Any ideas?

    Thanks

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Your switch syntax is wrong, need to fix it first.
    Code:
    switch (somevalue)
    {
    case 0:
    break; (or return)
    
    case 1:
         switch (othervalue)
         {
                case 0:
                break;
    
                case 1:
                break;
         }
    break; (or return)
    
    default:
    break;

    Returning true means the app has processed the msg.

    All cases you return true.

    Add a default handler

    // for messages that we don't deal with
    default:
    return DefWindowProc (hwnd, message, wParam, lParam);

    or

    return zero to any msgs you don't process.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Chief Code Coloniser!
    Join Date
    Apr 2005
    Posts
    121
    Quote Originally Posted by MSDN
    Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message.
    You aren't "processing" the messages that you're handling in any way. You need to return FALSE instead of TRUE.
    Code:
    BOOL CALLBACK MainDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	switch(Message)
    	{
    	case WM_INITDIALOG:
    		{
    			// do whatever
    			break;
    		}
    	case WM_COMMAND:
    		{
    			switch(LOWORD(wParam))
    			{
    				case IDC_WHATEVER:
    				{
    					// do something
    					break;
    				}
    			}
    			// break;
    		}
    		
    	}
    	return FALSE;
    }

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    100
    Thank you! You fixed my problem

  5. #5
    Chief Code Coloniser!
    Join Date
    Apr 2005
    Posts
    121
    // for messages that we don't deal with
    default:
    return DefWindowProc (hwnd, message, wParam, lParam);
    Don't do this for Dialog boxes.

Popular pages Recent additions subscribe to a feed