Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WndProc assignment issue

Tags:

c++

I am attempting to make a custom GLWindow class that includes all of my setting up of my OpenGL window. However, I also want to include the WndProc callback function for messages being sent to the window in my GLWindow class.

GLWindow.h:

class GLWindow
{
    private:
        HWND hWnd;
        HDC hDC;
        HGLRC hRC;
    public:
        GLWindow();

        LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

        bool Create();

        ~GLWindow();
}

GLWindow.cpp:

GLWindow::GLWindow()
{

}

bool GLWindow::Create(int width, int height, char * title, bool fullscreen)
{
    WNDCLASSEX window;

    HINSTANCE hInstance;

    hInstance = GetModuleHandle(NULL);
    window.cbSize = sizeof(WNDCLASSEX);
    window.cbClsExtra = 0;
    window.cbWndExtra = 0;
    window.hbrBackground = NULL;
    window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    window.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    window.hCursor = LoadCursor(NULL, IDC_ARROW);
    window.hInstance = hInstance;
    window.lpfnWndProc = GLWindow::WndProc; // ERROR
}

GLWindow::~GLWindow()
{

}

The Error is that a value of type "LRESULT (__stdcall GLWindow::*)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)" cannot be assigned to an entity of type "WNDPROC."

I can't figure it out

I've gotten this to work when WndProc shares the same .cpp file as the WinMain function, but it seems as if the scope throws it off.

like image 270
user680725 Avatar asked Oct 23 '25 16:10

user680725


1 Answers

It should be a static or global function. Class member function expects to receive an additional hidden parameter called this, so the signature doesn't match.

like image 89
littleadv Avatar answered Oct 26 '25 07:10

littleadv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!