Modal dialog and outside mouse control
Hi All ! :wave:
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
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);
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
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 ???
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. :confused:
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
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).
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
}