2

How I can get a window's descriptor if I know only a part of its title and its className?

hawbsl
  • 15,313
  • 25
  • 73
  • 114
HelloWorld
  • 1,061
  • 2
  • 15
  • 25

2 Answers2

6

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
2

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 ) ) {
      ...
    }
  }
}
Mike Kwan
  • 24,123
  • 12
  • 63
  • 96