WinApi FindWindow by a part of title
-
16-02-2021 - |
Question
How I can get a window's descriptor if I know only a part of its title and its className?
Solution
FindWindow()
requires the full title. Use EnumWindows()
, or GetWindow()
in a loop, to enumerate through all available windows, calling GetClassName()
and GetWindowText()
on each one and compare the values to your search criteria until you find a match.
OTHER TIPS
Something like this:
BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam ) {
wchar_t lpClassName[128] = {0};
MYSTRUCT* MS_INFO = ( MYSTRUCT* )lParam;
GetClassName( hwnd, lpClassName, _countof( lpClassName ) );
if( strstr( lpClassName, MS_INFO -> lpClassName ) ) {
wchar_t lpWindowName[128] = {0};
GetWindowText( hwnd, lpWindowName, _countof( lpWindowName ) );
if( strstr( lpWindowName, MS_INFO -> lpWindowName ) ) {
...
}
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow