enumwindows()如何用法,我要关闭特定的窗口该怎么办(100分)

  • 主题发起人 主题发起人 flyinsky
  • 开始时间 开始时间
function EnumWindowsProc(AHWnd: HWnd;<br>&nbsp; LPARAM: lParam): boolean; stdcall;<br>var<br>&nbsp; WndCaption: array[0..254] of char;<br>begin<br>&nbsp; GetWindowText(AHWnd, @WndCaption, 254);<br>&nbsp; mainform.lb_window.Items.Add(StrPas(WndCaption));<br>&nbsp; mainform.LB_object_hwnd.Items.Add(inttostr(ahwnd));<br>&nbsp; Result := True;<br>end;<br><br>procedure Tmainform.BB_findClick(Sender: TObject);<br>begin<br>&nbsp; &nbsp; &nbsp;lb_window.Items.Clear;<br>&nbsp; &nbsp; &nbsp;lb_object_hwnd.Items.Clear;<br>&nbsp; &nbsp; &nbsp;EnumWindows(@EnumWindowsProc, 0);<br>end;<br>
 
那我如何用来自动关闭窗口而保留特定的窗口呢,要取的要保留窗口的ID号吧
 
再回调函数中根据得到的句柄, 判断是否是要关闭的窗口,<br>是就关闭, 不是就放过.<br>function EnumWindowsProc(AHWnd: HWnd; //此处 aHWND 就是窗口句柄.<br>&nbsp; LPARAM: lParam): boolean; stdcall;<br>
 
最好用POSTMESSAGE(AHWnd,WM_CLOSE,0,0),而不用SENDMESSAGE;
 
为什么不能用SENDMESSAGE?
 
如果是特定的窗口就不用EnumWindowsProc了,直接用FindWindow(),<br>反正特定窗口的名字你是知道的。这样容易些
 
不,特定窗口我应该是不知道的,因为由程序自动随机打开一个浏览器窗口后,<br><br>自动进行浏览,当浏览过程中出现新窗口时要关闭它,而只保留原来一个浏览窗口。
 
多人接受答案了。
 
后退
顶部