在本人的《自动关闭信息提示窗体的实现》中实现了利用线程来关闭不需要的窗体技术,它所实现的是关闭同一程序中的窗体,而有时是需要关闭不在一个程序中的窗体的。比如,现在所见到的“广告杀手”(自动关闭广告窗体的一个程序)。
      实现关闭窗体的关键在于找到该窗体的句柄,之后就可以发送WM_CLOSE给该窗体实现窗体的关闭。下面就是一个典型的例子用来关闭指定窗体标题以及窗体类名称的一个函数。
Procedure TForm1.Button1Click(Sender: TObject);
var
 hCurrentWindow: HWnd;
 szText: array[0..254] of char;
begin
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
  while hCurrentWindow <> 0 do
  begin
    if GetWindowText(hCurrentWindow, @szText, 255)>0 then
    begin
       if StrPas(@szText))=’窗体标题’ then
if GetClassName(hCurrentWindow, @szText, 255)>0 then
        if StrPas(@szText))=’窗体类名称’ then
   break;
    end;
   hCurrentWindow:=GetWindow(hCurrentWindow, GW_HWNDNEXT);
 end;