Question Set Active Window

jonbisch

New member
Joined
Nov 12, 2008
Messages
2
Programming Experience
Beginner
I am trying to create a simple app that sets the active window and then sends a few keystrokes to the window.

The problem I have is that the active window is a child/sub window of a different program. I could use the title bar of the window to reference it instead of the PID (main and subwindow have same PID), but my problem is that the program I am trying to activate the window for has multiple windows with the same exact title. I have already tried renaming the title of one of the windows so that i can reference the one i want, and that works for only a split second. The reason is only works for a split second is that the programs windows titles are also updated every second with new data, so when i rename the title, the program changes it right back a second later.

What i need to figure out is code to activate the window i need to send commands to, that takes into account that the window is a child of another program and shares the same PID, the title of the window is the same of another window, and the title cannot be changed to single out the one i want because the program changes the title every second.

Any ideas would be greatly appreciated. I am somewhat new to VB but have written a few small in house apps and have a decent working knowledge.

Thanks
 
The window handle doesn't change, which you should be able to use with SetForegroundWindow.
VB.NET:
Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Int32) As Int32
 
Everytime I close the program and open it back up the handle changes. I have already successfully set the active window with the way you recommended, but as soon as i close the program and open it back up the handle for the new windows are no longer the same.
 
Back
Top