CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  API

下面的插入菜单函数怎么使?

楼主goldstar3000(蓝腾软件)2003-12-04 12:54:42 在 VB / API 提问

Declare   Function   InsertMenu   Lib   "user32"   Alias   "InsertMenuA"   (ByVal   hMenu   As   Long,   ByVal   nPosition   As   Long,   ByVal   wFlags   As   Long,   ByVal   wIDNewItem   As   Long,   ByVal   lpNewItem   As   Any)   As   Long  
  Declare   Function   CreateMenu   Lib   "user32"   Alias   "CreateMenu"   ()   As   Long  
  问题点数:0、回复次数:5Top

1 楼reayi(reayi)回复于 2003-12-04 13:31:43 得分 0

dim   hMenu   as   long  
  const   ID_NEW=100  
   
  hMenu=CreateMenu()  
  InsertMenu   (hMenu,0,MF_BYPOSITION,ID_NEW,"FILE");  
  MF_BYPOSITION:   常量,参考API   Viewer  
  Top

2 楼flc(▄︻┻┳═一)回复于 2003-12-22 16:58:14 得分 0

关注Top

3 楼passer_wave(路人)回复于 2003-12-22 17:07:44 得分 0

【操作系统】  
  Win9X:Yes  
  WinNT:Yes  
  【说明】  
      在菜单的指定位置处插入一个菜单条目,并根据需要将其他条目向下移动    
  【返回值】  
      Long,非零表示成功,零表示失败。会设置GetLastError    
  【其它】  
      在vb里使用:这个函数做出的许多改变都可以正常发挥作用,但却不能由vb菜单对象反映出来。添加的命令ID必须能由vb菜单系统识别  
  【参数表】  
      hMenu   ----------     Long,菜单的句柄  
      nPosition   ------     Long,定义了新条目插入点的一个现有菜单条目的标志符。如果在wFlags中指定了MF_BYCOMMAND标志,这个参数就代表欲改变的菜单条目的命令ID。如设置的是MF_BYPOSITION标志,这个参数就代表菜单条目在菜单中的位置,第一个条目的位置为零  
      wFlags   ---------     Long,一系列常数标志的组合。参考ModifyMenu  
      wIDNewItem   -----     Long,指定菜单条目的新菜单ID。如果在wFlags中指定了MF_POPUP标志,就应该指定弹出式菜单的一个句柄  
      lpNewItem   ------     如果在wFlags参数中设置了MF_STRING标志,就代表要设置到菜单中的字串(String)。如设置的是MF_BITMAP标志,就代表一个Long型变量,其中包含了一个位图句柄  
  Top

4 楼passer_wave(路人)回复于 2003-12-22 17:10:23 得分 0

也可参照此api来应用:  
   
  Declare   Function   InsertMenuItem   Lib   "user32"   Alias   "InsertMenuItemA"   (ByVal   hMenu   As   Long,   ByVal   un   As   Long,   ByVal   bool   As   Boolean,   lpcMenuItemInfo   As   MENUITEMINFO)   As   Long  
   
  【操作系统】  
  Win9X:Yes  
  WinNT:No  
  【说明】  
      用一个MENUITEMINFO结构指定的特征插入一个新菜单条目    
  【返回值】  
      Long,TRUE(非零)表示成功,否则返回零。会设置GetLastError    
  【其它】  
  【参数表】  
      hMenu   ----------     Long,菜单的句柄  
      un   -------------     Long,菜单条目的菜单ID。新条目会插入由这个参数指定的项目之前  
      bool   -----------     Boolean,如un指定的是条目的位置,就为TRUE,如指定的是菜单ID,就为FALSE  
      lpcMenuItemInfo   -     MENUITEMINFO,用于设置指定菜单条目的特征  
  Top

5 楼passer_wave(路人)回复于 2003-12-22 17:11:42 得分 0

例子代码:  
   
  Public   Declare   Function   GetSystemMenu   Lib   "user32.dll"   (ByVal   hWnd   As   Long,   ByVal   bRevert   As   Long)   As   Long  
  Public   Declare   Function   GetMenuItemCount   Lib   "user32.dll"   (ByVal   hMenu   As   Long)   As   Long  
  Public   Type   MENUITEMINFO  
  cbSize   As   Long  
  fMask   As   Long  
  fType   As   Long  
  fState   As   Long  
  wID   As   Long  
  hSubMenu   As   Long  
  hbmpChecked   As   Long  
  hbmpUnchecked   As   Long  
  dwItemData   As   Long  
  dwTypeData   As   String  
  cch   As   Long  
  End   Type  
  Public   Const   MIIM_STATE   =   &H1  
  Public   Const   MIIM_ID   =   &H2  
  Public   Const   MIIM_TYPE   =   &H10  
  Public   Const   MFT_SEPARATOR   =   &H800  
  Public   Const   MFT_STRING   =   &H0  
  Public   Const   MFS_ENABLED   =   &H0  
  Public   Const   MFS_CHECKED   =   &H8  
  Public   Declare   Function   InsertMenuItem   Lib   "user32.dll"   Alias   "InsertMenuItemA"   (ByVal   hMenu   As   Long,   ByVal   uItem   As   Long,   ByVal   fByPosition   As   Long,   lpmii   As   MENUITEMINFO)   As   Long  
  Public   Declare   Function   SetMenuItemInfo   Lib   "user32.dll"   Alias   "SetMenuItemInfoA"   (ByVal   hMenu   As   Long,   ByVal   uItem   As   Long,   ByVal   fByPosition   As   Long,   lpmii   As   MENUITEMINFO)   As   Long  
  Public   Declare   Function   SetWindowPos   Lib   "user32.dll"   (ByVal   hWnd   As   Long,   ByVal   hWndInsertAfter   As   Long,   ByVal   x   As   Long,   ByVal   y   As   Long,   ByVal   cx   As   Long,   ByVal   cy   As   Long,   ByVal   wFlags   As   Long)   As   Long  
  Public   Const   HWND_TOPMOST   =   -1  
  Public   Const   HWND_NOTOPMOST   =   -2  
  Public   Const   SWP_NOMOVE   =   &H2  
  Public   Const   SWP_NOSIZE   =   &H1  
  Public   Declare   Function   SetWindowLong   Lib   "user32.dll"   Alias   "SetWindowLongA"   (ByVal   hWnd   As   Long,   ByVal   nIndex   As   Long,   ByVal   dwNewLong   As   Long)   As   Long  
  Public   Const   GWL_WNDPROC   =   -4  
  Public   Declare   Function   CallWindowProc   Lib   "user32.dll"   Alias   "CallWindowProcA"   (ByVal   lpPrevWndFunc   As   Long,   ByVal   hWnd   As   Long,   ByVal   Msg   As   Long,   ByVal   wParam   As   Long,   ByVal   lParam   As   Long)   As   Long  
  Public   Const   WM_SYSCOMMAND   =   &H112  
  Public   Const   WM_INITMENU   =   &H116  
   
  '   Add   an   option   to   make   window   Form1   "Always   On   Top"   to   the   bottom   of   its   system  
  '   menu.     A   check   mark   appears   next   to   this   option   when   active.     The   menu   item   acts   as   a   toggle.  
  '   Note   how   subclassing   the   window   is   necessary   to   process   the   two   messages   needed  
  '   to   give   the   added   system   menu   item   its   full   functionality.  
   
  '   ***   Place   the   following   code   in   a   module.   ***  
   
  Public   pOldProc   As   Long     '   pointer   to   Form1's   previous   window   procedure  
  Public   ontop   As   Boolean     '   identifies   if   Form1   is   always   on   top   or   not  
   
  '   The   following   function   acts   as   Form1's   window   procedure   to   process   messages.  
  Public   Function   WindowProc   (ByVal   hwnd   As   Long,   ByVal   uMsg   As   Long,   ByVal   wParam   As   Long,   ByVal   lParam   As   Long)   As   Long  
  Dim   hSysMenu   As   Long           '   handle   to   Form1's   system   menu  
  Dim   mii   As   MENUITEMINFO     '   menu   item   information   for   Always   On   Top  
  Dim   retval   As   Long               '   return   value  
   
  Select   Case   uMsg  
  Case   WM_INITMENU  
  '   Before   displaying   the   system   menu,   make   sure   that   the   Always   On   Top  
  '   option   is   properly   checked.  
  hSysMenu   =   GetSystemMenu(hwnd,   0)  
  With   mii  
  '   Size   of   the   structure.  
  .cbSize   =   Len(mii)  
  '   Only   use   what   needs   to   be   changed.  
  .fMask   =   MIIM_STATE  
  '   If   Form1   is   now   always   on   top,   check   the   item.  
  .fState   =   MFS_ENABLED   Or   IIf(ontop,   MFS_CHECKED,   0)  
  End   With  
  retval   =   SetMenuItemInfo(hSysMenu,   1,   0,   mii)  
  WindowProc   =   0  
  Case   WM_SYSCOMMAND  
  '   If   Always   On   Top   (ID   =   1)   was   selected,   change   the   on   top/not   on   top  
  '   setting   of   Form1   to   match.  
  If   wParam   =   1   Then  
  '   Reverse   the   setting   and   make   it   the   current   one.  
  ontop   =   Not   ontop  
  retval   =   SetWindowPos(hwnd,   IIf(ontop,   HWND_TOPMOST,   HWND_NOTOPMOST),   0,   0,   0,   0,   SWP_NOMOVE   Or   SWP_NOSIZE)  
  WindowProc   =   0  
  Else  
  '   Some   other   item   was   selected.     Let   the   previous   window   procedure  
  '   process   it.  
  WindowProc   =   CallWindowProc(pOldProc,   hwnd,   uMsg,   wParam,   lParam)  
  End   If  
  Case   Else  
  '   If   this   is   some   other   message,   let   the   previous   procedure   handle   it.  
  WindowProc   =   CallWindowProc(pOldProc,   hwnd,   uMsg,   wParam,   lParam)  
  End   Select  
  End   Function  
   
  '   ***   Place   the   following   code   inside   Form1.   ***  
   
  '   When   Form1   loads,   add   Always   On   Top   to   the   system   menu   and   set   up   the  
  '   new   window   procedure.  
  Private   Sub   Form_Load()  
  Dim   hSysMenu   As   Long           '   handle   to   the   system   menu  
  Dim   count   As   Long                 '   the   number   of   items   initially   on   the   menu  
  Dim   mii   As   MENUITEMINFO     '   describes   a   menu   item   to   add  
  Dim   retval   As   Long               '   return   value  
   
  '   Get   a   handle   to   the   system   menu.  
  hSysMenu   =   GetSystemMenu(Form1.hWnd,   0)  
  '   See   how   many   items   are   currently   in   it.  
  count   =   GetMenuItemCount(hSysMenu)  
   
  '   Add   a   separator   bar   and   then   Always   On   Top   to   the   system   menu.  
  With   mii  
  '   The   size   of   the   structure.  
  .cbSize   =   Len(mii)  
  '   What   parts   of   the   structure   to   use.  
  .fMask   =   MIIM_ID   Or   MIIM_TYPE  
  '   This   is   a   separator.  
  .fType   =   MFT_SEPARATOR  
  '   It   has   an   ID   of   0.  
  .wID   =   0  
  End   With  
  '   Add   the   separator   to   the   end   of   the   system   menu.  
  retval   =   InsertMenuItem(hSysMenu,   count,   1,   mii)  
   
  '   Likewise,   add   the   Always   On   Top   command.  
  With   mii  
  .fMask   =   MIIM_STATE   Or   MIIM_ID   Or   MIIM_TYPE  
  '   This   is   a   regular   text   item.  
  .fType   =   MFT_STRING  
  '   The   option   is   enabled.  
  .fState   =   MFS_ENABLED  
  '   It   has   an   ID   of   1   (this   identifies   it   in   the   window   procedure).  
  .wID   =   1  
  '   The   text   to   place   in   the   menu   item.  
  .dwTypeData   =   "&Always   On   Top"  
  .cch   =   Len(.dwTypeData)  
  End   With  
  '   Add   this   to   the   bottom   of   the   system   menu.  
  retval   =   InsertMenuItem(hSysMenu,   count   +   1,   1,   mii)  
   
  '   Set   the   custom   window   procedure   to   process   Form1's   messages.  
  ontop   =   False  
  pOldProc   =   SetWindowLong(Form1.hWnd,   GWL_WNDPROC,   AddressOf   WindowProc)  
  End   Sub  
   
  '   Before   unloading,   restore   the   default   system   menu   and   remove   the  
  '   custom   window   procedure.  
  Private   Sub   Form_Unload(Cancel   As   Integer)  
  Dim   retval   As   Long     '   return   value  
   
  '   Replace   the   previous   window   procedure   to   prevent   crashing.  
  retval   =   SetWindowLong(Form1.hWnd,   GWL_WNDPROC,   pOldProc)  
  '   Remove   the   modifications   made   to   the   system   menu.  
  retval   =   GetSystemMenu(Form1.hWnd,   1)  
  End   SubTop

相关问题

  • 菜单响应函数问题
  • 怎样用API函数创建菜单和子菜单?附API函数说明
  • ★★ ☆☆如何在Win2000和Win98下用VB API函数把开始菜单中的最下面的“关机”选项屏蔽掉呢??
  • SOS,怎么将这个两级菜单的函数改成三级菜单的函数?
  • 用什么函数可以在字符串里插入字符?
  • insert函数为什么不能在中间进行插入?
  • VBA在excel里插入一列,用哪个函数
  • 在excel里插入一列,用哪个函数vba
  • 求插入函数,不胜感激,100分送上 谢谢!
  • 将数据插入PostgreSQL数据库,用什么函数?

关键词

  • dll
  • 菜单
  • 条目
  • 指定
  • hmenu
  • 句柄
  • 插入
  • wflags
  • mfs
  • 参数

得分解答快速导航

  • 帖主:goldstar3000

相关链接

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

广告也精彩

反馈

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