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.

相关阅读 >>

Delphi fmx调用jar里的java类init方法

Delphi 2009 中 tstrings 与 tstream 的增强

Delphi 快速读取写入注册表参数值的函数

Delphi mscomm 比较完整的用法例子

Delphi中如何向某个ip不间断的发送数据

Delphi edit只允许输入数字

Delphi system 中的数学函数

Delphi 获取与设置系统环境变量

Delphi qr /条形码扫描仪应用示例代码(使用zxing,tframestand)

Delphi dbgrideh 的分组统计 datagrouping

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...