static BOOL CALLBACK enumWindowCallback(HWND func_hWnd, LPARAM lparam) {
int length = GetWindowTextLength(func_hWnd);
TCHAR* buffer;
char* buffer = new char[length + 1];
GetWindowText(hWnd, buffer, length + 1);
string windowTitle(buffer);
if (length != 0) {
std::cout << func_hWnd << ": " << windowTitle << std::endl;
}
return TRUE;
}
#include <Windows.h>
#include <string>
#include <iostream>
using namespace std;
static BOOL CALLBACK enumWindowCallback(HWND func_hWnd, LPARAM lparam) {
int length = GetWindowTextLengthA(func_hWnd);
if (length != 0) {
string windowTitle(length, '\0');
GetWindowTextA(func_hWnd, windowTitle.data(), length + 1); // ANSI version and func_hWnd
std::cout << func_hWnd << ": " << windowTitle << std::endl;
}
return TRUE;
}
int main() {
SetConsoleOutputCP(GetACP());
EnumWindows((WNDENUMPROC)enumWindowCallback, 0);
system("pause");
return 0;
}
string title(length, '\0');
GetWindowText(hWnd, (char*)(title.data()), length+1);