Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AppendMenu API MF_BITMAP and MF_CHECKED MF_UNCHECKED 1

Status
Not open for further replies.

patriciaxxx

Programmer
Jan 30, 2012
277
GB
The following code creates a popup menu with 7 options 1x, 1.5x etc.

How do I create the following behavior… set one option, say 2x, to a variable as checked when the menu is first created and then when you click on another it becomes the only checked one and passes a value to the variable, and so on.

Code:
Dim hMenu As Long
Dim hSubMenuMagnification As Long

hSubMenuMagnification = CreatePopupMenu
AppendMenu hSubMenuMagnification, 0, 121, "1x"
AppendMenu hSubMenuMagnification, 0, 122, "1.5x"
AppendMenu hSubMenuMagnification, 0, 123, "2x"
AppendMenu hSubMenuMagnification, 0, 124, "3x"
AppendMenu hSubMenuMagnification, 0, 125, "4x"
AppendMenu hSubMenuMagnification, 0, 126, "8x"
AppendMenu hSubMenuMagnification, 0, 127, "16x"

hMenu = CreatePopupMenu()
AppendMenu hMenu, MF_STRING, lngEXIT_APP, "Show Magnifying Glass…"
AppendMenu hMenu, MF_POPUP, hSubMenuMagnification, "Magnification"
AppendMenu hMenu, MF_SEPARATOR, ByVal 0&, ByVal 0&
AppendMenu hMenu, MF_STRING, lngRESTORE_WINDOW, "Exit"

buildMenu = hMenu

And how do you create an entry with a bitmap and text together on the same item. The following code creates a bitmap item and a text item but they are two separate menu items I want the item as one with bitmap and text together, how is this done?

Code:
AppendMenu hMenu, MF_STRING, lngEXIT_APP, "Show Magnifying Glass…"
AppendMenu hMenu, MF_BItMAP, 102, CLng(Forms!frmSystray.ImageList.ListImages(2).Picture)

Any help would be much appreciated as menu creation using API is new and confusing to me and all the examples I have seen are either very simple and don’t cover these points or in any code but VBA.
 
It's going to get more confusing. You can't directly set text and a bitmap using AppendMenu. The trick is to set the text, and then add a bitmap afterwards. And you do this using another API call: SetMenuItemBitmaps. Using your own code as the basis, we might have:

Code:
[blue]AppendMenu hMenu, MF_STRING, 102, "Example"
SetMenuItemBitmaps hMenu, 102, 0, CLng(Forms!frmSystray.ImageList.ListImages(2).Picture), CLng(Forms!frmSystray.ImageList.ListImages(2).Picture)[/blue]
 
Hello strongm

Well I tried a lot but I didn’t try that.

I have put those lines in to my menu code and I have bitmap and text together, I really am very grateful to you, I didn’t think I was going to get that one working.

As for the check / uncheck and set variable value I have set public constants for the AppendMenu() “newitem” values and public variables for the AppendMenu() “flag” values and then I use a case statement for the onclick menu item and get and set the values there.

I would like to know if you think that is an acceptable way of achieving that kind of behavior. It was the only thing I could think of and it does work.

Thank you again for your help in solving the bitmap with text problem for me I appreciate your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top