如何在程序中将一个被其它程序遮住的窗口激活并弹出到所有窗口的最前面?(50分)

  • 主题发起人 主题发起人 peng_qs
  • 开始时间 开始时间
嘿嘿,正好我今天看到,贴给你。<br><br>unit SysFocus;<br><br>interface<br>uses<br>&nbsp; Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs;<br>type<br>&nbsp; TSysFocus=class(TComponent)<br>&nbsp; &nbsp; public<br>&nbsp; &nbsp; &nbsp; function GetSysFocus:integer;<br>&nbsp; &nbsp; &nbsp; function SetSysFocus(hwnd:integer):integer;<br>&nbsp; end;<br><br>implementation<br><br>function TSysFoucs.GetSysFocus;//取当前活动窗口<br>var<br>&nbsp; hOtherWin,OtherThreadID,hFocusWin:integer;<br>begin<br>&nbsp; hOtherWin:=GetForegroundWindow;<br>&nbsp; OtherThreadID:=GetWindowThreadProcessID(hOtherWin,nil);<br>&nbsp; if AttachThreadInput(GetcurrentThreadID,OtherThreadID,True) then<br>&nbsp; begin<br>&nbsp; &nbsp; hFocusWin:=GetFocus;<br>&nbsp; &nbsp; result:=GetFocus;<br>&nbsp; &nbsp; if HFocusWin&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; //SendMessage(GetFocus,WM_COPY,0,0);//书上是这么写的<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; AttachThreadInput(GetcurrentThreadID,OtherThreadID,False);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end<br>&nbsp; else result:=GetFocus;<br>end;<br><br>function TSysFocus.SetSysFocus(hwnd:integer):integer;//设置某窗口为活动窗口<br>var<br>&nbsp; hOtherWin,OtherTHreadID,hFocusWin:integer;<br>begin<br>&nbsp; hOtherWin:=GetForegroundWindow;<br>&nbsp; OtherThreadID:=GetWindowThreadProcessID(hOtherWin,nil);<br>&nbsp; if AttachThreadInput(GetcurrentThreadID,OtherThreadID,True) then<br>&nbsp; begin<br>&nbsp; &nbsp; hFocusWin:=GetFocus;<br>&nbsp; &nbsp; SetFocus(hwnd);<br>&nbsp; &nbsp; //SendMessage(hwnd,WM_COPY,0,0);<br>&nbsp; &nbsp; if hFocusWin&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; //SendMessage(GetFocus,WM_COPY,0,0);<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; AttachThreadInput(GetCurrentTHreadID,OtherTHreadID,False);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end<br>&nbsp; else result:=SetFocus(hwnd);<br>end;<br><br>end.<br>
 
接受答案了.
 
后退
顶部