Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question has been asked before but the non-answer is "Well, its up to each application to support different options". Still, when you right-click a selection in notepad, a browser, whatever Something is building a context menu. How does an app do that? Why can't I add to it? How to you add to the hightlight context menu? No answer is better than a non-answer.

share|improve this question

closed as not a real question by studiohack Aug 20 '12 at 19:29

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Welcome to Superuser. What you consider a "non-answer" is actually an answer, considering not all context menus are editable. It does depend on the program you are working with. Can you edit your question with specifics of what you are trying to do? Is there a specific program you are trying to add to? – CharlieRB Aug 20 '12 at 12:02

Short answer: If you added a new menu item, the program wouldn't know what to do when the item was clicked. You actually have to change the program's code to make new menu items do something. This is why "It's up to each application" is a valid answer.

Windows, like most other operating systems, provides a set of functions for building GUI programs – some are part of the system ("create a window"), others are mostly for convenience ("draw a button that can be clicked").

Most programs display their menus (normal and context) by using these functions – they basically give Windows a list of items and ask for it to be displayed on screen in the form of a menu, and to inform the program about what you picked.

Windows doesn't particularly care where the list of items comes from. Some menus are generated by the program itself (such as the "Recent files" list); you cannot change these without actually rewriting the part of the program that creates the recent file list. Other menus, such as "File" or "Edit" or "Help" menu in Notepad, are created from a "resource" stored within the .exe file itself, and there are tools to edit such resources (to e.g. rearrange menu items or to change the program's icon).

But if you used such a tool to add new menu items, they wouldn't work, because the program wouldn't know what to do. There is no magic associated with each menu item, only a single number, a "command ID". For example, "Copy", being common in many programs, has command ID 12 ("IDM_COPY") assigned, and something specific to a single program (such as "New Game") could have 1234 or 2468 or something else. When you open a context menu and click on "Copy", Windows tells Notepad only that "command ID 12 was chosen", and it's up to Notepad to actually put selected text into clipboard whenever that happens.

  • Cut → ID 11 → Notepad puts text into clipboard, then deletes it from document
  • Copy → ID 12 → Notepad puts text into clipboard
  • Paste → ID 13 → Notepad gets text from clipboard, then inserts it into document
  • Sing → ID 12 → Notepad puts text into clipboard
  • Copy Again → ID 3456 → Notepad does nothing, since it has no clue what ID 3456 should mean

Side note: The above is a bit simplified. The context menu in Notepad is actually implemented by the "editable text" control, which is part of the aforementioned utility functions provided by Windows. The main menu, however, is entirely part of Notepad.

Side note: Some programs, usually those that can be skinned or themed, actually draw various controls by themselves – which isn't particularly hard, since a pop-up menu is just a window without a titlebar. While I haven't seen the code of such programs myself, I don't think the details would change much.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged .