C/C++/C# Force window to be on top
有没有办法迫使另一个窗口位于顶部?不是应用程序的窗口,而是已经在系统上运行的另一个窗口。 (Windows,C / C / C#)
1 | SetWindowPos(that_window_handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); |
您可以使用Win32 API BringWindowToTop。这需要HWND。
您还可以使用Win32 API SetWindowPos,它还可以使您将窗口设置为顶级窗口。
如果要将应用程序窗口从后面(或最小化)移到前面,
BringWindowToTop()无效。以下代码可靠地完成了此技巧:
1 2 | ShowWindow(hwnd, SW_MINIMIZE); ShowWindow(hwnd, SW_RESTORE); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | BOOL CALLBACK EnumWindowsProc(HWND hWnd, long lParam) { wchar_t buff[255]; if (IsWindowVisible(hWnd)) { GetWindowText(hWnd, (LPWSTR) buff, 254); //wprintf(L"%s\ ", buff); wstring ws = buff; if (ws.find(L"Firefox") != ws.npos) { ::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); } } return TRUE; } int main(){ BOOL enumeratingWindowsSucceeded = ::EnumWindows( EnumWindowsProc, NULL ); } |