ShIvADeSt
Moderator | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору mihas83 Цитата: Где предлагался, и где не рекомендуют юзать? Почему? | Я не помню где это было, просто данный код давно у меня вроде бы это было в ФИДОшной эхе, врать не буду. просто вот два варианта, один из которых твой, второй почему то не работает на NT системах Цитата: Если это твоя пpога, можешь поюзать SwitchToThisWindow(Window, true). Если же испpавить этот глюк в системе, то вот: =========================================================== While rooting around the MSDN Library CD i noticed that SystemParametersInfo has a couple of new flags, among them these two: SPI_GETFOREGROUNDFLASHCOUNT TWindows NT 5.0 and later, Windows 98: Indicates the number of times SetForegroundWindow will flash the taskbar button when rejecting a foreground switch request. The pvParam parameter must point to a DWORD variable that receives the value. SPI_GETFOREGROUNDLOCKTIMEOUT Windows NT 5.0 and later, Windows 98: Indicates the amount of time following user input, in milliseconds, during which the system will not allow applications to force themselves into the foreground. The pvParam parameter must point to a DWORD variable that receives the time. There are also two matching SPI_SET flags. Now, this indicates that it might be possible to - get the old LOCKTIMEOUT - set the LOCKTIMEOUT to 0 - call SetForegroundWindow - restore the old LOCKTIMEOUT and thus get your window to front even if the user is hammering away at the keyboard in another app. Of course doing so would be antisocial behaviour, but anyway: could you test this notion? I do not have Win98 or NT 5 beta installed anywhere // 1-й способ (корректный) Procedure ForceForegroundWindow( Wnd : HWND ); // by "Peter Below (TeamB)" <100113.1101@compuXXserve.com> Const SPI_GETFOREGROUNDLOCKTIMEOUT = $2000; SPI_SETFOREGROUNDLOCKTIMEOUT = $2001; Var timeout, temp: DWORD; needsHack: Boolean; Begin needsHack := { Is it Win98 or NT 5 or later? } ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4) ) or ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and ((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and (Win32MinorVersion > 0) ) ) ); If needsHack Then Begin ParametersInfo( SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0); temp := 0; SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, 0, @temp, 0); End; { If } SetForegroundWindow( Wnd ); If needsHack Then Begin SystemParametersInfo( SPI_SETFOREGROUNDLOCKTIMEOUT, timeout, @timeout, 0); { Note: the platform SDK docs indicate that the second parameter is not used in setting the timeout but that does not match with the common use of this parameter for other SPI_SET flags. If it is not used then specifying it should do no harm, if the docs are off we have covered both bases <g>.} End; { If } End; { ForceForegroundWindow } // 2-й способ (работает, но ...) function ForceForegroundWindow(Const hWnd: THandle): Boolean; var hCurWnd: THandle; begin Result := False; if not isWindow(hWnd) then Exit; hCurWnd := GetForegroundWindow; if (hCurWnd=hWnd) then begin Result := True; Exit; end; if (GetWindowLong( hWnd, GWL_STYLE ) and WS_MINIMIZE)<>0 then ShowWindow(hWnd, SW_SHOWNOACTIVATE); AttachThreadInput( GetWindowThreadProcessId(hCurWnd, nil), GetCurrentThreadId, True); Application.ProcessMessages; SetForegroundWindow(hWnd); AttachThreadInput( GetWindowThreadProcessId(hCurWnd, nil), GetCurrentThreadId, False); Result := GetForegroundWindow=hWnd; end; | как видно рекомендуют юзать именно первый способ. По крайней мере я так понял.
---------- И создал Бог женщину... Существо получилось злобное, но забавное... |
|