How to close this dialog box?
------ main.cpp ------
#include <windows.h>
#include "resource.h"
BOOL CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
switch(message)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_QUIT:
EndDialog(hwnd, ID_QUIT);
break;
}
break;
case WM_DESTROY:
EndDialog(hwnd, ID_QUIT);
break;
default:
return FALSE;
}
return TRUE;
}
int main()
{
DialogBox(
GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DIALOG),
NULL,
WndProc);
return 0;
}
------- myresource.rc ----------
#include <windows.h>
#include "resource.h"
IDD_DIALOG DIALOG DISCARDABLE 100, 50, 400, 300
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU |
WS_MAXIMIZEBOX | WS_MINIMIZEBOX
CAPTION "A Dialog Program"
FONT 8, "MS Sans Serif"
BEGIN
CTEXT "This is a program\r\ncreated using dialog boxes
methodology.",
IDC_STATIC, 16, 18, 144, 33
PUSHBUTTON "&Quit", ID_QUIT, 200, 250, 50, 14
END
> case ID_QUIT:
> EndDialog(hwnd, ID_QUIT);
> break;
case IDCANCEL:
//...
No, even this does not work...(Merry christmas & happy new year).
- deostroll
You need to handle IDOK and IDCANCEL in your WM_COMMAND handler.
Additionally, it's not necessary to call EndDialog when you see
WM_DESTROY (though, afaik it's effectively just a no-op).
--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
It is the final proof of God's omnipotence that he need not exist in
order to save us.
-- Peter De Vries
>>On 21 déc, 05:51, deostroll <deostr...@gmail.com> wrote:
>>
>>
>>> case ID_QUIT:
>>> EndDialog(hwnd, ID_QUIT);
>>> break;
>>
>>case IDCANCEL:
>>//...
>
>
> No, even this does not work...(Merry christmas & happy new year).
It must work if you haven't done any mistake.
It's the default behaviour of the Dialog Manager on WM_CLOSE
(and I've tested (XP SP2)...)
This should be:
case WM_CLOSE:
EndDialog(hdial,FALSE);
break;
On WM_DESTROY window is already being destroyed and you might want only
to do some cleanup there (like freeing memory you have allocated on
WM_INITDIALOG).
--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D
Perhaps the OP failed to understand your excessively brief response.
He/she may have placed the case statement AFTER the break statement as
it appears in your message.
To the OP:
Clicking the "X" button causes a WM_CLOSE message to be sent to the
dialog. The default action of the dialog is to send a WM_COMMAND message
with wParam set to IDCANCEL to you dialog function. Christian intended
to suggest that your code should look like this:
switch (message) {
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_QUIT:
case IDCANCEL:
EndDialog(...);
--
Norm
To reply, change domain to an adult feline.
WM_CLOSE worked!!! But if I write it like this...
------dialog.h-------
BOOL CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case WM_CLOSE:
case ID_QUIT:
EndDialog(hwnd, ID_QUIT);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
Seems a little weird. I initially put WM_CLOSE in the first switch and
found out that such messages were not actually being passed...I wonder
why? Anyway thanx all for the support.
-- deostroll
Tons. Probably the on of interest to you is IDCANCEL, which is what
you should be looking for in the first place.
--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
He had to get up to run some more. He told his muscles to do so. They
told him they had the night off.
-- Deadly Relations: Bester Ascendant by J. Gregory Keyes
>Can someone tell me what constant has the value "0x2"?
That is not nearly enough info. My copy of winuser.h lists the
following:
SB_CTL
SB_PAGEUP
SB_PAGELEFT
ALERT_SYSTEM_WARNING
IDCANCEL
and a whole lot more.
>-deostroll
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
Even WM_DESTROY has the same value. Putting WM_CLOSE in the switch
didn't actually do the work. (But I could have sworn I thought it
did). But instead WM_DESTROY does the trick gracefully. Anyway once
again thanx everyone for your support.
-deostroll
case WM_SYSCOMMAND:
{
switch( LOWORD( wParam ) )
{
case SC_CLOSE:
DestroyWindow( hwnd );
break;
default: