none
hook to wm_close RRS feed

  • Question

  • Hi

    i want to catch wm_close of main window but it wm_close also fires when i close any dialog box 

    How to detect wm_close and make sure that is generate by main window closing.

    Thanks


    sahil

    Thursday, October 4, 2012 12:32 PM

All replies

  • Hi,

    You can get the WM_CLOSE message in Wndproc

    Look into the following link

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms632617%28v=vs.85%29.aspx


    Will show the code how you get the message for WM_CLOSE  that cause WM_CLOSE fires for closing  dialogboxs too??

    Thank You


    Gopinath.S


    • Edited by Gopinath.S Friday, October 5, 2012 6:49 AM
    Friday, October 5, 2012 6:47 AM
  • Thanks For Reply 

    But i hooked with both WH_GETMESSAGE and WH_CALLWNDPROCRET but still not able to trap wm_close event in case of main window closing but able to detect wm_close of closing dialog box

    by using WH_CALLWNDPROCRET .

    How can i detect wm_close in case when user clicks on cross button of main application window

    Thanks 


    sahil

    Friday, October 5, 2012 12:47 PM
  • Thanks For Reply 

    But i hooked with both WH_GETMESSAGE and WH_CALLWNDPROCRET but still not able to trap wm_close event in case of main window closing but able to detect wm_close of closing dialog box

    How can i detect wm_close in case when user clicks on cross button of main application window

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	int wmId, wmEvent;
    	PAINTSTRUCT ps;
    	HDC hdc;
    
    	switch (message)
    	{
    	case WM_COMMAND:
    		wmId    = LOWORD(wParam);
    		wmEvent = HIWORD(wParam);
    		// Parse the menu selections:
    		switch (wmId)
    		{
    		case IDM_ABOUT:
    			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
    			break;
    		case IDM_EXIT:
    			DestroyWindow(hWnd);
    			break;
    		default:
    			return DefWindowProc(hWnd, message, wParam, lParam);
    		}
    		break;
    	case WM_PAINT:
    		hdc = BeginPaint(hWnd, &ps);
    		// TODO: Add any drawing code here...
    		EndPaint(hWnd, &ps);
    		break;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    
    	case WM_CLOSE:
    		  MessageBox(NULL, L"Closing Application", L"Message", MB_OK);
    
    	default:
    		return DefWindowProc(hWnd, message, wParam, lParam);
    	}
    	return 0;
    }
    
    // Message handler for about box.
    INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	UNREFERENCED_PARAMETER(lParam);
    	switch (message)
    	{
    	case WM_INITDIALOG:
    		return (INT_PTR)TRUE;
    
    	case WM_COMMAND:
    		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
    		{
    			EndDialog(hDlg, LOWORD(wParam));
    			return (INT_PTR)TRUE;
    		}
    		break;
    	case WM_CLOSE:
    		MessageBox(NULL, L"Closing dialogbox", L"Message", MB_OK);
    	}
    	return (INT_PTR)FALSE;
    }
    

    Hi,

    You can simply given the WM _CLOSE in wndproc as shown in the code.Look into the simple code.It only detect the Closing event of main applicatuion window right!


    Gopinath.S

    Friday, October 5, 2012 1:41 PM