i have a program and when i click a button in the program i want ti to set focus on another process i have runing. the other process is running in windowed mode how can i do this?
Printable View
i have a program and when i click a button in the program i want ti to set focus on another process i have runing. the other process is running in windowed mode how can i do this?
The easy way is to use the AppActivate function. The alternative is to use a Process object to get the handle to the other app's main window, then call the SetForegroundWindow API function. Some consider it poor form to use Runtime functions like AppActivate, and I'm one of them, but I'd consider that preferable to resorting to API calls. The difference is that AppActivate will not restore the application window if it's minimised, whereas you can test for that and restore it using API functions, although it requires more than just SetForegroundWindow.
You can test for the app being minimized by using the IsIconic API.
Ok i used AppActivate and it works just fine for what i need. I dont need to restore the process if it has been minimized. Here is the code i used incase anyone else is wondering how to do it this way.
VB Code:
Dim proc As Process Dim h As Integer Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load proc = Process.GetProcessesByName("myprocess")(0)' the process to set focus too must be started before this code is run End Sub Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click AppActivate(proc.Id)'sets focus to the process End Sub