If, when the cursor is in the position 0.0, press left or up (i.e., an attempt to go outside the editable area), then the standard richedit beeps (bell probably). How to remove this squeaking?

I use CreateWindowEx, an example of creating richedit http://docs.microsoft.com/en-us/windows/desktop/controls/create-rich-edit-controls somewhere like this:

LoadLibrary(TEXT("Msftedit.dll")); HWND hwndEdit= CreateWindowEx(0, MSFTEDIT_CLASS, TEXT("Type here"), ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP, x, y, width, height, hwndOwner, NULL, hinst, NULL); 

PS In Windows, there is a "bright" example of the meager use of richedit - wordpad. The developers did not bother - the sound was left (or maybe it was conceived). Start wordpad by pressing to the left - and there will be the same screech.

If there is an example for Delphi, for the CRichEdit component and mn that uses the richedit component of WINAPI - that also works, I will find and dig out how to do this in WINAPI.

  • As far as I understand, there’s no other way than analyzing the situation when handling WM_CHAR and ignoring peep buttons - Pavel Gridin 7:31 pm
  • Yes, this idea occurred to me, but ... buttons are needed, and you will have to do a lot of calculations whether you can go in any direction. 4 cases of re + 4 checks ... probably. - nick_n_a

1 answer 1

Something like this:

 typedef LRESULT (CALLBACK * PWNDPROC ) (HWND, UINT, WPARAM, LPARAM); PWNDPROC RichEditOldWndProc = NULL; //указатель на стандартную WNDPROC элемента Rich Edit LRESULT CALLBACK RichEditNewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) //переопределенный WNDPROC для Rich Edit { CHARRANGE cr; int line; switch (message) { case WM_KEYDOWN: switch (wParam){ case VK_UP: //получаем текущую позицию курсора ZeroMemory(&cr,sizeof(cr)); SendMessage(hWnd, EM_EXGETSEL, 0, (LPARAM)&cr); //находим, на какой строке находится курсор line = SendMessage(hWnd, EM_EXLINEFROMCHAR, 0, cr.cpMin); //если курсор на первой строке, не передаем управление стандартной WNDPROC if(line == 0) return 0; break; } break; //аналогично для случаев вниз/вправо/влево... } //передаем управление стандартной WNDPROC... return RichEditOldWndProc(hWnd,message,wParam,lParam); } void InitRichEdit() { LoadLibrary(TEXT("Msftedit.dll")); HWND hwndEdit= CreateWindowEx(0, MSFTEDIT_CLASS, TEXT(""), ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP, x, y, width, height, hWnd, NULL, hInst, NULL); //сохраняем указатель на стандартную WNDPROC RichEditOldWndProc = (PWNDPROC) GetWindowLongPtr(hwndEdit, GWLP_WNDPROC); //переопределяем WNDPROC SetWindowLongPtr(hwndEdit, GWLP_WNDPROC, (LONG_PTR)RichEditNewWndProc); }