大家一定用过xp吧,应该知道xp有一个功能很不错,可以一次性关闭已打开的程序,一般程序运行后,会在任务栏上有一个按钮,按钮上有窗口的名字。现在大家开始动手吧,
我已经找到以下程序可以列出 任务栏上有按钮的所以程序窗口名称。
****************************************************************
uses shellapi;function GetText(Wnd : HWND) : string;
var
textlength : integer;
text : PChar;
begin
textlength:=SendMessage(Wnd,WM_GETTEXTLENGTH,0,0);
if textlength=0 then
Result := ''
else begin
getmem(text,textlength+1);
SendMessage(Wnd,WM_GETTEXT,textlength+1,Integer(text));
Result:=text;
freemem(text);
end;
end;function EnumWindowsProc (Wnd: HWND; LParam: LPARAM): BOOL; stdcall;
begin
Result := True;
if (IsWindowVisible(Wnd)) and
(GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
begin
Form1.Listbox1.items.add('Handle:'+Inttostr(Wnd)+',Text:'+GetText(Wnd));
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
Param : Longint;
begin
EnumWindows(@EnumWindowsProc , Param); //列出已运行的程序
end;请大家帮忙练习一下,如果将这些已列出的程序,一个个关闭。期待中。
我已经找到以下程序可以列出 任务栏上有按钮的所以程序窗口名称。
****************************************************************
uses shellapi;function GetText(Wnd : HWND) : string;
var
textlength : integer;
text : PChar;
begin
textlength:=SendMessage(Wnd,WM_GETTEXTLENGTH,0,0);
if textlength=0 then
Result := ''
else begin
getmem(text,textlength+1);
SendMessage(Wnd,WM_GETTEXT,textlength+1,Integer(text));
Result:=text;
freemem(text);
end;
end;function EnumWindowsProc (Wnd: HWND; LParam: LPARAM): BOOL; stdcall;
begin
Result := True;
if (IsWindowVisible(Wnd)) and
(GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
begin
Form1.Listbox1.items.add('Handle:'+Inttostr(Wnd)+',Text:'+GetText(Wnd));
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
Param : Longint;
begin
EnumWindows(@EnumWindowsProc , Param); //列出已运行的程序
end;请大家帮忙练习一下,如果将这些已列出的程序,一个个关闭。期待中。
解决方案 »
- 急,救我,在线!!!!!
- 百分求助!有关FastReport的DataSets(数据字典)的问题,THANKS!
- 动态创建控件的几个函数之间调用问题。。
- 控件问题,在线等待!!!!!
- 有人有现成的物业管理 请发至[email protected]
- 如何动态创建一个ini文件?
- 关于ADO
- intebase 数据库 一个及其简单的问题 表是只读的???
- TCPClient的问题
- DELPHI 与串口 COM 的实时通讯?
- 在Delphi8中,出現Unable to attach to ASP.Net worker process(typically aspnet_wp.exe or w3wp.exe)該如何解決?
- DLL 的问题哦,快来看看。
ZAppName: array[0..127] of char;
begin
StrPCopy(ZAppName, '标题');
closeWindow(FindWindow(nil, ZAppName))
HANDLE hThread,
DWORD dwExitCode
);
var
hprocessID: INTEGER;
processHandle: THandle;
DWResult: DWORD;
begin
SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult);
if isWindow(hWindowHandle) then
begin
// PostMessage(hWindowHandle, WM_QUIT, 0, 0);
{ Get the process identifier for the window}
GetWindowThreadProcessID(hWindowHandle, @hprocessID);
if hprocessID <> 0 then
begin
{ Get the process handle }
processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
False, hprocessID);
if processHandle <> 0 then
begin
{ Terminate the process }
TerminateProcess(processHandle, 0);
CloseHandle(ProcessHandle);
end;
end;
end;
end;
function EnabledDebugPrivilege(const bEnabled: Boolean):Boolean;
var
hToken: THandle;
tp: TOKEN_PRIVILEGES;
a: DWORD;
const
SE_DEBUG_NAME = 'SeDebugPrivilege';
begin
Result:=False;
//打开当前Process的令牌(我一直叫Token为令牌)
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, hToken)) then
begin
//调整令牌的权限,也就是加上或者取消调试权限(SE_DEBUG_NAME)
tp.PrivilegeCount :=1;
LookupPrivilegeValue(nil,SE_DEBUG_NAME ,tp.Privileges[0].Luid);
if bEnabled then
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
tp.Privileges[0].Attributes := 0;
a:=0;
AdjustTokenPrivileges(hToken,False,tp,SizeOf(tp),nil,a);
Result:= GetLastError = ERROR_SUCCESS;
CloseHandle(hToken);
end;
end;procedure KillProcess(ProcessId:THandle);
Var
Hds:THandle;
ECode:Cardinal;
begin
Hds:=OpenProcess(PROCESS_ALL_ACCESS,true,ProcessId);
if GetExitCodeProcess(Hds,ECode) then
TerminateProcess(Hds,ECode);
end;Function GetProcessFullPath(Name:String):String;
Var
Lp:TProcessEntry32;
Hd:THandle;
begin
EnabledDebugPrivilege(true);
Try
Lp.dwSize:=sizeof(TProcessEntry32);
Hd:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if Process32First(Hd,Lp) then
Repeat
Try
KillProcess(Lp.th32ProcessID)
Except
end;
Until Process32Next(Hd,Lp)=False;
CloseHandle(Hd);
Finally
EnabledDebugPrivilege(false);
end;
end;