开发者

Using Windows Hooks to intercept mouse click on my application c++

In my C++ MFC application I have an ActiveX contr开发者_如何学JAVAol 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


GetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)CDWFDLG::ClickProc, GetModuleHandle(NULL), 0)

Means you are hooking globally, all mouse clicks performed.

What you want is to hook WH_MOUSE, with the option GetCurrentThreadId() instead of 0, this will yield the results you want.


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 Parent to True and left everything else in the child dialog's properties to default (Control is false and and Style is Popup etc).

Now when I call the dialog through DoModal() it has focus and doesn't allow clicks on the ActiveX control.

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜