本文整理自网络,侵删。
Delphi使程序的窗口出现在最前面并激活
var
pt, OldPt, NewPt: TPoint;
begin
//判断Application是否最小化,而不是主窗口的Handle, 使用Restore来还原
if IsIconic(Application.Handle) then
Application.Restore;
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
// 保存鼠标位置,模拟点击窗口,然后再还原鼠标位置 www.delphitop.com
GetCursorPos(OldPt);
NewPt:=Point(0, 0);
Windows.ClientToScreen(Handle, NewPt);
SetCursorPos(NewPt.X, NewPt.Y);
mouse_event(MOUSEEVENTF_LEFTDOWN, NewPt.X, NewPt.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, NewPt.X, NewPt.Y, 0, 0);
SetCursorPos(OldPt.X, OldPt.Y);
end;
相关阅读 >>
Delphi2010中字符串汇编需要注意的一点,以及支持2010的aes加密库
Delphi setfileattributes 功能:修改文件属性
Delphi2010中使用pchar时e2010 incompatible types: 'char' and 'ansichar' 错误的处理
更多相关阅读请进入《Delphi》频道 >>