Powered by |
How to bring window to the foreground?In the past the question was trivial - The first one intends using undocumented HMODULE hLib = GetModuleHandle("user32.dll");
void (__stdcall *SwitchToThisWindow)(HWND, BOOL);
(FARPROC &)SwitchToThisWindow = GetProcAddress(hLib, "SwitchToThisWindow");
SwitchToThisWindow(hWnd, TRUE);
But it does not work in the lates versions of Win98/2K. Another means is to use something like this: DWORD dwTimeout; SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &dwTimeout, 0); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 0, 0); SetForegroundWindow(hWnd); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)dwTimeout, 0); It works in Win98 but not in Win2K. And the last third trick is to use HWND hCurrWnd; int iMyTID; int iCurrTID; hCurrWnd = ::GetForegroundWindow(); iMyTID = GetCurrentThreadId(); iCurrTID = GetWindowThreadProcessId(hCurrWnd,0); AttachThreadInput(iMyTID, iCurrTID, TRUE); SetForegroundWindow(hWnd); AttachThreadInput(iMyTID, iCurrTID, FALSE); This works in Win98/ME/2K always. I have tested it in Win2K. Works indeed. For the details see recommended links. Recommended links: Bob Moore's site, RDSN.ru (in Russian)
|