好多好多解决方案:

var
Input: TInput;
begin
ZeroMemory(@Input, SizeOf(Input));
SendInput(, Input, SizeOf(Input)); // don't send anyting actually to another app..
SetForegroundWindow(Handle);

I am doing something similar in one of my applications and this function works for me in xp/vista/w7:

function ForceForegroundWindow(hwnd: THandle): Boolean;
const
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
ForegroundThreadID: DWORD;
ThisThreadID: DWORD;
timeout: DWORD;
begin
if IsIconic(hwnd) then ShowWindow(hwnd, SW_RESTORE); if GetForegroundWindow = hwnd then Result := True
else
begin
// Windows 98/2000 doesn't want to foreground a window when some other
// window has keyboard focus if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4)) or
((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
(Win32MinorVersion > 0)))) then
begin
Result := False;
ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow, nil);
ThisThreadID := GetWindowThreadPRocessId(hwnd, nil);
if AttachThreadInput(ThisThreadID, ForegroundThreadID, True) then
begin
BringWindowToTop(hwnd); // IE 5.5 related hack
SetForegroundWindow(hwnd);
AttachThreadInput(ThisThreadID, ForegroundThreadID, False);
Result := (GetForegroundWindow = hwnd);
end;
if not Result then
begin
// Code by Daniel P. Stasinski
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0),
SPIF_SENDCHANGE);
BringWindowToTop(hwnd); // IE 5.5 related hack
SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE);
end;
end
else
begin
BringWindowToTop(hwnd); // IE 5.5 related hack
SetForegroundWindow(hwnd);
end; Result := (GetForegroundWindow = hwnd);
end;
end;

Another solution is not to steal focus and just put the window TOPMOST in the z buffer:

procedure ForceForegroundNoActivate(hWnd : THandle);

begin
if IsIconic(Application.Handle) then
ShowWindow(Application.Handle, SW_SHOWNOACTIVATE);
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOACTIVATE or SWP_NOMOVE);
SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOACTIVATE or SWP_NOMOVE);
end;
Application.Restore; // unminimize window, makes no harm always call it
SetWindowPos(self.Handle, HWND_NOTOPMOST,0,0,0,0, SWP_NOMOVE or SWP_NOSIZE);
SetWindowPos(self.Handle, HWND_TOPMOST,0,0,0,0, SWP_NOMOVE or SWP_NOSIZE);
SetWindowPos(self.Handle, HWND_NOTOPMOST,0,0,0,0, SWP_SHOWWINDOW or SWP_NOMOVE or SWP_NOSIZE);
function WinActivate(const AWinTitle: string): boolean;
var
_WindowHandle: HWND;
begin
Result := false;
_WindowHandle := FindWindow(nil, PWideChar(AWinTitle));
if _WindowHandle <> 0 then
begin
if IsIconic(_WindowHandle) then
Result := ShowWindow(_WindowHandle, SW_RESTORE)
else
Result := SetForegroundWindow(_WindowHandle);
end;
end; if WinActivate(self.Caption) then
ShowMessage('This works for me in Windows 10');
tmpFormStyle := Application.MainForm.FormStyle;
Application.MainForm.FormStyle := fsStayOnTop;
Application.Restore; // optional
Application.BringToFront;
Application.MainForm.FormStyle := tmpFormStyle;

http://stackoverflow.com/questions/12946150/how-to-bring-my-application-to-the-front/20707637#20707637

SetForegroundWindow API函数还不够(好多好多解决方案,真是奇思妙想)的更多相关文章

  1. Delphi 常用API 函数(好多都没见过)

    AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小AnyPopup 判断屏幕上是否存在任何弹出式窗口ArrangeIconicWindows 排列一个父窗口的最小 ...

  2. Windows API 函数列表 附帮助手册

    所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...

  3. C#中可直接调用WIN32的API函数--USER32.DLL

    Win32的API函数可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候直接调用Win32的API,可以很高效的实现想要的效果. using System; using System ...

  4. API函数

    1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同 ...

  5. WINDOWS API 函数(超长,值得学习)

    一.隐藏和显示光标 函数: int ShowCursor ( BOOL bShow );  参数 bshow,为布尔型,bShow的值为False时隐藏光标,为True时显示光标:该函数的返回值为整型 ...

  6. Delphi 常用API 函数

    Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小 AnyPopup 判断屏幕上是否存在任何弹出式窗口 ArrangeIconic ...

  7. linux API函数大全

    获取当前执行路径:getcwd1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAdd ...

  8. 使用API函数EnumWindows()枚举顶层窗口

      http://simpleease.blog.163.com/blog/static/1596085820052770290/ 要枚举Windows当前所有打开的顶层窗口,可使用Windows A ...

  9. C# 窗体常用API函数 应用程序窗体查找

    常用的处理窗体的API函数如下(注意:API函数必须放在窗体中...): 使用C#语言,要引用DllImport,必须要添加using System.Runtime.InteropServices命名 ...

随机推荐

  1. Linux-shell脚本-mysql一键安装

    转自: https://blog.csdn.net/zmken497300/article/details/51615678 安装环境 CentOS-7-x86_64-DVD-1511.iso mys ...

  2. PHP基本的文件和文件夹操作常用的汇总

    资源:http://www.ido321.com/835.html 一.基本文件的操作 文件的基本操作有:文件推断.文件夹推断.文件大小.读写性推断.存在性推断及文件时间等 1: <?php 2 ...

  3. Java_压缩与解压工具类

    转载请注明出处:http://blog.csdn.net/y22222ly/article/details/52201675 zip压缩,解压 zip压缩与解压主要依靠java api的两个类: Zi ...

  4. Dojo第一节:学会使用firebug对js,Dojo进行调适

    内容概要: 学会使用firebug的基本功能 1. 简介:Firebug是Firefox的一个插件,用来对js代码进行调适的工具. (官方废话:Firebug是firefox下的一个插件,可以调试全部 ...

  5. 理解 t-SNE (Python)

    t-SNE(t-distribution Stochastic Neighbor Embedding)是目前最为流行的高维数据的降维算法. t-SNE 成立的前提基于这样的一个假设:我们现实世界观察到 ...

  6. python 左旋转字符串

    比较简单的一道题 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果.对于一个给定的字符序列S,请你把其循环左移K位后的序列输出.例如,字符序列S= ...

  7. Windows 10 子系统Linux重启(不重启Win10)

    Using CMD (Administrator) net stop LxssManager net start LxssManager

  8. 机器学习: DeepDreaming with TensorFlow (一)

    在TensorFlow 的官网上,有一个很有趣的教程,就是用 TensorFlow 以及训练好的深度卷积神经(GoogleNet)网络去生成一些有趣的pattern,通过这些pattern,可以更加深 ...

  9. 用游戏杆控制WPF中三维模型

    原文:用游戏杆控制WPF中三维模型 用游戏杆控制WPF中三维模型   今天心情比较好,不写WF的文章了,换个主题.写一个我最最最擅长的内容.   例子下载: http://files.cnblogs. ...

  10. python3 基本使用多线程

    #coding=utf-8 import threading #进口threading from time import sleep import time def task1(): print (& ...