I have a std::map of windows, for example:
class MyWindow
{
public:
MyWindow()
{
CreateWindow(...);
}
... // rest of code
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
// code
}
}
std::map<string, MyWindow> windows;
And inside the WndProc function I want to know which window is now in the function, how can I get the key of this window.
You could use
SetWindowLongPtrto store a pointer to an object (thisif you’re creating a window in a class method) for a givenHWND. UseGWLP_USERDATAasnIndexargument.This way, you need no map at all: when you have a window handle,
GetWindowLongPtris enough to get an object.