0

I have created a callback to handle Window procedures. Everytime that a click a mouse button for instance, I would like to send this message to several classes, so which class can handle it differently depending on its own need. I would like this to be cross platform if possible, but Windows only would be appreciate as well.

CGui * gui;
gui = new Gui();

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    case WM_LBUTTONDOWN:
    {
      // how to send that a left button was pressed to CGui class ?
      // is there another way than gui->LeftButtonPressed = true;
    }
    return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}

Answering my own question :

I believe the "solution" that you guys are talking about is :

    case WM_NCCREATE:
    {
        CREATESTRUCT * pcs = (CREATESTRUCT*)lParam;
        CGui * pCGui = (CGui*)pcs->lpCreateParams;
        pCGui->m_hWnd = hwnd;
        SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG)pcs->lpCreateParams);
        CGui * pCGui = (CGui*)GetWindowLongPtr(hwnd, GWLP_USERDATA);

        break;
    }

But actually since I need to upgrade several (as I mentioned) classes, the right solution would be the classes to access the WndProc as :

    gui->handleMessages(window->hWND, window->message, window->wpParam, 
    window->lpParam);

    And add at the original WndProc :
    message = uMsg;
    wpParam = wParam;
    lpParam = lpParam;

Thanks anyway.

Mrax
  • 63
  • 9
  • You should spend some more time learning C++ and Win32 API. You could just create a method like `on_left_button_clicked` in CGUI class and inside `WM_LBUTTONDOWN` call `gui->on_left_button_clicked`. You are missing `break;` after case statement – Asesh Jan 03 '20 at 03:59
  • 1
    There are tons of questions on StackOverflow that demonstrate how to use class objects with a WndProc callback on Windows. Read up about the `lpParam` parameter of `CreateWindow/Ex()` and the `WM_CREATE` message – Remy Lebeau Jan 03 '20 at 05:52

0 Answers0