删除右下角指定的托盘图标(100分)

  • 主题发起人 主题发起人 rockmmm
  • 开始时间 开始时间
R

rockmmm

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,问题主要是因为进程强行结束后,右下角的托盘图标不消失,当鼠标移过去才消失,有没有什么办法在关闭进程时删掉之个图标,比如说是QQ的,Shell_NotifyIcon(NIM_DELETE,..),但现在后面一个参数是未知的,我能得到QQ的进程的<br> &nbsp;tagPROCESSENTRY32 = packed record<br> &nbsp; &nbsp;dwSize: DWORD;<br> &nbsp; &nbsp;cntUsage: DWORD;<br> &nbsp; &nbsp;th32ProcessID: DWORD; &nbsp; &nbsp; &nbsp; // this process<br> &nbsp; &nbsp;th32DefaultHeapID: DWORD;<br> &nbsp; &nbsp;th32ModuleID: DWORD; &nbsp; &nbsp; &nbsp; &nbsp;// associated exe<br> &nbsp; &nbsp;cntThreads: DWORD;<br> &nbsp; &nbsp;th32ParentProcessID: DWORD; // this process's parent process<br> &nbsp; &nbsp;pcPriClassBase: Longint; // Base priority of process's threads<br> &nbsp; &nbsp;dwFlags: DWORD;<br> &nbsp; &nbsp;szExeFile: array[0..MAX_PATH - 1] of Char;// Path<br> &nbsp;end;<br>通过上面的信息能不能删掉图标?如果有别的办法只要能达到效果就行!
 
自已顶!
 
没有人会吗?还是不愿意说?帮帮忙啊!
 
通过进程自己删除比较难以办到,因为强制关闭进程该进程是得不到任何将要被关闭的消息所以你没有办法来处理善后的事。比较好的办法是开一个子进程来监视主进程的活动,发现被关闭了则发出刷新系统托盘区的消息让系统重画就可以了。
 
补充一下,当进程关闭时其实属于该进程的托盘图标就已经不存在了,不需要Shell_NotifyIcon(NIM_DELETE,..)
 
//向任务栏添加一个图标后马上删除,使任务栏刷新。你看看这样行吗?<br> &nbsp;lpData := new(PNotifyIconDataA);<br> &nbsp;lpData.cbSize := 88;<br> &nbsp;lpData.Wnd := Form1.Handle;<br> &nbsp;lpData.hIcon := Form1.Icon.Handle;<br> &nbsp;lpData.uCallbackMessage := 0;<br> &nbsp;lpData.uID :=0;<br> &nbsp;lpData.szTip := 'Samples';<br> &nbsp;lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;<br> &nbsp;Shell_NotifyIcon(NIM_ADD,lpData);<br> &nbsp;Shell_NotifyIcon(NIM_DELETE,lpData);<br> &nbsp;dispose(lpData);
 
大唐电信<br>我试一下你的方法,一旦OK,马上送分。<br>另外,Rainstorey:<br>//补充一下,当进程关闭时其实属于该进程的托盘图标就已经不存在了,不需要Shell_NotifyIcon(NIM_DELETE,..) <br>删除图标的操作能否在结束进程前操作?如果可以的话,就更好了!
 
大唐电信,你的方法不行!<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>lpdata: TNotifyIcondataA;<br>begin<br> &nbsp;lpData.cbSize := 88;<br> &nbsp;lpData.Wnd := Form1.Handle;<br> &nbsp;lpData.hIcon := Form1.Icon.Handle;<br> &nbsp;lpData.uCallbackMessage := 0;<br> &nbsp;lpData.uID :=0;<br> &nbsp;lpData.szTip := 'Samples';<br> &nbsp;lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;<br> &nbsp;Shell_NotifyIcon(NIM_ADD,@lpData);<br> &nbsp;Shell_NotifyIcon(NIM_DELETE,@lpData);<br>end;<br>实现不了!
 
我也遇到帮助顶
 
自己多写一小段程序,模拟鼠标扫过系统托盘区就可以了。
 
其实只是一个刷新问题,如果程序正常退出时图标应该可以自动消失的,而强行结束的话有点“暴力”,估计进程资源并没有马上释放,等你移动到托盘时系统在响应这个事件时会自动更新,可以试试拦截结束进程的那个api,让它在调用时刷新下!
 
我以前也问过<br>但没有找到答案
 
我也存在这个问题,顶
 
下面的代码可以隐藏掉QQ的图标,你可以结束进程前操作。<br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> v_hShellTray: &nbsp;THandle;<br> v_hTrayNotify: THandle;<br> v_hToolBar: &nbsp; &nbsp;THandle;<br> i,j:integer;<br> &nbsp; Info: &nbsp; _TBBUTTON;<br> buffer:pchar;<br> PID: &nbsp; THandle;<br> PRC: &nbsp; THandle;<br> R: &nbsp; Cardinal;<br> S:array[0..1024] of char;<br> MaxWidth: integer;<br> temps:string;<br> lpData:PNotifyIconData;<br>begin<br> &nbsp;v_hShellTray := FindWindow('Shell_TrayWnd', nil);<br> &nbsp;v_hTrayNotify := FindWindowEx(v_hShellTray, 0, 'TrayNotifyWnd', nil);<br> &nbsp;v_hToolBar := FindWindowEx(v_hTrayNotify, 0, 'ToolbarWindow32', nil);<br><br> &nbsp;GetWindowThreadProcessId(v_hToolBar, &nbsp; @PID);<br> &nbsp;PRC &nbsp; := &nbsp; OpenProcess(PROCESS_VM_OPERATION &nbsp; or &nbsp; PROCESS_VM_READ &nbsp; or &nbsp; PROCESS_VM_WRITE, &nbsp; False, &nbsp; PID);<br> &nbsp;Buffer &nbsp; := &nbsp; VirtualAllocEx(PRC, &nbsp; nil, &nbsp; 4096, &nbsp; MEM_RESERVE &nbsp; or &nbsp; MEM_COMMIT, &nbsp; PAGE_READWRITE);<br><br> &nbsp;j:=SendMessage(v_hToolBar,TB_BUTTONCOUNT,0,0);<br> &nbsp;for i:=0 to j-1 do<br> &nbsp;begin<br> &nbsp; &nbsp; FillChar(Info, &nbsp; SizeOf(Info), &nbsp; 0);<br> &nbsp; &nbsp; WriteProcessMemory(PRC, &nbsp; Buffer, &nbsp; @Info, &nbsp; SizeOf(Info), &nbsp; R);<br><br> &nbsp; &nbsp; SendMessage(v_hToolBar, &nbsp; TB_GETBUTTON, &nbsp; i, &nbsp; integer(Buffer));<br> &nbsp; &nbsp; ReadProcessMemory(PRC, &nbsp; Buffer, &nbsp; @Info, &nbsp; SizeOf(Info), &nbsp; R);<br> &nbsp; &nbsp; if &nbsp;Info.iString&lt;&gt;-1 then<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(v_hToolBar, &nbsp; TB_GETBUTTONTEXT, &nbsp; Info.idCommand, &nbsp; integer(integer(@Buffer[0]) &nbsp; + &nbsp; SizeOf(Info)));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReadProcessMemory(PRC, &nbsp; Pointer(integer(@Buffer[0]) &nbsp; + &nbsp; SizeOf(Info)), &nbsp; @S[0], &nbsp; SizeOf(S), &nbsp; R);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;temps:=s;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if pos('QQ',temps)&gt;0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SendMessage(v_hToolBar, TB_HIDEBUTTON, Info.idCommand, integer(true));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;VirtualFreeEx(PRC, &nbsp; Buffer, &nbsp; 0, &nbsp; MEM_RELEASE);<br> &nbsp;CloseHandle(PRC);<br> &nbsp; &nbsp;//向任务栏添加一个图标后马上删除,使任务栏刷新。<br> &nbsp;lpData := new(PNotifyIconDataA);<br> &nbsp;lpData.cbSize := 88;<br> &nbsp;lpData.Wnd := Form1.Handle;<br> &nbsp;lpData.hIcon := Form1.Icon.Handle;<br> &nbsp;lpData.uCallbackMessage := 0;<br> &nbsp;lpData.uID :=0;<br> &nbsp;lpData.szTip := 'Samples';<br> &nbsp;lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;<br> &nbsp;Shell_NotifyIcon(NIM_ADD,lpData);<br> &nbsp;Shell_NotifyIcon(NIM_DELETE,lpData);<br> &nbsp;dispose(lpData);<br>end;
 
接受答案了.
 
后退
顶部