Search code examples
c++winapirichedit

strange behavior of richedit controll, text is written horizontally like in old japanese


All this compiles ok, with no errors, but the cursor is vertical and shows on top-right corner of the window, and the text flow is like japanese top to bottom in characters, right to left in lines. The characters are invisible, but copyable. I have english windows XP SP3 with no asian software on board.

#include <windows.h>
#include <richedit.h>

int main() {
  LoadLibrary("Msftedit.dll");
  HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(0);
  HWND richeditWindow = CreateWindowExW (
    WS_EX_TOPMOST,
    L"RichEdit50W",
    L"window text",
    WS_OVERLAPPEDWINDOW | ES_MULTILINE | WS_VISIBLE,
    0, 0, 500, 500,
    NULL, NULL, hInstance, NULL
  );

  MSG msg;
  while( GetMessageW( &msg, richeditWindow, 0, 0 ) ) {
    TranslateMessage( &msg );
    DispatchMessageW( &msg );
  }
}

Solution

  • The problem is your use of the WS_OVERLAPPEDWINDOW style. Rich edit controls are designed to be used as child windows and do not support WS_OVERLAPPEDWINDOW.

    WS_OVERLAPPEDWINDOW compiles as 0x00CF0000. This overlaps several rich edit styles, namely:

    ES_VERTICAL         0x00400000
    ES_NOIME            0x00080000
    ES_SELFIME          0x00040000
    

    So applying the WS_OVERLAPPEDWINDOW macro to your control is the same as applying those styles.