Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

SetMenuBitmap - Add a bitmap to a menu item

Total Hit ( 3737)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, _
  ByVal nPos As Long) As Long
Private 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 Const MF_BYPOSITION = &H400&

' add a bitmap to a menu item
'
' The first two arguments can be the Picture property
' of a PictureBox control, or the result from a LoadPicture
' function. If CheckedPicture is Nothing, the first Picture is
' used both for the unchecked and checked status.
' To remove a menu picture, use Nothing for both arguments
'
' Warning: Use the GetSystemMetrics function with the
' CXMENUCHECK and CYMENUCHECK values to retrieve the bitmap
' dimensions. (Typical max size is 13x13 pixels.)
' Bitmaps larger than this size make this function fail.
'
' The third argument is the hWnd of the form
'
' All the arguments from the 4th one onward serve to
' identify which menu should be assigned the bitmap.
' For example, the following statement assign the bitmap in
' Picture1 to the 3rd menu item of the 2nd submenu
' (note that menu indexes are zero-based)
'   SetMenuBitmap Picture1, Nothing, Me.hWnd, 1, 2

Sub SetMenuBitmap(Picture As StdPicture, CheckedPicture As StdPicture, _
  ByVal hWnd As Long, ParamArray menuPos() As Variant)
  Dim hMenu As Long
  Dim id As Long
  Dim i As Long
  Dim chkPicture As StdPicture
  
  ' provide a value for the CheckedPicture
  If CheckedPicture Is Nothing Then
    Set chkPicture = Picture
  Else
    Set chkPicture = CheckedPicture
  End If
  
  ' get the handle of the toplevel menu
  hMenu = GetMenu(hWnd)
  
  ' all the values in menuPos() except the last one
  ' are indexes of submenus
  For i = 0 To UBound(menuPos) - 1
    hMenu = GetSubMenu(hMenu, menuPos(i))
  Next
  
  ' the last element in the paramarray is the
  ' index of a menu item
  If Picture Is Nothing Then
    SetMenuItemBitmaps hMenu, menuPos(UBound(menuPos)), MF_BYPOSITION, 0, 0
  Else
    SetMenuItemBitmaps hMenu, menuPos(UBound(menuPos)), MF_BYPOSITION, _
      Picture.Handle, chkPicture.Handle
  End If
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.