首页| 论坛| 消息

标题:Windows下 , 自己把自己 激活窗口
作者:cyberpunker
日期:2017-08-04 08:57
内容:

Windows下,Qt激活指定句柄的窗口
http://blog.csdn.net/aid414944/article/details/18993559
亲测可用:
#ifdef Q_OS_WIN
void activateMsWindow(WId id)
{
//声明需要使用的函数指针变量
/*user32.dll*/
typedef unsigned int(_stdcall*GetWindowThreadProcessId)(WId id, unsigned int *lpdwProcessId);
GetWindowThreadProcessId getWindowThreadProcessId;
typedef WId(_stdcall*GetForegroundWindow)();
GetForegroundWindow getForegroundWindow;
typedef bool(_stdcall*SetForegroundWindow)(WId id);
SetForegroundWindow setForegroundWindow;
typedef WId(_stdcall*SetFocus)(WId id);
SetFocus setFocus;
typedef bool(_stdcall*AttachThreadInput)(unsigned int idAttach, unsigned int idAttachTo, bool fAttach);
AttachThreadInput attachThreadInput;
/*kernel32.dll*/
typedef unsigned int(_stdcall*GetCurrentThreadId)();
GetCurrentThreadId getCurrentThreadId;

//获取函数地址
QLibrary user32("user32");
user32.load();
getWindowThreadProcessId = (GetWindowThreadProcessId)user32.resolve("GetWindowThreadProcessId");
getForegroundWindow = (GetForegroundWindow)user32.resolve("GetForegroundWindow");
setForegroundWindow = (SetForegroundWindow)user32.resolve("SetForegroundWindow");
setFocus = (SetFocus)user32.resolve("SetFocus");
attachThreadInput = (AttachThreadInput)user32.resolve("AttachThreadInput");
QLibrary kernel32("kernel32");
kernel3 ..

回复 发表
主题 版块