Hi I have a new question for all fellow programmers to solve. Is there a way that I can press a button or have a timer on that will fire an event that will make my app switch from one app to another? for example lets say I want to make a app that when i press a button it will switch from the current app to another app that is running like notepad or a game or something.
If there is a way to open a specific app by its name that would be great to, thanks.
PS: I already know how to code a timer so you don’t have to post one if you don’t want to.
Using the two WinAPI functions
FindWindowandSetFocus, you can achieve your desired goal:For example, to set a notepad window with the title “” to the foreground, you can use the following code:
If you don’t know the form’s name, then you can enumerate the windows using other WinAPI functions.
Alternatively, you can use the
Interaction.AppActivate()method fromMicrosoft.VisualBasic.dll, found in namespaceMicrosoft.VisualBasicif you reference it.Just simple call
Interaction.AppActivate("window title")orInteraction.AppActivate(iPID).The appropriate documentation for this method can be found here.