C++代码
1
2
3
4
5
6
7
8
9
10
11
12
13
|
BOOL
SetTopWindow(
HWND
hWnd)
{
HWND
hForeWnd = GetForegroundWindow();
DWORD
dwForeID = GetWindowThreadProcessId(hForeWnd, NULL);
DWORD
dwCurID = GetCurrentThreadId();
AttachThreadInput(dwCurID, dwForeID, TRUE);
ShowWindow(hWnd, SW_SHOWNORMAL);
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
SetForegroundWindow(hWnd);
AttachThreadInput(dwCurID, dwForeID, FALSE);
return
TRUE;
}
|
描述:一个解决SetForegroundWindow和BringWindowToTop等函数有时失败,无法将窗口带到前台的问题。 以上是据说是微软的标准调用代码,包试包灵,童叟无欺,解决了困扰我很久的问题,有需要的赶紧收下吧!