Win32API DialogBox Problem

This is a discussion on Win32API DialogBox Problem within the Windows Programming forums, part of the Platform Specific Boards category; I'm using MSVC++6 Professional to make this project. I'm using the Resource Editor to build the Dialog box (IDD_DIALOG1) with ...

  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 06:36 PM.
    {RTFM, KISS}

  2. #2
    Perverted unanimous's Avatar
    Join Date
    Oct 2001
    Posts
    336

    Post WinAPI No Close

    Try putting :

    Code:
    case WM_CLOSE:
                      DestroyWindow(hwnd);
                      break;
    after WM_DESTROY
    Give me a bad reputation!!!

  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, 09:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM

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