delphi 将被其他窗体遮住的窗体弹到最前面  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 将被其他窗体遮住的窗体弹到最前面


unit SysFocus;

interface

uses

Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs;

type

TSysFocus=class(TComponent)

public

function GetSysFocus:integer;

function SetSysFocus(hwnd:integer):integer;

end;

implementation

function TSysFoucs.GetSysFocus;//取当前活动窗口

var

hOtherWin,OtherThreadID,hFocusWin:integer;

begin

hOtherWin:=GetForegroundWindow;

OtherThreadID:=GetWindowThreadProcessID(hOtherWin,nil);

if AttachThreadInput(GetcurrentThreadID,OtherThreadID,True) then

begin

hFocusWin:=GetFocus;

result:=GetFocus;

if HFocusWin<>0 then

try

//SendMessage(GetFocus,WM_COPY,0,0);//书上是这么写的

finally

AttachThreadInput(GetcurrentThreadID,OtherThreadID,False);

end;

end

else result:=GetFocus;

end;

function TSysFocus.SetSysFocus(hwnd:integer):integer;//设置某窗口为活动窗口

var

hOtherWin,OtherTHreadID,hFocusWin:integer;

begin

hOtherWin:=GetForegroundWindow;

OtherThreadID:=GetWindowThreadProcessID(hOtherWin,nil);

if AttachThreadInput(GetcurrentThreadID,OtherThreadID,True) then

begin

hFocusWin:=GetFocus;

SetFocus(hwnd);

//SendMessage(hwnd,WM_COPY,0,0);

if hFocusWin<>0 then

try

//SendMessage(GetFocus,WM_COPY,0,0);

finally

AttachThreadInput(GetCurrentTHreadID,OtherTHreadID,False);

end;

end

else result:=SetFocus(hwnd);

end;

end.


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.052044868469238 seconds