In my C++ MFC application I have an ActiveX control on a form. At some point I create and show a new dialog. I don’t want the user to be able to click the ActiveX control while this second dialog is up so I tried creating it as a child dialog. However the ActiveX control always appears above the child dialog in Z order. I have tried sending message on the create to change the Z order but nothing worked.
I’ve tried using Windows Hooks to intercept the mouse click using the following code:
GetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)CDWFDLG::ClickProc, GetModuleHandle(NULL), 0)
LRESULT CALLBACK CDWFDLG::ClickProc(int ncode, WPARAM wparam, LPARAM lparam)
{
if(wparam == WM_LBUTTONDOWN)
{
Beep(110, 30);
return TRUE;
}
return CallNextHookEx(0, ncode, wparam, lparam);
}
This blocks all left mouse clicks which is what I want. However it does this on everything, not just on my application. I’ve tried setting the thread Id using
GetCurrentThreadId()
and
GetWindowThreadProcessId(this->m_hWnd, &threadId )
However neither of these worked. What should I use to just get the hook to run on my application? Once this is working I was planning on using the coordinates of the click to check whether is was on the new dialog and handle it from there.
Thanks
Although I couldn’t fix the problem using Window Hooks, I think I’ve fixed it using the dialog properties. I’ve set the parent dialog’s
Control Parentto True and left everything else in the child dialog’s properties to default (Controlis false and andStyleis Popup etc).Now when I call the dialog through
DoModal()it has focus and doesn’t allow clicks on the ActiveX control.Thanks