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 新建文件 复制文件 重命名文件名时 文件存在自动重命名

Delphi使用xmlhttp组件代码

Delphi 获取安卓机器码

Delphi 注入不用writeprocessmemory 函数

Delphi 防止程序重复执行的单元

Delphi 关于access的日期类型字段比较的一点认识

Delphi debug release区别是什么?

Delphi 生成二维码图形

Delphi2010 的自带的内存泄漏检测

Delphi listview用法

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



打赏

取消

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

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

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

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

评论

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