How to bring a window foreground using c#?

前端 未结 6 1448
遥遥无期
遥遥无期 2020-12-30 13:37

I am trying to bring a window foreground. I am using this code. But its not working. Could someone please help?

ShowWindowAsync(wnd.hWnd, SW_SHOW);

SetForeg         


        
6条回答
  •  执念已碎
    2020-12-30 14:12

    In order for SetForegroundWindow to work consistently, you have to meet a few criteria. The first is your process that would run the command must be in the foreground. Only foreground process can make another process foreground. In order to make your process foreground first, you have to bring the main window to the front, if it is not. You minimise it first and then SetForegroundWindow it, to make it foreground. Now find the target process and bring it to the front

    The steps are

    • Minimise the current window
    • SetForegroundWindow it
    • Find the target process
    • SetForegroundWindow it

    I've got an example, though it's a slightly different use case.

提交回复
热议问题