Pointer to another Window
-
Within my program, I want to bring a window to another program to the foreground. I'm doing the following:
CWnd *pFV; pFV = CWnd::FindWindow(NULL, _T("Another Program Title"));
Then if FindWindow was successful, I call pFV->SetForegroundWindow() to bring it to the front. This works great in most cases, but it sometimes fails... The program I'm referencing changes its name in the titlebar depending on which options are selected. I don't have the source to the program, so I can't modify it. How can I get a pointer to this window without knowing what the title is going to be? Is there a way to link to the process name? I also know that the first x characters in the title will always be the same. Is there some way to search through all the titles of open windows to do a comparison? Any help would be greatly appreciated. Thanks. Todd Krzeminski tkrzeminski@nlxcorp.com -
Within my program, I want to bring a window to another program to the foreground. I'm doing the following:
CWnd *pFV; pFV = CWnd::FindWindow(NULL, _T("Another Program Title"));
Then if FindWindow was successful, I call pFV->SetForegroundWindow() to bring it to the front. This works great in most cases, but it sometimes fails... The program I'm referencing changes its name in the titlebar depending on which options are selected. I don't have the source to the program, so I can't modify it. How can I get a pointer to this window without knowing what the title is going to be? Is there a way to link to the process name? I also know that the first x characters in the title will always be the same. Is there some way to search through all the titles of open windows to do a comparison? Any help would be greatly appreciated. Thanks. Todd Krzeminski tkrzeminski@nlxcorp.comThe most efficient method here would be to use Microsoft Spy++ to find out the class name of the window, then use
FindWindow
on the class name instead of window caption. Just start Spy++, start the target program, and detect it's class name. If you do not know how to use Spy++, refer to it's help files, they are very throughout. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible. -
Within my program, I want to bring a window to another program to the foreground. I'm doing the following:
CWnd *pFV; pFV = CWnd::FindWindow(NULL, _T("Another Program Title"));
Then if FindWindow was successful, I call pFV->SetForegroundWindow() to bring it to the front. This works great in most cases, but it sometimes fails... The program I'm referencing changes its name in the titlebar depending on which options are selected. I don't have the source to the program, so I can't modify it. How can I get a pointer to this window without knowing what the title is going to be? Is there a way to link to the process name? I also know that the first x characters in the title will always be the same. Is there some way to search through all the titles of open windows to do a comparison? Any help would be greatly appreciated. Thanks. Todd Krzeminski tkrzeminski@nlxcorp.comtjkrz wrote: How can I get a pointer to this window without knowing what the title is going to be? How about the window's class name?
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
The most efficient method here would be to use Microsoft Spy++ to find out the class name of the window, then use
FindWindow
on the class name instead of window caption. Just start Spy++, start the target program, and detect it's class name. If you do not know how to use Spy++, refer to it's help files, they are very throughout. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.I tried that, but for the class name I get an long string (Afx:4000...) that seems to vary each time I run it. Am I doing something wrong? Thanks, Todd Krzeminski tkrzeminski@nlxcorp.com
-
Within my program, I want to bring a window to another program to the foreground. I'm doing the following:
CWnd *pFV; pFV = CWnd::FindWindow(NULL, _T("Another Program Title"));
Then if FindWindow was successful, I call pFV->SetForegroundWindow() to bring it to the front. This works great in most cases, but it sometimes fails... The program I'm referencing changes its name in the titlebar depending on which options are selected. I don't have the source to the program, so I can't modify it. How can I get a pointer to this window without knowing what the title is going to be? Is there a way to link to the process name? I also know that the first x characters in the title will always be the same. Is there some way to search through all the titles of open windows to do a comparison? Any help would be greatly appreciated. Thanks. Todd Krzeminski tkrzeminski@nlxcorp.comIf you can't use the class name, then the best alternative is to use EnumWindows. This will call a function you provide. With each callback you get will need to retrieve the titlebar text and do your own matching. Once you've found the window you can return FALSE to stop the enumeration early. Hope that helps. -- Joel Lucsy
-
I tried that, but for the class name I get an long string (Afx:4000...) that seems to vary each time I run it. Am I doing something wrong? Thanks, Todd Krzeminski tkrzeminski@nlxcorp.com
This type of class name means that the program uses MFC to register a new class for itself always when it is run. This means that the class name of the window is not an usable option. The other poster suggested using window enumeration callback routine. I find this the best alternative as well. Just get the caption of each window and compare X characters of it to see if there is a match. I remember you saying that certain characters of the window title always remain constant, so this would sound like the best course of action. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.
-
If you can't use the class name, then the best alternative is to use EnumWindows. This will call a function you provide. With each callback you get will need to retrieve the titlebar text and do your own matching. Once you've found the window you can return FALSE to stop the enumeration early. Hope that helps. -- Joel Lucsy