在菜单hookproc()中采样mousedown? [英] Sampling mousedown in a menu hookproc() ?

查看:55
本文介绍了在菜单hookproc()中采样mousedown?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长话短说:



我需要监视一个应用程序,以便检测文件,保存点击。

我有在codeguru这里和现在都有所帮助,现在在本周末,我可以做我想要做的事情。使用应用程序挂钩(不是全局挂钩)。



我遇到的问题是采样WM_MENUSELECT只是通过巡航导致真实状态

鼠标在子菜单上(即& Save)。显然这是不可接受的,因为我需要知道用户何时实际点击了保存。所以我去检查标志 - 这没有帮助。



所以我做了这个非常难看的测试代码,看看我是否可以采样鼠标关键状态。

给我的手指足够的时间,同时检查GetAsyncKeyState(l_Button ....



)将停顿变量从0增加到0xffff它永远不会看到鼠标点击。



然后它突然出现在我身上,我正在等待这个applcations消息队列等待

a鼠标点击。 - 这不会发生。



如果是这样的话,我现在不知道如何检测鼠标点击&当我用鼠标巡航时保存(保存菜单项)而不是触发。



这是丑陋的错误部分,我在那里采样鼠标按钮。 />


Long story short:

I needed to spy on an application so as to detect File,Save click.
I have had help both here and over at codeguru and now at the end of the week, I can do what I
set out to do. using an application hook (not a global one).

The problem I am having is sampling WM_MENUSELECT causes a "true" condition just by cruising
the mouse over the sub-menu (ie &Save). obviously this is unacceptable as I need to know when the user has actually clicked save. So I went about checking the flags - this did not help.

And so I did this very ugly piece of test code to see if I could "sample" the mouse key state.
giving my fingers enough time while incremting a dwell variable from 0 to 0xffff while checking GetAsyncKeyState(l_Button....

It never sees the mouse click.

Then it dawned on me, I am holding up this applcations message queue while I am waiting for
a mouse click. - that won''t happen.

If that is the case, I am at a loss right now as how to detect a mouse click on &Save (Save menu item) instead of firing when I cruise over it with the mouse.

Here is the ugly buggered up section where I sample the mouse button.

int dwell=0;
if(!strncmp(szmenu,"&Save",5)) // mouse is over Save menu item
{
	while(dwell < 0xffff) // long enough for me to click mouse - proof of concept....
        {
		if ((GetAsyncKeyState(VK_LBUTTON) & 0x80) != 0)
	        {
			dwell = 0xffff; // terminate while
			WritePersistFile = 1; // do what we do when user clicks Save
		}
		dwell++;
	}
}

推荐答案

我怀疑这种方式是疯狂的。我认为除了 WM_COMMAND 或其他任何生成的内容之外,你根本不需要取样 WM_MENUSELECT 通过实际点击文件保存消息。
I suspect that this way lies madness. I think you don''t need to be sampling WM_MENUSELECT at all but either WM_COMMAND or whatever else is generated as a message by actually clicking on File Save.


好吧我是傻瓜,疯了,也许是个白痴,但我做到了。



WM_MENUSELECT点击鼠标检测,对于任何像我一样吵架的人。



在MenuHookProc中,当我通过WM_MENUSELECT发现鼠标悬停在Save上时,

我将一个全局bool变量设置为true其他明智的假。



Ok I''m Stupid, Mad and maybe an idiot, but I did it.

WM_MENUSELECT Click mouse detection for anyone sturggling with this as I was.

in the MenuHookProc, when I have found via WM_MENUSELECT that the mouse is hovering over Save,
I set a global bool variable to true other wise false.

if(!strncmp(szmenu,"&Save",5)) // mouse is over Save menu item
{
      MouseOnSave = true;
}else{
     MouseOnSave = false;
}





然后我挂钩鼠标。



进入上面的MenuHookProc的WM_MENUSELECT到达任何WM_LBUTTONDOWN消息之前

到达下面。



在mouseproc()



我查找WM_LBUTTONDOWN,如果是,请检查全局MouseOnSave的状态。如果它是真的,我们在保存按钮上并点击它,以便点击我们在

实例中做的事情。



现在适合我。



Then I hook the mouse.

The WM_MENUSELECT coming into the MenuHookProc above arrives before any WM_LBUTTONDOWN message
arriving below.

In the mouseproc()

I look for WM_LBUTTONDOWN and if so, then check the state of the global MouseOnSave. If it''s true, The we are on the Save button and have clicked it so fire off what we are to do in that
instance.

Works for me for now.


这篇关于在菜单hookproc()中采样mousedown?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆