gpt4 book ai didi

c++ - 如何使用SetWindowLong来寻址类成员函数?

转载 作者:太空宇宙 更新时间:2023-11-04 15:23:17 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
To pass a pointer to a member function

当我离开类时,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;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com