Found answer this is my revised code, look at PeekMessageW
and DispatchMessageW
.
#include <windows.h>
#include <iostream>
#include <sstream>
int main() {
using namespace std;
LoadLibrary("Msftedit.dll");
HWND richeditWindow = CreateWindowExW (
WS_EX_TOPMOST,
L"RICHEDIT50W",
L"window text",
WS_SYSMENU | WS_VSCROLL | ES_MULTILINE | ES_NOHIDESEL | WS_VISIBLE,
50, 50, 500, 500,
NULL, NULL, NULL, NULL
);
MSG msg;
for (int i = 0 ; i<100000; i++) {
wstringstream wss;
wss << i << L", ";
SendMessageW(richeditWindow, EM_REPLACESEL, FALSE, (LPARAM) wss.str().c_str());
if (PeekMessageW(&msg, richeditWindow, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
while( GetMessageW( &msg, richeditWindow, 0, 0 ) ) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}