【任务栏右键菜单】如何获得选中项内容?(200)

  • 主题发起人 主题发起人 wooiguo
  • 开始时间 开始时间
W

wooiguo

Unregistered / Unconfirmed
GUEST, unregistred user!
我已经知道怎么添加菜单和响应点击,点击时,如何获得此项菜单的Caption? const SC_MyMenuItem = WM_USER + 1; procedure TForm1.FormCreate(Sender: TObject); var myMenu:hMenu; begin Mymenu := getsystemmenu(application.Handle, false); AppendMenu(myMenu,MF_STRING,SC_MyMenuItem,'menu1'); AppendMenu(myMenu,MF_STRING,SC_MyMenuItem+1,'menu2); Application.OnMessage:=OnAppMessage; end; procedure TForm1.OnAppMessage(var Msg:TMsg;var Handled:boolean); var myMenu:hMenu; begin Mymenu := getsystemmenu(application.Handle, false); Handled:=false; if (Msg.message=WM_SYSCOMMAND) and (Msg.wParam=SC_MyMenuItem) then begin showMessage('测试1'); Handled:=True; end; if (Msg.message=WM_SYSCOMMAND) and (Msg.wParam=SC_MyMenuItem+1) then begin showMessage('测试2); Handled:=True; end; end;
 
Mymenu 定义为全局变量。一次getsystemmenu 就行,把OnAppMessage里面的 Mymenu 去掉获取菜单的Caption API int GetMenuString( HMENU hMenu, // handle to the menu UINT uIDItem, // menu item identifier LPTSTR lpString, // buffer for the string int nMaxCount, // maximum length of string UINT uFlag // options);GetMenuString(myMenu,SC_MyMenuItem,str,100,MF_BYCOMMAND);
 
在你的OnAppMessage里,取得Mymenu总项数,加个遍历,看遍历到的那项是不是点击那项,如果是,再用GetMenuString(myMenu,i,@c,254,MF_BYPOSITION)取得caption,c:array [0..256] of char.
 
多人接受答案了。
 
后退
顶部