The SetLayeredWindowAttributes function sets the opacity and the transparency color key of a layered window. Find an example of using this function in Semi-transparent Form code sample in this reference.
All menu popups are layered windows, which makes this technique applicable to them.
All VFP menus are owner-draw menus. The WM_DRAWITEM message is sent to the parent window of an owner-drawn menu when its visual aspect has changed. Through this message the window procedure obtains a pointer to the DRAWITEMSTRUCT structure.
This structure contains the hDC for a menu popup window. Pass this hDC to the WindowFromDC function to obtain the window handle (HWND) for the menu pop window.
In VFP9, BINDEVENT() function can intercept Windows messages including the WM_DRAWITEM. Thus a VFP application can be notified whenever any menu popup is redrawn. So the application can intervene and make a popup window transparent or semi-transparent.
To test the MenuManager class, copy the code sample to MenuManager.prg and type in the Command Window:
oManager = NEWOBJECT("MenuManager", "MenuManager.prg")
oManager.SetHook(Application.hWnd) && VFP9 required
After that the VFP System Menu will show semi-transparent. Release the MenuManager object to return the menu back to its normal state.
Transparency settings (crKey and bAlpha parameters in SetLayeredWindowAttributes call) should be carefully picked to ensure menu readability.
Menu related Windows messages:
WM_ENTERMENULOOP
WM_INITMENU
WM_MENUSELECT
WM_INITMENUPOPUP
WM_DRAWITEM
WM_UNINITMENUPOPUP
WM_COMMAND
WM_EXITMENULOOP
WM_ENTERIDLE
WM_SYSCOMMAND
* * *
Recommended reading: OwnerDrawn Menus, an article written by Herman Tan and published in October 2005 issue of UniversalThread Magazine.
* * * ContextMenu Control
Designed for generating and displaying shortcut menus on VFP forms. A generated menu is object-oriented: menu items are accessible during runtime, can be modified, added and deleted. A menu can be exported to XML string, as well as loaded from a XML string.
Credits: PHP (4.4.9), an HTML-embedded scripting language,
MySQL (5.1.55-log), the Open Source standard SQL database,
AceHTML Freeware
Version 4, freeware HTML Editor of choice. Hosted by Korax Online Inc.