How to set focus to another window?

后端 未结 2 405
抹茶落季
抹茶落季 2020-12-16 00:00

I have a problem with a program that loses focus. It\'s not my program. How can I write a second program to set focus to that window every 1-2 seconds? Is is possible to do

2条回答
  •  遥遥无期
    2020-12-16 00:09

    You can use following Win32 API if you want to bring some other program/process

            [DllImport("user32.dll")]
            static extern bool SetForegroundWindow (IntPtr hWnd);
    
             private void BringToFront(Process pTemp)
             {
               SetForegroundWindow(pTemp.MainWindowHandle);
             }
    

提交回复
热议问题