Results 1 to 7 of 7

Thread: Why does it close here but not there?

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    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.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  3. #3

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    *wonders why he didn't see that* Thanks a lot
    Alcohol & calculus don't mix.
    Never drink & derive.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5
    Megatron
    Guest
    TRUE = true = 1
    FALSE = false = 0

  6. #6
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    BOOL is a win32 data type and bool is a standard c++ data type. That is the difference.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width