#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <vector>
#define MAX_LENGTH 25600
using namespace std;
TCHAR * result;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
int _tmain(int argc, _TCHAR* argv[])
{
result = (TCHAR*)malloc(sizeof(TCHAR)*MAX_LENGTH);
ZeroMemory(result,sizeof(result));
wcout.imbue(std::locale("chs"));
EnumWindows(EnumWindowsProc, 0);
wcout << result << endl;
free(result);
return 0;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
if (!IsWindowVisible (hwnd))
return (TRUE);
TCHAR title[256];
GetWindowText(hwnd, title, sizeof(title));
if(wcslen(title) >0 )
{
static int i = 0;
wcout << title << endl;
wcscat(result,title);
wcscat(result, TEXT("##"));
}
return true;
}
backup 1
转载于:https://my.oschina.net/uniquejava/blog/162710