返回得到的菜单句柄,你枚举一下其各个项目就知道是怎么回事了。
直接对这个句柄添加删除修改菜单项就行了。菜单项对应的相应消息是 WM_SYSCOMMAND,你添加了菜单项,在WM_SYSCOMMAND 消息里面处理你的命令。
——没用过 vista , 任务栏接口是 ITastBarList,可以得到任务栏上的项目。
关于项目上的右键菜单,难道有好几种点击方法?没明白你说的意思。
你用 WM_INITMENU 拦截一下查看各子项字符串试试。
隐藏,显示其他程序的托盘图标(此为Delphi代码)Delphi
USES Commctrl,ShellAPI
procedure TForm1.Button1Click(Sender: TObject)
var TBHWND:HWND
i,count:integer
PID,PRC: THandle
Buff: PChar
Info: _TBBUTTON
R: Cardinal
S: array[0..1024] of char
begin
TBHWND := FindWindow('Shell_TrayWnd', nil) // Shell_TrayWnd: 任务栏窗口
TBHWND := FindWindowEx(TBHWND, 0, 'TrayNotifyWnd', nil)// TrayNotifyWnd:任务栏类
TBHWND := FindWindowEx(TBHWND, 0, 'ToolbarWindow32', nil) // ToolbarWindow32:托盘类,是一个toolbar// wd:=FindWindowEx(wd,0,'SysPager',NIL)
if TBHWND=0 then exit
GetWindowThreadProcessId(TBHWND, @PID)
PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID)
Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE)
count:=SendMessage(TBHWND,TB_BUTTONCOUNT,0 , 0) //托盘中button的个数,不一定是图标的个数,有些button是隐藏的。
for i:=0 to count-1 do
begin
FillChar(Info, SizeOf(Info), 0)
WriteProcessMemory(PRC, Buff, @Info, SizeOf(Info), R) //消息使用的内存空间必须在Shell之内,所以利用ReadProcessMemoery和WriteProcessMemory。
SendMessage(TBHWND, TB_GETBUTTON, i, integer(Buff))
ReadProcessMemory(PRC, Buff, @Info, SizeOf(Info), R)
SendMessage(TBHWND, TB_GETBUTTONTEXT, Info.idCommand, integer(integer(@Buff[0]) + SizeOf(Info)))
ReadProcessMemory(PRC, Pointer(integer(@Buff[0]) + SizeOf(Info)), @S[0], SizeOf(S), R)
if pos('QQ',StrPas(S))>0 then//如果button的TEXT中包含'QQ'
SendMessage(TBHWND, TB_DELETEBUTTON, i, 0) //删除
Form1.Memo1.Lines.Add(StrPas(S)) //在MEMO1中记录所有button的TEXT
end
VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE)
CloseHandle(PRC)
end
相关的消息:
TCM_ADJUSTRECT TB_ADDBITMAP
TCM_DELETEALLITEMTB_ADDBUTTONS TB_GETMAXSIZE TB_SAVERESTORE
TCM_DELETEITEM TB_ADDSTRINGTB_GETOBJECTTB_SETANCHORHIGHLIGHT
TCM_DESELECTALL TB_AUTOSIZE TB_GETPADDING TB_SETBITMAPSIZE
TCM_GETCURFOCUS TB_BUTTONCOUNT TB_GETRECT TB_SETBUTTONINFO
TCM_GETCURSELTB_BUTTONSTRUCTSIZE TB_GETROWS TB_SETBUTTONSIZE
TCM_GETEXTENDEDSTYLE TB_CHANGEBITMAP TB_GETSTATE TB_SETBUTTONWIDTH
TCM_GETIMAGELIST TB_CHECKBUTTON TB_GETSTYLE TB_SETCMDID
TCM_GETITEM TB_COMMANDTOINDEX TB_GETTEXTROWS TB_SETDISABLEDIMAGELIST
TCM_GETITEMCOUNT TB_CUSTOMIZETB_GETTOOLTIPS TB_SETEXTENDEDSTYLE
TCM_GETITEMRECT TB_DELETEBUTTON TB_HIDEBUTTON TB_SETHOTIMAGELIST
TCM_GETROWCOUNT TB_ENABLEBUTTON TB_HITTEST TB_SETHOTITEM
TCM_GETTOOLTIPS TB_GETANCHORHIGHLIGHT TB_INDETERMINATETB_SETIMAGELIST
TCM_HIGHLISHTITEMTB_GETBITMAPTB_INSERTBUTTON TB_SETINDENT
TCM_HITTEST TB_GETBITMAPFLAGS TB_INSERTMARKHITTESTTB_SETINSERTMARK
TCM_INSERTITEM TB_GETBUTTONTB_ISBUTTONCHECKED TB_SETINSERTMARKCOLOR
TCM_REMOVEIMAGE TB_GETBUTTONINFOTB_ISBUTTONENABLED TB_SETMAXTEXTROWS
TCM_SETCURFOCUS TB_GETBUTTONSIZETB_ISBUTTONHIDDEN TB_SETPADDING
TCM_SETCURSELTB_GETBUTTONTEXTTB_ISBUTTONHIGHLIGHTED TB_SETPARENT
TCM_SETEXTENDEDSTYLE TB_GETDISABLEDIMAGELIST TB_ISBUTTONINDETERMINATETB_SETROWS
TCM_SETIMAGELIST TB_GETEXTENDEDSTYLE TB_ISBUTTONPRESSED TB_SETSTATE
TCM_SETITEM TB_GETHOTIMAGELIST TB_LOADIMAGES TB_SETSTYLE
TCM_SETITEMEXTRA TB_GETHOTITEM TB_MAPACCELERATOR TB_SETTOOLTIPS
TCM_SETITEMSIZE TB_GETIMAGELIST TB_MARKBUTTON
TCM_SETMINTABWIDTH TB_GETINSERTMARKTB_MOVEBUTTON
TCM_SETPADDING TB_GETINSERTMARKCOLOR TB_PRESSBUTTON
TCM_SETTOOLTIPS TB_GETITEMRECT TB_REPLACEBITMAP
我现在也正在做这个问题,找了半天只有这一个方法其他都不行。不知道你有什么好方法没?在Hide.cpp中InitInstance()
CHideDlg dlgParent
dlgParent.Create(IDD_HIDE_DIALOG)
dlgParent.ShowWindow(SW_HIDE)
//dlgParent.ShowWindow(SW_SHOW)
CHideDlg dlg(&dlgParent)
m_pMainWnd = &dlg
int nResponse = dlg.DoModal()
dlgParent.DestroyWindow()
这样做的结果如果在CHideDlg.cpp中OnInitDialog()添加了加载图标菜单等都被加载俩次。所以我的做法是新加了一个什么都不显示的对话框ABC
我的代码
在Hide.cpp中InitInstance()
CAbcDlg dlg
m_pMainWnd = &dlg
int nResponse = dlg.DoModal()
if (nResponse == IDOK)
……
在Abc的OnCreate中(OnInitDialog里也可以吧)
if (dlg.DoModal() == IDOK) /*这个dlg是我在Abc中定义的类全局变量 CHideDlg dlg*/
OnOK()
else
OnCancel()
我这样虽然间接实现了不显示在任务栏但如果是Abc就是主窗口了吧(我也刚学)这样多了资源,而且一些处理要在CAbcDlg中处理
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)