Jak mogę uzyskać EnumWindows, aby wyświetlić wszystkie okna?
Zakładam, że to, o co pytam, powinno być domyślne, ale doświadczam pewnych zachowań, których nie rozumiem.
<code>#include "stdafx.h" using namespace std; BOOL CALLBACK enumWindowsProc( __in HWND hWnd, __in LPARAM lParam ) { if( !::IsIconic( hWnd ) ) { return TRUE; } int length = ::GetWindowTextLength( hWnd ); if( 0 == length ) return TRUE; TCHAR* buffer; buffer = new TCHAR[ length + 1 ]; memset( buffer, 0, ( length + 1 ) * sizeof( TCHAR ) ); GetWindowText( hWnd, buffer, length + 1 ); tstring windowTitle = tstring( buffer ); delete[] buffer; wcout << hWnd << TEXT( ": " ) << windowTitle << std::endl; return TRUE; } int _tmain( int argc, _TCHAR* argv[] ) { wcout << TEXT( "Enumerating Windows..." ) << endl; BOOL enumeratingWindowsSucceeded = ::EnumWindows( enumWindowsProc, NULL ); cin.get(); return 0; } </code>
Jeśli wywołam ten kod, wyświetli listę wszystkich zminimalizowanych okien:
Teraz nie interesują mnie już tylko zminimalizowane okna, teraz chcę je wszystkie. Więc usuwamIsIconic
czek:
<code>BOOL CALLBACK enumWindowsProc( __in HWND hWnd, __in LPARAM lParam ) { /* if( !::IsIconic( hWnd ) ) { return TRUE; } */ int length = ::GetWindowTextLength( hWnd ); if( 0 == length ) return TRUE; TCHAR* buffer; buffer = new TCHAR[ length + 1 ]; memset( buffer, 0, ( length + 1 ) * sizeof( TCHAR ) ); GetWindowText( hWnd, buffer, length + 1 ); tstring windowTitle = tstring( buffer ); delete[] buffer; wcout << hWnd << TEXT( ": " ) << windowTitle << std::endl; return TRUE; } </code>
Teraz dostaję wszystkie oknaz wyjątkiem zminimalizowane (tym razem nie wymieniono żadnego z wymienionych wcześniej uchwytów okien):
Dla kompletności jest tostdafx.h
:
<code>#pragma once #include "targetver.h" #include <iostream> #include <map> #include <string> namespace std { #if defined _UNICODE || defined UNICODE typedef wstring tstring; #else typedef string tstring; #endif } #include <stdio.h> #include <tchar.h> #include <Windows.h> #include <psapi.h> </code>Co ja robię źle?