-1

I develop a Edit control like TMemo, but I'm using TCustomControl.

How can I show a standard popup menu for edit controls?enter image description here

My control can use WM_COPY, WM_PASTE etc. to handle the menu items.

I receive a WM_CONTEXTMENU message to show a menu. But I want to have the standard menu with the local display strings. Is there any function / message, to show the same menu, which TMemo uses?

TMemo based on "EDIT" class. But I'm using TCustomControl, since I handle and paint the text very different.

Tahtu
  • 433
  • 1
  • 4
  • 15
  • I would recommend that you just write your own menu. – Anders Jul 13 '17 at 13:58
  • OT: Is this picture one of your custom control? Asking because it is identical to the one in [this](https://stackoverflow.com/questions/32991402/how-to-disable-copy-paste-commands-in-the-windows-edit-control-context-menu) question, apart from the overlay used there. – Sertac Akyuz Jul 14 '17 at 19:36
  • @SertacAkyuz: You are right, I copied the picture from that question. But this menu is from User32.dll like answered from Anders here. In the other question, the menu is generated by the EDIT control. Now, I'm using this menu inside my custom control by using LoadMenu. And because of this, I can disable the items. But this is not an answer to the other questions. – Tahtu Jul 15 '17 at 08:25

2 Answers2

1

The way to have this menu shown is to get the EDIT window class to do it. Subclass the standard EDIT window class, precisely as TEdit and TMemo do. You'll then need to apply your customisations in your code.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thanks! Now I see that menu. But only Paste is enabled. Copy, Cut, Delete, Select All and Undo are disabled. Do I need to set any flag, state or something like that? `EM_GETSEL` will not be called before showing the menu... – Tahtu Jul 13 '17 at 10:13
  • You would need to put some text in there for actions like copy to be enabled ...... – David Heffernan Jul 13 '17 at 10:18
  • ... but I store the text inside my own memory - not in the memory of the Windows control. – Tahtu Jul 13 '17 at 10:26
  • If you want to have this menu, you'd be advised to change that policy. If you want to make a complete custom control, then make your own menu. You aren't going to be able to have your cake and eat it. – David Heffernan Jul 13 '17 at 10:29
  • ... or with other words: You don't know an answer. Nevertheless thank you for your answer. – Tahtu Jul 13 '17 at 10:44
  • 1
    Sometimes the answer is, what you are trying to do cannot be done. You cannot expect the system to provide that menu and its functionality without the `EDIT` control behind it. It exists as part of the `EDIT` control, it does not exist standalone. That is the answer to the question that you asked. The fact that this is not the answer you wanted or hoped for does not mean that it is nevertheless the answer. – David Heffernan Jul 13 '17 at 10:49
  • It is [documented here](https://msdn.microsoft.com/en-us/library/windows/desktop/bb775460(v=vs.85).aspx#cut_copy_etc) _"An edit control includes a built-in context menu that makes it easy for the user to move text between the edit control and the clipboard. The context menu appears when the user right-clicks the control. The commands in the context menu include Undo, Cut, Copy, Paste, Delete, and Select All."_ – Victoria Jul 14 '17 at 06:07
  • ... yes, you are right. But this does not belong to my question. I asked, how to get this for a TCustomControl - not for a "EDIT" window. Maybe you are right, and there is no solution. But your answer still does not belong to my question... – Tahtu Jul 14 '17 at 09:07
1

The menu exists in User32.dll with resource id 1.

This is of course a undocumented implementation detail and it is not exactly the same as the edit controls menu because it appends to the menu if ImmIsIME is true (The 700..703 resource strings in User32.dll). You would have to debug the edit control to figure out exactly what it does to the menu depending on the locale and language pack (EditSetMenu) if you want the exact same behavior...

Anders
  • 97,548
  • 12
  • 110
  • 164