Recent

Author Topic: TRichMemo: Popup menu not shown when the Menu key is pressed  (Read 670 times)

CM630

  • Hero Member
  • *****
  • Posts: 1447
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
TRichMemo: Popup menu not shown when the Menu key is pressed
« on: January 23, 2025, 09:57:53 am »
Windows 10, 64 bit, Lazarus 4RC2, 32 bit.
I create a TRichMemo, then I add a popup and link the popup with the RichMemo.
When I right click the memo or I press “Shift + F10” the popup menu is shown.
When I press the menu key on the keyboard the popup menu is not shown, some small rectangle is shown on the place of the mouse instead.

I succeeded in making a workaround, which works:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.RichMemo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  2. begin
  3.   if (Key = 93) then
  4.   begin
  5.     PopupMenu1.PopUp; //or maybe better TRichMemo(Sender).PopupMenu.PopUp;  
  6.     key := 0;
  7.   end;
  8. end;
So probably the Menu key invokes something which probably should not be invoked.
« Last Edit: January 23, 2025, 10:04:46 am by CM630 »
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

rvk

  • Hero Member
  • *****
  • Posts: 6807
Re: TRichMemo: Popup menu not shown when the Menu key is pressed
« Reply #1 on: July 04, 2025, 10:22:52 am »
Partially found the problem. Somehow LM_CONTEXTMENU gets pushed twice to the messaging queue.

If I comment out the LM_CONTEXTMENU in TRichEditCallback.GetContextMenu, the context menu for right click doesn't work anymore, but the Menu key starts working.

Code: Pascal  [Select][+][-]
  1. function TRichEditCallback.GetContextMenu(seltype: Word; oleobj: IOleObject;
  2.   const chrg: TCharRange; var menu: HMENU): HRESULT; stdcall;
  3. var
  4.   msg : TLMContextMenu;
  5. begin
  6.   {
  7.   FillChar(msg, sizeof(msg), 0);
  8.   msg.Msg:=LM_CONTEXTMENU;
  9.   msg.XPos:=Mouse.CursorPos.x;
  10.   msg.YPos:=Mouse.CursorPos.y;
  11.   msg.hWnd:=fOwner.Handle;
  12.   DeliverMessage(fOwner, msg);
  13.   }
  14.   // do not give hmenu back to RichEdit, it will destory it!
  15.   menu:=0;
  16.   Result:=S_OK;
  17. end;

Tracing through the code you see TControl.WMContextMenu is called twice for the Menu key.
So TPopupMenu.PopUp is executed twice because of this resulting in closing the just opened popup by the previous call.

I'm not sure who pushes the LM_CONTEXTMENU to the queue when the menu key is pressed... but if it's already done... TRichEditCallback.GetContextMenu shouldn't do this again.

I don't think Dmitry ( @skalogryz ) is very active with Lazarus anymore.

CM630

  • Hero Member
  • *****
  • Posts: 1447
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TRichMemo: Popup menu not shown when the Menu key is pressed
« Reply #2 on: July 04, 2025, 02:57:51 pm »
...
I don't think Dmitry ( @skalogryz ) is very active with Lazarus anymore.
...
Sounds like TRichMemo is abandoned  :'(, hopefully someone adopts it.
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018