c++ - Filling a list with Window objects using EnumWindows -
i'm trying fill list 'window" objects of active windows can't figure out way save window information in windowlist. windowlist passed callback function through lparam parameter.
here current code:
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; }
when try print out every element in windowlist through loop, error message pops up, saying "debug assertion failed! expression: list iterators incompatible"
this loop:
void center::printwindowlist() { (std::list<window>::iterator = windowlist.begin(); != windowlist.end(); ++it) std::cout << ' ' << it->gettitle(); }
hope can help
in callback function you're treating inputlist
parameter window*
instead of list<window>*
. try this:
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); auto windowptr = reinterpret_cast<std::list<window>*>(inputlist); windowptr->push_back(window((int)hwnd, title, true)); std::cout << (int)hwnd << " - " << title << std::endl; } return true; }
Comments
Post a Comment