Icons on popup menus
From: Tom_OM (dontspamme_at_junkmailstinks.com)
Date: 10/30/04
- Next message: Veign: "Re: Icons on popup menus"
- Previous message: Tom_OM: "Re: Installing both Visual Studio Professional and Enterprise"
- Next in thread: Veign: "Re: Icons on popup menus"
- Reply: Veign: "Re: Icons on popup menus"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 30 Oct 2004 02:41:09 GMT
I've used modified code from a tutorial
(http://skaiste.elekta.lt/Books/windows/VB-HOWTO/index2-7.html) off
and on for a while now for putting images into menus and it's always
served me well. However, for some reason this code isn't working on a
popup menu. I have a toolbar that the user clicks on to make the menu
pop up. When the menu pops up -- no dice. The icon (actually, it's a
bitmap) isn't there.
For some reason, this line of code in my Form_Load sub is the culprit:
mnuHelp.Visible = False
If I rem out that line, the icon shows up in the menu, both in the
regular one and on the popup one. I'm wondering why this popup menu
is being so stubborn. Why is it refusing to show its icon unless it
is allowed to be visible as a regular menu?
The icon is being gotten from a PictureBox control array named
picHelp(0) -- aka picHelp(picHelpContents) as it's known with its
Enum. Here's my code:
>From the form's Declarations section:
' ############################# Enums for pics in menus START
###################
Private Enum PicsToMenu
enmPopUpMenu = 0
enmHelpMenu = 1
enmHelpContents = 0
enmHelpWhatsThis = 1
enmHelpWhatsNew = 2
enmHelpAbout = 3
picHelpContents = 0
picWhatsThis = 1
picWhatsNew = 2
picAbout = 3
End Enum
' ##############################Enums for pics in menus STOP
####################
In module:
'---------------------------------------------------------------------------------------
' Module : modPicMenus
' Purpose : API Calls for adding images to menus
'---------------------------------------------------------------------------------------
Option Explicit
Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As
Long
Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long,
_
ByVal nPos As Long) As Long
Public Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As
Long, _
ByVal nPos As Long) As Long
Public Declare Function SetMenuItemBitmaps Lib "user32" (ByVal hMenu
As Long, _
ByVal nPosition As Long, ByVal wFlags As Long, ByVal
hBitmapUnchecked As Long, _
ByVal hBitmapChecked As Long) As Long
Private Sub tbrHelp_ButtonClick(ByVal Button As MSComctlLib.Button)
PopupMenu mnuHelp
End Sub
in Form_Load:
' put icons into menus
Call PicsToMenu
' hide popup menu & help menu
mnuPopUp.Visible = False
mnuHelp.Visible = False
'---------------------------------------------------------------------------------------
' Procedure : PicsToMenu
' Purpose : Put pictures into menus
'---------------------------------------------------------------------------------------
Private Sub PicsToMenu()
On Error Resume Next
Dim lngMenu As Long
Dim lngSubMenu As Long
Dim lngMenuItemID As Long
Dim lngRet As Long
lngMenu = GetMenu(frmStart.hwnd) ' get handle of menu collection
lngSubMenu = GetSubMenu(lngMenu, enmHelpMenu) ' Get menu value
'Get menu ID:
lngMenuItemID = GetMenuItemID(lngSubMenu, enmHelpMenu)
' Put "help contents" image into menu:
lngMenuItemID = GetMenuItemID(lngSubMenu, enmHelpContents)
lngRet = SetMenuItemBitmaps(lngMenu, lngMenuItemID, 0, _
picHelp(picHelpContents).Picture,
picHelp(picHelpContents).Picture)
End Sub
- Next message: Veign: "Re: Icons on popup menus"
- Previous message: Tom_OM: "Re: Installing both Visual Studio Professional and Enterprise"
- Next in thread: Veign: "Re: Icons on popup menus"
- Reply: Veign: "Re: Icons on popup menus"
- Messages sorted by: [ date ] [ thread ]