简体   繁体   中英

why this richedit window doesn't show up when I put the code in class?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM