Author: Jonas Bilinkevicius
Is there a way to keep the default popup menus for e.g. TMemo, TEdit if there is an
explicit popup menu for the parent control?
Answer:
You have to trap the WM_CONTEXTMENU message on the level of the parent. Assuming
the parent is the form you would add a message handler to the form:
1 { ... }2 private3 4 procedure WMContextMenu(varmessage: TWMContextMenu); message WM_CONTEXTMENU;
5 { ... }
and implement it like this:
6 7 procedure TForm1.WMContextMenu(varmessage: TWMContextMenu);
8 var9 wnd: HWND;
10 ctrl: TWinControl;
11 begin12 ifmessage.XPos > 0 then13 begin14 wnd := WindowFromPoint(Mouse.CursorPos);
15 if wnd <> handle then16 begin17 ctrl := FindControl(wnd);
18 if Assigned(ctrl) and (ctrl is TCustomEdit) then19 Exit;
20 end;
21 end22 elseif ActiveControl is TCustomEdit then23 Exit;
24 inherited;
25 end;
Doing the same if the parent with the menu is a panel or tabsheet or such is a bit more difficult, you have to subclass it via WindowProc, or make a descendent class to be able to trap the message.