SetForegroundWindow() 正确用法:激活一个窗口并前台显示
激活窗口,并前台显示:
//如果最小化了窗口, 就先恢复 if(IsIconic(hWnd)) { ShowWindow(hWnd, SW_RESTORE); } //激活窗口,并前台显示窗口 HWND hForeWnd = GetForegroundWindow(); DWORD dwCurID = GetCurrentThreadId(); DWORD dwForeID = GetWindowThreadProcessId(hForeWnd, NULL); 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);
来自:https://www.cnblogs.com/dengpeng1004/p/5049646.html