怎么用sendmessage向菜单发送消息完成鼠标点击事件? ( 积分: 100 )

  • 主题发起人 主题发起人 funxu
  • 开始时间 开始时间
F

funxu

Unregistered / Unconfirmed
GUEST, unregistred user!
我用findwindows找到一个窗体句柄不管是用getmenu或者遍历其控件向他发送消息,该菜单都没有相应,我用了postmessage,sendmessage模拟鼠标事件或者模拟热健均没有效果,只有用mouse_event移动到菜单上再模拟鼠标按下事件或者用keybd_event才行,另外delphi自己做的程序中向菜单句柄发送消息也收不到回应,why?
 
我用findwindows找到一个窗体句柄不管是用getmenu或者遍历其控件向他发送消息,该菜单都没有相应,我用了postmessage,sendmessage模拟鼠标事件或者模拟热健均没有效果,只有用mouse_event移动到菜单上再模拟鼠标按下事件或者用keybd_event才行,另外delphi自己做的程序中向菜单句柄发送消息也收不到回应,why?
 
给菜单所在的窗体发送WM_COMMAND消息..[:)]
 
临时做了个例子还是不行<br>var<br>h:thandle;<br>p:pchar;<br>j,i:integer;<br>ListPos: TPoint;<br>MousePos: TSmallPoint;<br>begin<br>p:=allocmem(255);<br>h:=getmenu(form1.Handle);<br>i:=getmenuitemcount(h);<br> &nbsp;for j:=0 to i-1 do<br> &nbsp;begin<br> &nbsp;GetMenuString(h,j,p,255,MF_BYPOSITION);<br> &nbsp;form1.edit3.text:=p;<br> &nbsp; &nbsp;if form1.edit3.text='ff&amp;c' then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; postmessage(h,WM_command,vk_menu+key_c,MainMenu1.Items[0].Handle);//是这样吗?没有反应呀<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>{setcursorpos(212,200);//模拟鼠标事件可以实现点击效果<br> &nbsp;mouse_event (MOUSEEVENTF_LEFTDOWN, 0,0,0,0);<br> &nbsp;mouse_event (MOUSEEVENTF_LEFTUP, 0,0,0,0);<br>setcursorpos(212,222);<br> &nbsp;mouse_event (MOUSEEVENTF_LEFTDOWN, 0,0,0,0);<br> &nbsp;mouse_event (MOUSEEVENTF_LEFTUP, 0,0,0,0);<br>}<br>//以下代码均无反应<br>//postmessage(h,WM_LBUTTONdown,0,0);<br>//postmessage(h,WM_LBUTTONup,0,0);<br>{postmessage(h,WM_KEYDOWN,0,Key_C);<br>postmessage(h,WM_KEYDOWN,0,VK_MENU);<br>postmessage(h,WM_KEYup,0,VK_MENU);<br>postmessage(h,WM_KEYup,0,Key_C);}<br>freemem(p);
 
发送wm_command消息,下面是个单击计算器的&quot;帮助&quot;-&amp;gt;&quot;关于&quot;菜单的例子<br>var<br> &nbsp;wh,mh:thandle;<br> &nbsp;id:word;<br>begin<br> &nbsp;wh:=findwindow(nil,'计算器');<br> &nbsp;if wh&amp;lt;&amp;gt;0 then<br> &nbsp;begin<br> &nbsp; &nbsp;mh:=getmenu(wh);<br> &nbsp; &nbsp;mh:=getsubmenu(mh,2); //取得帮助菜单句柄<br> &nbsp; &nbsp;id:=getmenuitemid(mh,2); //取得关于菜单的ID<br> &nbsp; &nbsp;postmessage(wh,wm_command,MAKEWPARAM(id,0),0);<br> &nbsp;end;<br>end;
 
接受答案了.
 
后退
顶部