Thread: Proper way to end a dialogbox.

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

    Proper way to end a dialogbox.

    Howdy. I'm wondering if I am closing my dialogbox properly. As you can see in my WinMain function, my DialogBox is the main window, the only window. Heres my WinMain function:

    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nShowCmd)
    {
    	MSG msg;
    	HWND hWnd;
    	
    	hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MainDlg), NULL, (DLGPROC)DialogProc);
    
    	ShowWindow(hWnd, nShowCmd);
    
    	while(GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	WSACleanup();
    
    	return 0;
    }
    And here is how I close my dialogbox in my DialogProc function:
    Code:
    ....
    
    	case WM_DESTROY:
    		{	
    			PostQuitMessage(0);
    			return TRUE;
    		}
    	case WM_CLOSE:
    		{
    			DestroyWindow(hWnd);
    			return TRUE;
    		}
    ...
    Should I use EndDialog? Both work.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Use DestroyWindow for modeless and EndDialog for modal dialogs:

    CreateDialog
    DialogBox

  3. #3
    Climber spoon_'s Avatar
    Join Date
    Jun 2002
    Location
    ATL
    Posts
    182
    Thanks = )
    {RTFM, KISS}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  2. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM
  5. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 02:40 PM