Thread: Win32API DialogBox Problem

  1. #1
    Climber spoon_'s Avatar
    Join Date
    Jun 2002
    Location
    ATL
    Posts
    182

    Win32API DialogBox Problem

    I'm using MSVC++6 Professional to make this project. I'm using the Resource Editor to build the Dialog box (IDD_DIALOG1) with controls and what not.

    Everything works just fine except for the fact that when I run my program, and then close it... clicking the X on the system menu doesn't work. Minimize does. Maximize does. I must be missing something. Do I need a different Message loop? I can't find any documentation on specific DialogBox msg loops.

    Am I doing it all wrong?

    Heres the code:


    Code:
    #include<windows.h>
    #include "resource.h"
    
    LRESULT CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int ShowCmd)
    {
    	MSG msg;
    
    	DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)DialogProc);
    
    	while(GetMessage(&msg, 0, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return msg.wParam;
    }
    
    LRESULT CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch(message)
    	{
    	case WM_INITDIALOG:
    		{
    			return TRUE;
    		}
    	case WM_DESTROY:
    		{
    			PostQuitMessage(0);
    			return 0;
    		}
    	}
    	return 0;
    }
    Thanks for the help,
    spoon_
    Last edited by spoon_; 07-21-2002 at 05:36 PM.
    {RTFM, KISS}

  2. #2

    Post WinAPI No Close

    Try putting :

    Code:
    case WM_CLOSE:
                      DestroyWindow(hwnd);
                      break;
    after WM_DESTROY

  3. #3
    Registered User cMADsc's Avatar
    Join Date
    Jun 2002
    Posts
    18

    Post

    You have to process the WM_COMMAND message in your Dailog's procedure


    BOOL CALLBACK DialogProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch(message)
    {
    case WM_INITDIALOG:
    return TRUE;

    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case IDOK:
    case IDCANCEL:
    EndDialog(hDlg, 0);
    return TRUE;
    }
    break;
    }
    return FALSE;
    }
    There are those who say they can, and there are those who acutally do.

    ...you can not learn programming in a class, you have to learn it on your own

  4. #4
    Registered User cMADsc's Avatar
    Join Date
    Jun 2002
    Posts
    18
    There are those who say they can, and there are those who acutally do.

    ...you can not learn programming in a class, you have to learn it on your own

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    The DialogBox function creates a modal Dialog box. You should be calling EndDialog to exit that dialog.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  6. #6
    Climber spoon_'s Avatar
    Join Date
    Jun 2002
    Location
    ATL
    Posts
    182

    cool

    Thanks a lot!

    So I should use EndDialog instead of DestroyWindow?

    Here's what I gather so far...

    Code:
    LRESULT CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch(message)
    	{
    	case WM_INITDIALOG:
    		{
    			return TRUE;
    		}
    	case WM_COMMAND:
    		{
    			switch(LOWORD(wParam))
    			{
    				/*take care of controls...*/
    			}
    		}
    	case WM_DESTROY:
    		{
    			PostQuitMessage(0);
    			return TRUE;
    		}
    	case WM_CLOSE:
    		{
    			EndDialog(hDlg, 0);
    			return TRUE;
    		}
    	}
    	return FALSE;
    }
    {RTFM, KISS}

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Try something like this..

    Code:
    case WM_CLOSE:
    case WM_DESTROY:
         EndDialog( hWnd, TRUE );
    I'm not sure exactly what you are doing so this may or may not be right for you.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM