【发布时间】:2010-10-07 23:01:21
【问题描述】:
我真的很难找到一种方法来提出另一个程序窗口。
例如,我使用 FindWindow 来查找记事本的句柄。然后我尝试使用 SetWindowPos(hWnd, 0,0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
但它只是不起作用! ShowWindow 也不行!
你能帮我看一下sn-p的代码吗?
谢谢
【问题讨论】:
我真的很难找到一种方法来提出另一个程序窗口。
例如,我使用 FindWindow 来查找记事本的句柄。然后我尝试使用 SetWindowPos(hWnd, 0,0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);
但它只是不起作用! ShowWindow 也不行!
你能帮我看一下sn-p的代码吗?
谢谢
【问题讨论】:
不知道这是否是同一件事,但在 Windows 开发的某个时刻,微软添加了一些过于聪明的“反弹出”代码,这将阻止没有焦点的程序取消-最小化它的窗口......相反,程序栏中的窗口条目只会闪烁。也许有类似的逻辑阻止非前台程序将其窗口向前移动?
无论如何,这里有一些代码可以尝试,可能有帮助也可能没有帮助:
// Check to see if we are the foreground thread
DWORD foregroundThreadID = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
DWORD ourThreadID = GetCurrentThreadId();
// If not, attach our thread's 'input' to the foreground thread's
if (foregroundThreadID != ourThreadID) AttachThreadInput(foregroundThreadID, ourThreadID, TRUE);
// Bring our window to the foreground
SetForegroundWindow(hWnd);
// If we attached our thread, detach it now
if (foregroundThreadID != ourThreadID) AttachThreadInput(foregroundThreadID, ourThreadID, FALSE);
// Force our window to redraw
InvalidateRect(hWnd, NULL, TRUE);
【讨论】: