Win32 closing Modeless dialogs

Started by
4 comments, last by Emexus 20 years, 10 months ago
Hi all, I have created a simple win32 app, it opens a dialog box and is modeless, but im having some trouble with closing the dialog box, this is the message handaler for it,

BOOL CALLBACK Deck1DlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
HWND g_hToolbar = NULL;
    switch(Message)
    {
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
	            case WM_CLOSE:
			EndDialog(g_hToolbar,0);
		    return 0;

		    case WM_DESTROY:
		        EndDialog(g_hToolbar,0);
			PostQuitMessage(0);
	            break;
            }
        break;
        default:
            return FALSE;

			
    }
    return TRUE;
}
 
all i want it to do is to return back to my main window, once the x is clicked in the top right hand corner i though this could be achived by


case WM_CLOSE:
     EndDialog(g_hToolbar,0);
return 0;

cheers for any help. [edited by - Emexus on June 5, 2003 11:47:35 AM]
Advertisement
Try handling a WM_SYSCOMMAND message with a wParam value of SC_CLOSE.

WM_CLOSE and WM_DESTROY are messages in their own right, not a sub-message of WM_COMMAND. WM_CLOSE is sent when the window/application should terminate, to allow for the application to create a confirmation/save/etc prompt. WM_DESTROY is sent when the window is being destroyed.

Skizz

[edited by - Skizz on June 5, 2003 12:34:09 PM]
Cheers for the reply, ive just tried that, and it dosent seem to work, at least not for me, nothing will happen when i click the x,

cheers,
Anyone else got any ideas, of what im doing wrong?
cheers
i use DestroyWindow on modeless dialogs, may want to try that.
While EndDialog seems to have worked for me in general on modaless dialogs, it is stated in the MSDN that modaless dialogs should instead use DestroyWindow to close the window. EndDialog is intended for use exclusively on modal dialogs only. Go figure.

If that doesn''t help you out then maybe we can figure something else out.

This topic is closed to new replies.

Advertisement