|
|
|
|
|
Dicas
|
|
Visual Basic (Menu/Toobar/Coolbar)
|
|
|
Título da Dica: Colocando bitmaps em menus
|
|
|
|
Postada em 14/8/2000 por Webmaster
webmaster@vbweb.com.br
'Com esta dica você poderá dar um incremento visual em seus programas, incluindo bitmaps nos ítens de menu.
'Coloque o código a seguir em um módulo: Declare Function GetMenu Lib "user32" (ByVal _ hWnd As Long) As Long Declare Function GetSubMenu Lib "user32" (ByVal _ hMenu As Long, ByVal nPos As Long) As Long Declare Function GetMenuItemID Lib "user32" _ (ByVal hMenu As Long, ByVal nPos As _ Long) As Long 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
Public Const MF_BITMAP As Long = &H4&
Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As String cch As Long End Type
Declare Function GetMenuItemCount Lib "user32" _ (ByVal hMenu As Long) As Long Declare Function GetMenuItemInfo Lib "user32" _ Alias "GetMenuItemInfoA" (ByVal hMenu As _ Long, ByVal un As Long, ByVal b As Boolean, _ lpMenuItemInfo As MENUITEMINFO) As Boolean
Public Const MIIM_ID As Long = &H2 Public Const MIIM_TYPE As Long = &H10 Public Const MFT_STRING As Long = &H0&
'Agora crie um formulário, coloque nele os menus, um picturebox (autosize=true) com um bitmap de tamanho máximo 13x13 e adicione o seguinte código em um botão:
Private Sub Command1_Click() Dim hMenu As Long, hsubMenu As Long, hID As Long 'Recupera o handle do menu formulário hMenu = GetMenu(Form1.hWnd) 'Recupera o handle do 1º menu hsubMenu = GetSubMenu(hMenu, 0) 'Pega o menuId do 1º submenu hID = GetMenuItemID(hsubMenu, 0) 'Adiciona o bitmap ao submenu SetMenuItemBitmaps hMenu, hID, MF_BITMAP, _ Picture1.Picture, Picture1.Picture 'Você pode colocar dois bitmaps no menu 'Uma para o estado selecionado, e outro 'para o não selecionado. End Sub
|
|
|
|
|