【发布时间】:2012-04-20 12:41:14
【问题描述】:
我假设,我所要求的实际上应该是默认设置,但我遇到了一些我不理解的行为。
#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;
}
如果我调用该代码,它将列出所有最小化的窗口:
现在,我不再只对最小化的窗口感兴趣,现在我想要所有这些。所以我删除了IsIconic 检查:
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;
}
现在我得到所有窗口除了最小化的窗口(这次没有列出之前列出的窗口句柄):
为了完整起见,这是stdafx.h:
#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>
我做错了什么?
【问题讨论】:
-
为什么不结合这两个函数来获得想要的结果?
-
如果我不能解决这个问题,那么我想这就是我要做的。但我确信我的代码中存在错误。我更愿意解决它。
-
我的评论有点不合格,抱歉(有其他想法);)
-
我假设您尝试向下滚动?
-
@TonyK 是的,我调整了窗口的高度以适合屏幕截图的文本。