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.
现在,某处会有一个部分(可能在Window类的构造函数中,需要为WNDCLASSEX分配一个WndProc,这在Window类中有说明。唯一的问题是,因为它是一个部分class,会出现错误。这样,它是如何实现的?它是静态的吗?即便如此,如果类包装它仍然是某种程度的类的一部分。如果我在类之外创建它,那么简单地抹掉了这一点。
1 个解决方案
#1
4
You pass the this
pointer as GWLP_USERDATA
to SetWindowLongPtr
, which effectively allows you to simply forward the free function to the member function.
您将此指针作为GWLP_USERDATA传递给SetWindowLongPtr,这有效地允许您将*函数简单地转发到成员函数。
#1
4
You pass the this
pointer as GWLP_USERDATA
to SetWindowLongPtr
, which effectively allows you to simply forward the free function to the member function.
您将此指针作为GWLP_USERDATA传递给SetWindowLongPtr,这有效地允许您将*函数简单地转发到成员函数。