Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You will have to create your own implementation which should be based on EnumWindows, GetWindowText and GetWindowTextLength which then must allow the wildcards.</p> <pre><code>#include &lt;Windows.h&gt; #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;vector&gt; struct FindWindowData { FindWindowData( TCHAR const * windowTitle ) : WindowTitle( windowTitle ) , ResultHandle( 0 ) {} std::basic_string&lt;TCHAR&gt; WindowTitle; HWND ResultHandle; }; BOOL CALLBACK FindWindowImpl( HWND hWnd, LPARAM lParam ) { FindWindowData * p = reinterpret_cast&lt;FindWindowData*&gt;( LongToPtr( lParam ) ); if( !p ) { // Finish enumerating we received an invalid parameter return FALSE; } int length = GetWindowTextLength( hWnd ) + 1; if( length &gt; 0 ) { std::vector&lt;TCHAR&gt; buffer( std::size_t( length ), 0 ); if( GetWindowText( hWnd, &amp;buffer[0], length ) ) { // Comparing the string - If you want to add some features you can do it here if( _tcsnicmp( &amp;buffer[0], p-&gt;WindowTitle.c_str(), min( buffer.size(), p-&gt;WindowTitle.size() ) ) == 0 ) { p-&gt;ResultHandle = hWnd; // Finish enumerating we found what we need return FALSE; } } } // Continue enumerating return TRUE; } // Returns the window handle when found if it returns 0 GetLastError() will return more information HWND FindWindowStart( TCHAR const * windowTitle ) { if( !windowTitle ) { SetLastError( ERROR_INVALID_PARAMETER ); return 0; } FindWindowData data( windowTitle ); if( !EnumWindows( FindWindowImpl, PtrToLong(&amp;data) ) &amp;&amp; data.ResultHandle != 0 ) { SetLastError( ERROR_SUCCESS ); return data.ResultHandle; } // Return ERROR_FILE_NOT_FOUND in GetLastError SetLastError( ERROR_FILE_NOT_FOUND ); return 0; } int _tmain(int argc, _TCHAR* argv[]) { std::cout &lt;&lt; "HWND: " &lt;&lt; FindWindowStart(TEXT("foobar ") ); std::cout &lt;&lt; " GetLastError() = " &lt;&lt; GetLastError() &lt;&lt; std::endl; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload