我目前正在尝试获取所有打开的窗口的列表并将它们存储在一个向量中。我一直在查看代码,以至于解决方案可能非常简单,但如果没有全局变量(我想避免),我似乎无法完成它。
这是代码:
#include "stdafx.h"
#include "json.h"
#include <algorithm>
using namespace std;
vector<string> vec;
BOOL CALLBACK speichereFenster(HWND hwnd, LPARAM substring){
const DWORD TITLE_SIZE = 1024;
TCHAR windowTitle[TITLE_SIZE];
GetWindowText(hwnd, windowTitle, TITLE_SIZE);
int length = ::GetWindowTextLength(hwnd);
wstring temp(&windowTitle[0]);
string title(temp.begin(), temp.end());
if (!IsWindowVisible(hwnd) || length == 0 || title == "Program Manager") {
return TRUE;
}
vec.push_back(title);
return TRUE;
}
int main() {
EnumWindows(speichereFenster, NULL);
cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想将所有标题存储在向量中,但我不知道如何将向量传递到函数中...
谢谢!!!