它编译并运行,没有错误。唯一的问题是窗口没有显示出来。析构函数应该永远保留,直到我用鼠标关闭窗口?
#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();
}
答案 0 :(得分:2)
你的问题在这里:
richEdit re();
不是类型为richEdit
的默认构造的对象。是名为re
的函数的声明,它不带参数并返回richEdit
。
你想要这个:
richEdit re;
...或 C ++ 11 :
richEdit re{};
请注意,阻止析构函数将来会让您头疼。