[英]why this richedit window doesn't show up when I put the code in class?
它可以编译并没有错误地运行。 唯一的事情是窗口不会显示。 在我用鼠标关闭窗口之前,析构函数应该一直保留下去。
#include <windows.h>
#include <richedit.h>
class richEdit {
HWND richeditWindow;
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
);
}
~richEdit() {
MSG msg;
while( GetMessageW( &msg, richeditWindow, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessageW( &msg );
}
}
};
int main() {
richEdit re();
}
您的问题在这里:
richEdit re();
不是richEdit
类型的默认构造的对象。 是名为re
的函数的声明,该函数不带任何参数并返回richEdit
。
您想要这个:
richEdit re;
...或在C ++ 11中 :
richEdit re{};
请注意,阻塞析构函数肯定会在将来使您头疼。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.