|
-
Oct 7th, 2001, 10:05 PM
#1
Thread Starter
Fanatic Member
Why does it close here but not there?
Code:
int CALLBACK DlgProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
if (LOWORD(wParam) == IDC_BTN_TEST)
{
iCount = ((GetTickCount() / 1000) / 60);
ltoa(iCount, szTicks, 10);
MessageBox(hWndDlg, szTicks, "Counter", MB_OK);
}
if(LOWORD(wParam) == IDC_BTN_CANCEL)
{
MessageBox(hWndDlg, "Cancel pressed!", "Button", MB_OK);
}
if(LOWORD(wParam) == IDC_BTN_OK)
{
MessageBox(hWndDlg, "OK pressed!", "Button", MB_OK);
return false;
}
case WM_CLOSE:
EndDialog(hWndDlg, 0);
PostQuitMessage(0);
break;
}
return false;
}
If I click the IDC_BTN_TEST button, it tells me a number, like I want it to, then closes. If I click the IDC_BTN_OK button, it tells me "OK pressed!", but it doesn't close. Why is this?
Alcohol & calculus don't mix.
Never drink & derive.
-
Oct 7th, 2001, 10:12 PM
#2
Because you are not breaking or returning after the Test button's code. The case is falling through to the WM_CLOSE code.
Code:
int CALLBACK DlgProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
if (LOWORD(wParam) == IDC_BTN_TEST)
{
iCount = ((GetTickCount() / 1000) / 60);
ltoa(iCount, szTicks, 10);
MessageBox(hWndDlg, szTicks, "Counter", MB_OK);
return false;
}
if(LOWORD(wParam) == IDC_BTN_CANCEL)
{
MessageBox(hWndDlg, "Cancel pressed!", "Button", MB_OK);
}
if(LOWORD(wParam) == IDC_BTN_OK)
{
MessageBox(hWndDlg, "OK pressed!", "Button", MB_OK);
return false;
}
case WM_CLOSE:
EndDialog(hWndDlg, 0);
PostQuitMessage(0);
break;
}
return false;
}
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 7th, 2001, 10:24 PM
#3
Thread Starter
Fanatic Member
*wonders why he didn't see that* Thanks a lot
Alcohol & calculus don't mix.
Never drink & derive.
-
Oct 10th, 2001, 02:38 PM
#4
why do you return false?
And why false instead of FALSE?
DlgProc has a predefined prototype with a BOOL return value, not bool. bool is a basic C++ data type, while BOOL is just an alias for int, and TRUE and FALSE are defined as 1 and 0.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 10th, 2001, 03:10 PM
#5
TRUE = true = 1
FALSE = false = 0
-
Oct 10th, 2001, 03:19 PM
#6
Frenzied Member
BOOL is a win32 data type and bool is a standard c++ data type. That is the difference.
-
Oct 10th, 2001, 03:26 PM
#7
Megatron: Try this code:
Code:
bool cppbool;
BOOL winbool;
cppbool = true;
cppbool = FALSE;
winbool = false;
winbool = TRUE;
You'll get a warning at cppbool = FALSE. Only a warning - the compiler will do the type conversion, but it#s a "possible speed hazard". The compiler will also do a type conversion at winbool = false
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|