How to wrap a win32 WndProc into a C++ class?

匆匆过客 提交于 2020-01-24 15:42:51

问题


Is this even possible? For example, let's say I have the following:

class Window {
private:
    WNDCLASSEX wc;
public:
    inline WNDCLASSEX getWindowClass() {
        return wc;
    }
    Window();
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, LPARAM lParam, WPARAM wParam);
}

void RegisterWindow(Window win) {
    WNDCLASSEX* wc = win.getWindowClass();
    RegisterClassEx(wc);

}

Now, somewhere there is going to be a section (probably in the constructor of the Window class, where it's necessary to assign the WNDCLASSEX a WndProc, which is noted in the Window class. The only issue is that, because it's a part of a class, there an error will be raised. Thus, how is this achieved? Is it made static? Even so, if the class wraps it it is still part of the class in some way. If I create it outside of the class, that simply obliterates the point.


回答1:


You pass the this pointer as GWLP_USERDATA to SetWindowLongPtr, which effectively allows you to simply forward the free function to the member function.



来源:https://stackoverflow.com/questions/8780700/how-to-wrap-a-win32-wndproc-into-a-c-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!