可能重复:
将指针传递给成员函数
当我离开课堂时WNDPROC DefEditProc;
,EditKeyProc
一切正常。但是现在当我粘贴代码时,编译失败并出现错误error: invalid use of member function (did you forget the '()' ?)
。所以我的问题是如何将这段代码压缩到类中,这样我就不会污染全局命名空间?
#include <windows.h>
#include <richedit.h>
class richEdit {
HWND richeditWindow;
WNDPROC DefEditProc;
public:
LRESULT EditKeyProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return CallWindowProc(DefEditProc, hwnd, uMsg, wParam, lParam);
}
richEdit() {
HMODULE richedit_library = LoadLibrary("Msftedit.dll");
if (NULL == richedit_library) abort();
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(0);
richeditWindow = CreateWindowExW (
WS_EX_TOPMOST,
MSFTEDIT_CLASS,
L"window text",
WS_OVERLAPPED | WS_SYSMENU | ES_MULTILINE | WS_VISIBLE,
0, 0, 500, 500,
NULL, NULL, hInstance, NULL
);
DefEditProc = (WNDPROC)SetWindowLong(richeditWindow, GWL_WNDPROC, (long)EditKeyProc);
}
~richEdit() {
MSG msg;
while( GetMessageW( &msg, richeditWindow, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessageW( &msg );
}
}
};
int main() {
richEdit re;
}