dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Modal dialog and outside mouse control

  1. #1
    Join Date
    Sep 2001
    Location
    Rotmanka, Poland
    Posts
    88

    Modal dialog and outside mouse control

    Hi All !

    I'm creating normal CDialog and show it by DoModal(). Problem is that I need to know if user click rigth mouse button OUT of this dialog.

    I try with SetCapture(). This is work, but mouse events not come to my controls in dialog, nc elements ect..

    I don't want a solution without DoModal() (create->Show). Will be the best if window is modal.

    Any ideas ?

    Thnx in advance
    OlekBa

  2. #2
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863

    Re: Modal dialog and outside mouse control

    You should be able to handle the WM_NCHITTEST message and check for
    HTNOWHERE or HTERROR (they are the same thing);
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  3. #3
    Join Date
    May 2005
    Posts
    4,954

    Re: Modal dialog and outside mouse control

    if SetCapture is not enough for you, consider using the ::SetWindowsHookEx(..) with WH_MOUSE to capture mouse events.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  4. #4
    Join Date
    Sep 2001
    Location
    Rotmanka, Poland
    Posts
    88

    Re: Modal dialog and outside mouse control

    Idea 1)
    WM_NCHITTEST is not call for outside of modal dialog

    Idea 2)
    ::SetWindowsHookEx(..) with WH_MOUSE - is exacly this same problem. I can detect all WM_RBUTTONDOWN in whole application WITHOUT this clicks what I need - out of modal dialog.

    If I click out of modal dialog I have additional beeps and window flash (like always in modal dialog) what inform me that I click out of dialog. But NO WM_NCHITTEST, NO HookEX, NO DefWindowProc......

    Any ideas ???

  5. #5
    Join Date
    May 2005
    Posts
    4,954

    Re: Modal dialog and outside mouse control

    Quote Originally Posted by olekba
    Idea 1)
    WM_NCHITTEST is not call for outside of modal dialog

    Idea 2)
    ::SetWindowsHookEx(..) with WH_MOUSE - is exacly this same problem. I can detect all WM_RBUTTONDOWN in whole application WITHOUT this clicks what I need - out of modal dialog.

    If I click out of modal dialog I have additional beeps and window flash (like always in modal dialog) what inform me that I click out of dialog. But NO WM_NCHITTEST, NO HookEX, NO DefWindowProc......

    Any ideas ???
    i dont really understand what trying to do.

    using SetWindowsHookEx(..) will give you a notification for any kind of mouse event in the whole windows, when you will recieve that notification
    do what you need to do and then you can choose:
    1)send it back to windows
    2) or block it in your hook function in order to avoid windows flashing.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  6. #6
    Join Date
    Sep 2001
    Location
    Rotmanka, Poland
    Posts
    88

    Re: Modal dialog and outside mouse control

    I have in my application modal dialog. My costumer in his program close a dialogs by click right button in this dialog or out of dialog, but his dialogs are not modal, so he just check if in any place of application come button click (not important in dialog or in main application window).

    This what I want is create this same funcjonality, but with modal dialogs. So I need information, that user click out of dialog (in main application window space).

    If I use SetCapture for dialog I have this funcionality, but mouse click in control not make result (dialog have a mouse and not propagete this events to controls). This same problem with "NCCLICK" i.e. click in cross for close application.

    I try with your's

    Code:
    SetWindowsHookEx(WH_MOUSE,MouseProc,NULL,GetCurrentThreadId());
    where

    Code:
    LRESULT CALLBACK MouseProc(          int nCode,
        WPARAM wParam,
        LPARAM lParam
    )
    {
    	if (wParam==WM_RBUTTONDOWN)
    	{
    		Beep(1000,100);
    	}
    	
    	return CallNextHookEx(0,nCode,wParam,lParam);
    }
    but I havn't this "beep" if I click out of modal dialog (in main application window).

  7. #7
    Join Date
    Aug 2005
    Posts
    1

    Re: Modal dialog and outside mouse control

    Hi,
    I'm writing a modal dialog witch is working like a combobox. So I have to capture the outside mouse click and close the dialog.
    This solution is working fine:

    CMyDlg* theDialog = NULL;
    HHOOK handleHook = NULL;

    LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    EVENTMSG * message = (EVENTMSG *)lParam;
    if (message->message == WM_RBUTTONDOWN ||
    message->message == WM_LBUTTONDOWN )
    {
    RECT rect;
    theDialog->GetWindowRect(&rect);
    POINT point;
    GetCursorPos(&point);
    if (!PtInRect(&rect, point))
    {
    theDialog->EndDialog(IDCANCEL);
    if(handleHook)
    UnhookWindowsHookEx(handleHook);
    handleHook = NULL;
    theDialog = NULL;
    }
    }
    LRESULT result = CallNextHookEx(handleHook,nCode,wParam,lParam);
    return result;
    }

    LRESULT CMyDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {

    ///////////////
    //
    //


    theDialog = this;

    handleHook = SetWindowsHookEx(
    WH_JOURNALRECORD,
    MouseProc,
    AfxGetInstanceHandle(),
    0);

    return 1; // Let the system set the focus
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)