CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  API

VB如何操作其它应用程序的菜单?

楼主supergoalcn(Supergoal)2003-02-02 01:00:36 在 VB / API 提问

目的:窗体中的Command按一下,模拟点击记事本的文件->打开   按钮。  
  用FindWindow,GetMenu,GetSubMenu后,再如何操作?  
  用SendMessage发送什么消息? 问题点数:0、回复次数:6Top

1 楼kingcom_xu(冷羽)回复于 2003-02-02 02:03:35 得分 0

获得菜单项的ID,并发送wm_commandTop

2 楼mjcom(不明飞行物)回复于 2003-02-02 10:43:53 得分 0

好啊,又多了像我一样爱管“闲事”的朋友,这个好办,我也正在进一步  
  研究呢。为了简单起见,只模拟一次按键事件,具体方法如下:  
  1。用FindWindow函数找到句柄  
  2。用FindWindowEx找到按钮句柄,或用GetMenu和GetSubMenu得到菜单项句柄  
  3。正如你所说的,用SendMessage像这个菜单项发送消息就可以了,  
   
  SendMessage   句柄,WM_COMMAND,WM_CLICKED,0  
  Top

3 楼supergoalcn(Supergoal)回复于 2003-02-02 11:24:25 得分 0

那又如何得到菜单的ID呢,Spy++没用。  
  菜单项的句柄也得不到,Spy++得不到,用GetSubMenu得到的是零。Top

4 楼feihong0233(泓)回复于 2003-02-02 17:11:40 得分 0

模拟打开吗?  
  自己弹出一个标准打开对话框,  
  然后NOTEPAD.EXE+文件名Top

5 楼supergoalcn(Supergoal)回复于 2003-02-02 19:33:44 得分 0

当然不行,记事本是我随便说的。  
  我是要知道具体的操作。Top

6 楼zyl910(编程的乐趣在于编程控制硬件,与用图形学实现绚丽效果)回复于 2003-02-04 11:31:56 得分 0

以windows98作为分界线  
  以前的一般用WM_COMMAND  
  以后的一般用WM_MENUCOMMAND  
   
   
   
   
  WM_COMMAND  
  The   WM_COMMAND   message   is   sent   when   the   user   selects   a   command   item   from   a   menu,   when   a   control   sends   a   notification   message   to   its   parent   window,   or   when   an   accelerator   keystroke   is   translated.    
   
  WM_COMMAND    
  wNotifyCode   =   HIWORD(wParam);   //   notification   code    
  wID   =   LOWORD(wParam);                   //   item,   control,   or   accelerator   identifier    
  hwndCtl   =   (HWND)   lParam;             //   handle   of   control    
     
  Parameters  
  wNotifyCode    
  Value   of   the   high-order   word   of   wParam.   Specifies   the   notification   code   if   the   message   is   from   a   control.   If   the   message   is   from   an   accelerator,   this   parameter   is   1.   If   the   message   is   from   a   menu,   this   parameter   is   0.    
  wID    
  Value   of   the   low-order   word   of   wParam.   Specifies   the   identifier   of   the   menu   item,   control,   or   accelerator.    
  hwndCtl    
  Value   of   lParam.   Handle   to   the   control   sending   the   message   if   the   message   is   from   a   control.   Otherwise,   this   parameter   is   NULL.    
  Return   Values  
  If   an   application   processes   this   message,   it   should   return   zero.    
   
  Remarks  
  Accelerator   keystrokes   that   select   items   from   the   window   menu   are   translated   into   WM_SYSCOMMAND   messages.    
   
  If   an   accelerator   keystroke   occurs   that   corresponds   to   a   menu   item   when   the   window   that   owns   the   menu   is   minimized,   no   WM_COMMAND   message   is   sent.   However,   if   an   accelerator   keystroke   occurs   that   does   not   match   any   of   the   items   in   the   window's   menu   or   in   the   window   menu,   a   WM_COMMAND   message   is   sent,   even   if   the   window   is   minimized.    
   
  If   an   application   enables   a   menu   separator,   the   system   sends   a   WM_COMMAND   message   with   the   low-word   of   the   wParam   parameter   set   to   zero   when   the   user   selects   the   separator.  
   
  QuickInfo  
      Windows   NT:   Requires   version   3.1   or   later.  
      Windows:   Requires   Windows   95   or   later.  
      Windows   CE:   Requires   version   1.0   or   later.  
      Header:   Declared   in   winuser.h.  
   
   
   
   
   
   
   
   
   
  WM_MENUCOMMAND   Notification      
   
  --------------------------------------------------------------------------------  
   
  The   WM_MENUCOMMAND   message   is   sent   when   the   user   makes   a   selection   from   a   menu.    
   
  Syntax  
   
  WM_MENUCOMMAND  
   
          WPARAM   wParam  
          LPARAM   lParam;  
           
  Parameters  
   
  wParam  
  Specifies   the   zero-based   index   of   the   item   selected.    
  Windows   98/Me:   The   high   word   is   the   zero-based   index   of   the   item   selected.   The   low   word   is   the   item   ID.    
   
  lParam  
  Handle   to   the   menu   for   the   item   selected.    
  Return   Value  
   
  No   return   value.  
  Remarks  
   
  The   WM_MENUCOMMAND   message   gives   you   a   handle   to   the   menu—so   you   can   access   the   menu   data   in   the   MENUINFO   structure—and   also   gives   you   the   index   of   the   selected   item,   which   is   typically   what   applications   need.   In   contrast,   the   WM_COMMAND   message   gives   you   the   menu   item   identifier.  
   
  The   WM_MENUCOMMAND   message   is   sent   only   for   menus   that   are   defined   with   the   MNS_NOTIFYBYPOS   flag   set   in   the   dwStyle   member   of   the   MENUINFO   structure.    
   
  Notification   Requirements  
   
  Minimum   DLL   Version   None    
  Header   Declared   in   Winuser.h,   include   Windows.h    
  Minimum   operating   systems   Included   in   Windows   98,   Windows   2000    
  Top

相关问题

  • 在VB程序中捕获另个应用程序的控件句柄并操作!
  • 反编译vb应用程序
  • 一段时间后,VB应用程序没有任何操作(键盘和鼠标没有任何操作),怎么自动关闭(能不能不在应用程序中写代码)?
  • 怎么在VB中控制另一应用程序?包括模拟点击菜单,选择任一子菜单项.解决后再放100分!
  • 如何修改已经编译好的VB应用程序中的文字信息及菜单文字(有加分)
  • 如何在一个应用程序中,调用另一个应用程序的某个菜单的功能,
  • 如何给基于Dialog的应用程序加上菜单?
  • 给基于对话框的应用程序添加菜单?
  • 怎样把其他应用程序的主菜单变灰?
  • EVC中基于Dialog的应用程序可以加菜单么?

关键词

  • 句柄
  • 菜单项
  • accelerator
  • getsubmenu
  • wm
  • notification
  • wparam
  • sendmessage
  • 打开
  • control

得分解答快速导航

  • 帖主:supergoalcn

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo