by Danny Krotzer (2 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating:
(5 Votes)

This shows how to access another process' menu and clone it in your own application using API. The example allows you to choose an app from a list of open windows, then once the menu is 'cloned', it will allow you to execute menu items in the other process by clicking on them in your own app. This also demonstrates how to create & remove dynamic menus and submenus on your form, as well as handle messages from them when clicked (uses subclassing). API Calls: IsWindow(), SetWindowLong(), EnumWindows(), GetMenuString(), GetMenuItemID(), GetMenuItemCount(), GetMenu(), GetSubMenu(), AppendMenu(), DeleteMenu(), CreatePopupMenu(), DrawMenuBar(), CallWindowProc(), PostMessage(), GetWindowTextLength(), GetWindowText(), & IsWindowVisible()
Side Effects
As with any subclassing and cross-process calls, debugging can be tricky and cause VB Environment to crash so save project often if you make any changes.
Download MenuAPI Example v1 (6 KB)