【发布时间】:2016-01-16 06:23:08
【问题描述】:
我正在尝试用所有活动 Windows 的“Window”对象填充列表,但我无法找到将 Window 信息保存在我的 windowList 中的方法。windowList 通过 lParam 参数传递给回调函数.
这是我当前的代码:
std::list <Window> windowList; //in center.h
//in center.cpp:
void Center :: detectWindows()
{
EnumWindows(detectWindowsProc, (LPARAM)&windowList);
}
BOOL CALLBACK detectWindowsProc(HWND hwnd, LPARAM inputList)
{
if (IsWindow(hwnd) && IsWindowEnabled(hwnd) && IsWindowVisible(hwnd))
{
TCHAR TCharTitle[100];
GetWindowText(hwnd, TCharTitle, 100);
std::string title = convertTCharToStr(TCharTitle);
Window * windowPtr;
windowPtr = (Window*)inputList;
Window newWindow((int)hwnd, title, true);
*windowPtr = newWindow;
std::cout << (int)hwnd << " - " << title << std::endl;
}
return true;
}
当我尝试通过 for 循环打印出 windowList 中的每个元素时,会弹出一条错误消息,提示“调试断言失败!表达式:列表迭代器不兼容”
这是for循环:
void Center::printWindowList()
{
for (std::list<Window>::iterator it = windowList.begin(); it != windowList.end(); ++it)
std::cout << ' ' << it->getTitle();
}
希望有人能帮忙
【问题讨论】:
标签: c++ windows list pointers winapi