How to add custom menu item to an existing app?
C#.
Example:
(source: brianapps.net)I'm working on a screen capture software, so I want to开发者_开发技巧 enable specific window capture.
mnuHandle = GetSystemMenu(hwnd, false)
//add a line to the end
AppendMenu(mnuHandle, MF_SEPARATOR, 0, "")
//2 add a command ID = 200
AppendMenu(mnuHandle, MF_STRING, 0x200, "Command &1")
AppendMenu(mnuHandle, MF_STRING, 0x201, "Command &2")
//insert a new item to the 2. position
InsertMenu(mnuHandle, 2, MF_BYPOSITION, 0x202, "Command &3")
//remove a standard item
RemoveMenu(mnuHandle, 0, MF_BYPOSITION)
it's not the point to create the menu items in the system menu of a totally different application... the question is more or less how would you hook the upcoming system menu events?
If resizing an arbitrary window is what you want to do: just fetch the window handle of the program (how would you do this?) and call SetWindowPos http://msdn.microsoft.com/en-us/library/ms633545(v=VS.85).aspx
You can call the GetSystemMenu
API method to get a handle to an existing window's system menu.
You can then call InsertMenuItem
to add an item to the menu.
精彩评论