Question

It compiles and runs with no error. The only thing is that the window doesn't show up. The destructor should stay forever until I close the window by mouse ?

#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();
}
Was it helpful?

Solution

Your problem is here:

richEdit re();

Is not a default-constructed object of type richEdit. Is a declaration of a function named re that takes no arguments and returns a richEdit.

You want this instead:

richEdit re;

...or in C++11:

richEdit re{};

Note that a blocking destructor is something that will certainly give you headaches in the future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top