You don't plan to do a Unicode menu, do you?
Hans
Unicode menu
Re: Unicode menu
I am sorry, I already found a very quick solution including some APIs.
Public Function SetMenuCaption(uForm As Form, lSubItem As Long, lMenuItem As Long, ByVal uText As String, oPicChecked As IPictureDisp, oPicUnchecked As IPictureDisp) As Boolean
On Error GoTo ErrHandler
'/* Use like that:
' Dim Control As Control
' For Each Control In controls
' If TypeOf Control Is Menu Then
' Debug.Print Control.Name
' End If
' Next Control
' Debug.Print FormMenuSetIcon(Me, 0&, 0&, Me.Picture, Me.Picture)
' Debug.Print FormMenuSetIcon(Me, 0&, 1&, Me.Picture, Me.Picture)
'/*
Const MF_BYCOMMAND = &H0&
Dim MII As MENUITEMINFO, strBuffer As String
Dim lhWndMenu As Long
Dim lhWndSubMenu As Long
Dim lhWndMenuItem As Long
'Get the menu handle
lhWndMenu = GetMenu(uForm.hWnd)
'Get the handle of the submenu
lhWndSubMenu = GetSubMenu(lhWndMenu, lSubItem)
'Get the handle of the menu item
lhWndMenuItem = GetMenuItemID(lhWndSubMenu, lMenuItem)
If lhWndMenuItem Then
MII.cbSize = Len(MII)
MII.fMask = MIIM_STRING
If GetMenuItemInfoW(lhWndMenu, lhWndMenuItem, 0&, MII) Then
strBuffer = Space$(MII.cch)
MII.dwTypeData = StrPtr(strBuffer)
MII.cch = MII.cch + 1
If GetMenuItemInfoW(lhWndMenu, lhWndMenuItem, 0&, MII) Then
Debug.Print """" & strBuffer & """"
MII.cch = 3
strBuffer = uText 'ChrW$(947) & ChrW$(&H3043)
MII.dwTypeData = StrPtr(strBuffer)
If SetMenuItemInfoW(lhWndMenu, lhWndMenuItem, 0&, MII) Then
Else
Debug.Print "SetMenuItemInfoW failed"
End If
Else
Debug.Print "GetMenuItemInfoW second phase failed"
End If
Else
Debug.Print "GetMenuItemInfoW failed"
End If
'The form has a sub menu, add the picture/icon
SetMenuCaption = CBool(SetMenuItemBitmaps(lhWndMenu, lhWndMenuItem, MF_BYCOMMAND, oPicChecked.Handle, oPicUnchecked.Handle))
If SetMenuCaption Then
'Added successfully, repaint the menu
'''''''Call DrawMenuBar(lhWndMenu)
End If
End If
Public Function SetMenuCaption(uForm As Form, lSubItem As Long, lMenuItem As Long, ByVal uText As String, oPicChecked As IPictureDisp, oPicUnchecked As IPictureDisp) As Boolean
On Error GoTo ErrHandler
'/* Use like that:
' Dim Control As Control
' For Each Control In controls
' If TypeOf Control Is Menu Then
' Debug.Print Control.Name
' End If
' Next Control
' Debug.Print FormMenuSetIcon(Me, 0&, 0&, Me.Picture, Me.Picture)
' Debug.Print FormMenuSetIcon(Me, 0&, 1&, Me.Picture, Me.Picture)
'/*
Const MF_BYCOMMAND = &H0&
Dim MII As MENUITEMINFO, strBuffer As String
Dim lhWndMenu As Long
Dim lhWndSubMenu As Long
Dim lhWndMenuItem As Long
'Get the menu handle
lhWndMenu = GetMenu(uForm.hWnd)
'Get the handle of the submenu
lhWndSubMenu = GetSubMenu(lhWndMenu, lSubItem)
'Get the handle of the menu item
lhWndMenuItem = GetMenuItemID(lhWndSubMenu, lMenuItem)
If lhWndMenuItem Then
MII.cbSize = Len(MII)
MII.fMask = MIIM_STRING
If GetMenuItemInfoW(lhWndMenu, lhWndMenuItem, 0&, MII) Then
strBuffer = Space$(MII.cch)
MII.dwTypeData = StrPtr(strBuffer)
MII.cch = MII.cch + 1
If GetMenuItemInfoW(lhWndMenu, lhWndMenuItem, 0&, MII) Then
Debug.Print """" & strBuffer & """"
MII.cch = 3
strBuffer = uText 'ChrW$(947) & ChrW$(&H3043)
MII.dwTypeData = StrPtr(strBuffer)
If SetMenuItemInfoW(lhWndMenu, lhWndMenuItem, 0&, MII) Then
Else
Debug.Print "SetMenuItemInfoW failed"
End If
Else
Debug.Print "GetMenuItemInfoW second phase failed"
End If
Else
Debug.Print "GetMenuItemInfoW failed"
End If
'The form has a sub menu, add the picture/icon
SetMenuCaption = CBool(SetMenuItemBitmaps(lhWndMenu, lhWndMenuItem, MF_BYCOMMAND, oPicChecked.Handle, oPicUnchecked.Handle))
If SetMenuCaption Then
'Added successfully, repaint the menu
'''''''Call DrawMenuBar(lhWndMenu)
End If
End If
Re: Unicode menu
Note: StdPicture and IPictureDisp can't handle images with a color depth of 32 bits per pixel. Also if you want really nice-looking icons within menus, you'll need owner-drawn menus.
I've attached a sample project that I wrote for a friend a while ago. It uses owner-drawn menus and 32 bpp icons and supports Unicode.
To answer your initial question: Simple Unicode menus can be easily done through the API. Something like ActiveBar from DataDynamics is appealling, but also more work than I could handle. I doubt I'll ever develop such a component.
I've attached a sample project that I wrote for a friend a while ago. It uses owner-drawn menus and 32 bpp icons and supports Unicode.
To answer your initial question: Simple Unicode menus can be easily done through the API. Something like ActiveBar from DataDynamics is appealling, but also more work than I could handle. I doubt I'll ever develop such a component.
- Attachments
-
- ShellMenu2.zip
- (74.86 KiB) Downloaded 821 times
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
Boycott DRM! Boycott HDCP!