richedit: how can i read some characters without cpu on 100%?
i'm creating a function for read some data from richedit:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
static LRESULT APIENTRY RichEditProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
consolewindow *richedit = (consolewindow *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch(uMsg)
{
case WM_KEYDOWN:
{
if((wParam==VK_RETURN) && (richedit->blnread==true))
{
richedit->blnread=false;
}
return 0;
}
break;
case WM_CHAR:
{
if(richedit->blnread==true)
richedit->strreaded=richedit->strreaded + char(wParam);
}
break;
}
return CallWindowProc(richedit->wpOrigRichEditProc,hwndDlg,uMsg,wParam,lParam);
}
|
read function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
void APIDoEvents()
{
MSG msg;
BOOL result;
while ( blnread==true)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
SleepEx(1,1);
}
}
}
string read()
{
blnread=true;
APIDoEvents();
DebugText("hi");
return strreaded;
}
|
these code works. but the cpu can be on 100%. how can i fix it?
how i know? because the other window\form\window application is freezed :(
Last edited on
"How to Use Rich Edit Text Operations"
https://msdn.microsoft.com/en-us/library/windows/desktop/hh270404%28v=vs.85%29.aspx
Topic archived. No new replies allowed.