How to bring my application to the front?

后端 未结 8 700
孤城傲影
孤城傲影 2020-12-08 15:32

I know all the reasons why it is a bad idea. I dislike it if an application steals input focus, but this is for purely personal use and I want it to happen; it will not dist

8条回答
  •  半阙折子戏
    2020-12-08 15:41

    This should work even in Windows7+8 OS. Only requirement is an application itself can call functions. It's trickier to use an external app to set another process's window front.

    Application.Restore; // unminimize window, makes no harm always call it
    SetWindowPos(self.Handle, HWND_NOTOPMOST,0,0,0,0, SWP_NOMOVE or SWP_NOSIZE);
    SetWindowPos(self.Handle, HWND_TOPMOST,0,0,0,0, SWP_NOMOVE or SWP_NOSIZE);
    SetWindowPos(self.Handle, HWND_NOTOPMOST,0,0,0,0, SWP_SHOWWINDOW or SWP_NOMOVE or SWP_NOSIZE);
    

    Edit Ok I found out one problem with this. Application is brought to front but focus is kept in an original application. Use this answer to fix the problem, its quite complex method but copypaste does the trick. Before calling ForceForegroundWindow(wnd) you may have to call Application.Restore unminimizing a window. https://stackoverflow.com/a/5885318/185565

提交回复
热议问题