1

I noticed that RichEdit does not send messages to parent window when CTRL key is pressed when the control is in focus. When parent window is active then all goes ok. But when cursor is in RichEdit only mouse 0x20 WM_SETCURSOR messages go ok. When pressing a key as in typing without control keys 0x111 WM_COMMAND is send, and when I try to press CTRL and during this any other key like 'S' for implementing save-as function, nothing is sent. Is there a way to create callback to RichEdit or in other way capture CTRL+S ?

Escape also doesn't send a message to parent window.

rsk82
  • 28,217
  • 50
  • 150
  • 240

2 Answers2

2

Found how to set a callback to richedit.

    DefEditProc = (WNDPROC)SetWindowLong(richeditWindow, GWL_WNDPROC, (long)&richEdit.EditKeyProc);

and before in code:

LRESULT EditKeyProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  if(uMsg == WM_KEYDOWN) {
    if(wParam == 'S' && GetAsyncKeyState(VK_CONTROL));
    return 0;
  }
  return CallWindowProc(DefEditProc, hwnd, uMsg, wParam, lParam);
}
rsk82
  • 28,217
  • 50
  • 150
  • 240
1

I think that it's not the best way to go if you just want to catch some particular key shortcuts to make defined actions like Ctrl+S for save.

I would say that the right way to go is to use accelerator tables. It has two advantages :

  • If the accelerator table is in resources, you can easily change or remove the shortcut without actually digging into the C/C++ code. There are also facilities for multilingual software, and you can also quite easily open/save the accelerator table in a file unstead of using resources if you want the user to customize the shortcuts, etc.
  • The shortcut is not only triggered when you are in that particular richedit. I think it's a good thing for users. Imagine that you have another control in the same window. With your code, Ctrl+S wouldn't work, unless you register your callback on all control windows. I'm an user, I'm currently on the other control, and I press Ctrl+S. Oh no, my document hasn't been saved ! frustrating and buggy-looking...
  • IF you are also using menus, there is no that much code to add...
QuentinC
  • 12,311
  • 4
  • 24
  • 37