Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to cast the pointer. A LPARAM is defined as a long in 32bit and __int64 in 64bit, so it's perfectly OK to cast your pointer to a LPARAM and back again.</p> <p>More than that, you really need to use a little object orientation here. There's absolutely no need to maintain your own counters or limited memory management, etc.</p> <pre><code>typedef std::basic_string&lt;TCHAR&gt; tstring; class Handles { public: struct window_data { tstring caption; HWND handle; }; private: std::vector&lt;window_data&gt; stuff; BOOL add_window(HWND hwnd) { TCHAR String[200] = {0}; if (!hwnd) return TRUE;// Not a window, return TRUE to Enumwindows in order to get the next handle if (!::IsWindowVisible(hwnd)) return TRUE;// Not visible, return TRUE to Enumwindows in order to get the next handle LRESULT result = SendMessageW(hwnd, WM_GETTEXT, sizeof(String), (LPARAM)String); if (!result) return TRUE;// No window title, return TRUE to Enumwindows in order to get the next handle window_data data; data.handle = hwnd; for(int i = 0; i &lt; result; i++) data.caption.push_back(String[i]); stuff.push_back(data); return TRUE; } static BOOL CALLBACK EnumWindowsProcCallback(HWND hwnd, LPARAM lparam) { Handles* ptr = reinterpret_cast&lt;Handles*&gt;(lparam); return ptr-&gt;add_window(hwnd); } public: Handles&amp; enum_windows() { stuff.clear(); if(!EnumWindows(EnumWindowsProcCallback, reinterpret_cast&lt;LPARAM&gt;(this))) { // Error! Call GetLastError(); } return *this; } std::vector&lt;window_data&gt;&amp; get_results() { return stuff; } }; int _tmain(int argc, TCHAR* argv[]) { std::vector&lt;Handles::window_data&gt; results = Handles().enum_windows().get_results(); } </code></pre> <p>Nice, easy interface, automated memory management - epic win.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload