0

它编译并运行没有错误。唯一的问题是窗口不显示。析构函数应该永远存在,直到我用鼠标关闭窗口?

#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();
}
4

1 回答 1

2

你的问题在这里:

richEdit re();

不是类型的默认构造对象richEdit。是一个名为的函数的声明re,它不带参数并返回一个richEdit.

你想要这个:

richEdit re;

...或在C++11中:

richEdit re{};

请注意,阻塞析构函数肯定会让您在未来感到头疼。

于 2013-01-17T20:07:11.420 回答