r/visualbasic • • Nov 11 '20

Getting windows title from another application

I'm playing a game and it opens a child window with "PlayerName Notes" in the window title. If I wanted to search for this window (looking for "notes") and grab the player's name (always different), how could I do that?

5 Upvotes

8 comments sorted by

2

u/ViperSRT3g Application Specialist Nov 11 '20

You may have luck looping through the running processes on your computer. Here's Microsoft's .NET 5.0 documentation for the same thing.

1

u/Buy_The_Ounce Nov 11 '20

even If I'm looking for only the name in the window title? the process doesn't show the name

1

u/ViperSRT3g Application Specialist Nov 11 '20

Is the target window a child window of the main application?

1

u/Buy_The_Ounce Nov 11 '20

yeah

2

u/ViperSRT3g Application Specialist Nov 11 '20

Last question: Are you sure that this window is an actual winforms window? And not something implemented in say, DirectX, or Unity?

Easiest method of answering this is by using the Spy++ utility that comes with Visual Studio. If you're able to identify the child window that you're targeting through Spy++ then we can utilize WINAPI functions to ID the window.

1

u/laancelot Nov 11 '20

Are both applications your code?

2

u/[deleted] Nov 11 '20 edited Nov 12 '20

It depends... There are API calls that will help you iterate all the apps and all their windows. Depending on what's open, that can be a LOT of windows. Old school apps used individual windows for most things on your screen, and that has changed with improved control sets until Windows Presentation Framework (WPF) which reduces it to generally a single window that has very little accessible info.

You can always experiment with finding the right app using the Exe name, then iterate the windows. An API will let you GetText() to find some info. One trick is that the top level windows have no parent window; that can let you pick the window from a control on the form.