掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
アクティブウィンドウのロックタイムアウトを設定するSystemParametersInfoの使い方について (ID:38952)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
(OS=XP) ・ウィンドウを最前面に移動するとき、SetForegroundWindowだけでは、タスクバーが点滅するだけで終わることがあるので、他ページをみて、下記のようなコードを試しましたが、たまにエラーがでます。ウィンドウは最前面になっているのですが、気になります。どこが間違っているのでしょうか。 エラー SystemParametersInfo GET OK. LockTimeOut = 17423844 SystemParametersInfo SET(0) Fail. アクセスが拒否されました。 SystemParametersInfo SET(BACK) Fail. アクセスが拒否されました。 コードここから LockTimeOut: DWORD; //begin ---------------- if KeyVK = $20 then begin Logging('Key = Space'); FormMain.Visible := True; ForegroundProcessId := GetWindowThreadProcessId(GetForegroundWindow, nil); CurrentProcessId := GetCurrentThreadId; if ForegroundProcessId = CurrentProcessId then begin Logging('ForegroundProcessId = CurrentProcessId'); if SetForegroundWindow(Application.Handle) then begin Logging('SetForegroundWindow OK') end else begin Logging('SetForegroundWindow Fail') end; end else //if ForegroundProcessId <> CurrentProcessId then begin Logging('ForegroundProcessId <> CurrentProcessId'); SetActiveWindow(Application.Handle); if AttachThreadInput(CurrentProcessId, ForegroundProcessId, True) then begin LockTimeOut := 0; Logging('AttachThreadInput OK'); if not SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @LockTimeOut, SPIF_SENDCHANGE) then begin Logging('SystemParametersInfo GET Fail. ' + SysErrorMessage(GetLastError)); end else begin Logging('SystemParametersInfo GET OK. LockTimeOut = ' + IntToStr(LockTimeOut)); end; if not SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Pointer(0), SPIF_SENDCHANGE) then begin Logging('SystemParametersInfo SET(0) Fail. ' + SysErrorMessage(GetLastError)); end else begin Logging('SystemParametersInfo SET(0) OK. '); end; SetActiveWindow(Application.Handle); SetForegroundWindow(Application.Handle); if SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Pointer(LockTimeOut), SPIF_SENDCHANGE) then begin Logging('SystemParametersInfo SET(BACK) OK. '); end else begin Logging('SystemParametersInfo SET(BACK) Fail. ' + SysErrorMessage(GetLastError)); end; AttachThreadInput(CurrentProcessId, ForegroundProcessId, False); end else begin Logging('AttachThreadInput Fail'); end; end; end; //end ----------------
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.