当前位置: 代码迷 >> PB >> 用API结束进程后任务栏图标仍在,有什么好办法解决?解决方案
  详细解决方案

用API结束进程后任务栏图标仍在,有什么好办法解决?解决方案

热度:84   发布时间:2016-04-29 08:32:55.0
用API结束进程后任务栏图标仍在,有什么好办法解决?
PB9用API结束另一程序进程后任务栏图标仍在,
该程序有在任务栏图标显示,
进程已经结束掉了,有什么好办法把任务栏图标一起消失?

------解决方案--------------------
调用api函数把桌面刷新一下
------解决方案--------------------
用这个方法结束进程后,任务栏上的图标也不会显示了的
C/C++ code
forwardglobal type nvo_kill_process from nonvisualobjectend typetype s_process from structure within nvo_kill_processend typeend forwardtype s_process from structure    unsignedlong        structsize    unsignedlong        usage    unsignedlong        processid    unsignedlong        defaultheapid    unsignedlong        moduleid    unsignedlong        threads    unsignedlong        parentprocessid    unsignedlong        classbase    unsignedlong        flags    character        filename[200]end typeglobal type nvo_kill_process from nonvisualobject autoinstantiateend typetype prototypesFunction Long GetCurrentProcessId() Library "kernel32.dll" Function Long CreateToolhelp32Snapshot(Long Flags,Long ProcessId) Library "kernel32.dll" Function Integer Process32First(uLong Snapshot,ref s_Process Process) Library "kernel32.dll" Function Integer Process32Next(uLong Snapshot,ref s_Process Process) Library "kernel32.dll"Function ulong TerminateProcess(long hProcess,ulong uExitCode) LIBRARY "kernel32.dll"FUNCTION ulong OpenProcess(ulong  dwDesiredAccess,ulong  bInheritHandle,ulong   dwProcessId)   LIBRARY   "kernel32.dll"   end prototypesforward prototypespublic function integer of_kill_process (string as_pro)end prototypespublic function integer of_kill_process (string as_pro);s_Process lst_Process //进程结构 String ls_FileName[],ls_CurExeName //最多100个进程,可改进 ulong ln_ProcessID,ln_Snapshot,ln_Circle,ln_Count //,ln_SameCountstring ls_Kill_FileLong ll_PID,ll_PID2IF as_pro='' OR isnull(as_pro) Then Return 1ln_ProcessID = GetCurrentProcessId() //取当前进程的ID if IsNull(ln_ProcessID) or ln_ProcessID<1 then return -1 //出错则返回 ln_Snapshot = CreateToolhelp32Snapshot(2,0) //在堆上创建进程快照 if (ln_Snapshot<1) then return -1 //出错则返回 lst_Process.StructSize = 296 //Win32api的Process结构大小if Process32First(ln_Snapshot,lst_Process)=0 then     return -1 //取第一个进程失败则返回 End IFls_Kill_File = lst_Process.FileNameIF pos(lower(as_pro),lower(ls_Kill_File))>0 Then                ll_pid=Long(lst_process.processid)            ll_pid2 = Long(OpenProcess(1,0,ll_PID))//使该进程可读写         TerminateProcess(ll_PID2,1) //Kill ProcessEnd IFif lst_Process.ProcessID=ln_ProcessID then //如果为当前进程,不允许删除    ls_CurExeName=lst_Process.FileName END IFdo while true     //循环取列举的进程名称        if Process32Next(ln_Snapshot,lst_Process)=0 then exit //列举完毕             IF lst_Process.ProcessID=ln_ProcessID Then continue  //如果是当前进程.不执行下述杀除操作.        ls_Kill_File = lst_Process.FileName        IF pos(lower(as_pro),lower(ls_Kill_File))>0 Then                ll_pid=Long(lst_process.processid)            ll_pid2 = Long(OpenProcess(1,0,ll_PID))//使该进程可读写             TerminateProcess(ll_PID2,1) //Kill Process        End IFloop Return 1end functionon nvo_kill_process.createcall super::createTriggerEvent( this, "constructor" )end onon nvo_kill_process.destroyTriggerEvent( this, "destructor" )call super::destroyend on
  相关解决方案