簡體   English   中英

如何確保由Process.Start(ProcessStartInfo)啟動的進程窗口具有所有窗體的焦點?

[英]How to ensure process window launched by Process.Start(ProcessStartInfo) has focus of all Forms?

c#。如何確保由Process.Start(ProcessStartInfo)啟動的進程窗口具有所有窗體的焦點? 謝謝,

SetForegroundWindow以及其他設置焦點的方法有很多限制。 如果您確實希望確定啟動過程將受到關注,建議您使用以下本機(非托管)函數

SystemParametersInfo (SPI_GETFOREGROUNDLOCKTIMEOUT, 0, (PVOID)&dwLockedTimeout, 0);
SystemParametersInfo (SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (PVOID)0,
                      SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);

在進程啟動和還原之前

SystemParametersInfo (SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (PVOID)&dwLockedTimeout,
                      SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);

在末尾。 像這樣的電話

WaitForInputIdle (pi.hProcess, 5000);

在程序啟動之后和恢復SPI_SETFOREGROUNDLOCKTIMEOUT之前,如果您在立即操作方面遇到問題,也可能會有所幫助

Process.Start返回一個Process對象。 為了使過程集中,首先設置以下PInvoke:

[DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr hWnd);

然后,使用:

MyProcess = Process.Start(ProcessStartInfo);
SetForegroundWindow(MyProcess.MainWindowHandle);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM