Adding Bitmap to Menu.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    Adding Bitmap to Menu.

    Add a menu item and a sub-menu to the main menu to the form.
    Add a picture box to the form and set its visible property to False.

    Add the following code to a general module (.BAS).(API Functions)
    =============== =============== =============== ====
    [code=vb]
    Public Declare Function CreateCompatibl eDC Lib "gdi32" (ByVal hdc As Long) As Long
    Public Declare Function CreateCompatibl eBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Public Declare Function ModifyMenu Lib "user32" Alias "ModifyMenu A" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
    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
    [/code]

    Add this code to the form load event.
    =============== ===============
    [code=vb]
    Picture1.Pictur e = LoadPicture(app .path & "\" & "CUT.BMP")
    Dim D As Long, DU as Long
    Dim H As Long
    D = CreateCompatibl eDC(Picture1.hd c)
    H = CreateCompatibl eBitmap(Picture 1.hdc, 16, 16)

    Dim P As Long
    P = SelectObject(D, H)
    DU = BitBlt(D, 0, 0, 16, 16, Picture1.hdc, 0, 0, &HCC0020)
    DU = SelectObject(D, P)
    D = ModifyMenu(GetS ubMenu(GetMenu( Me.hwnd), 0), 0, &H404, 0, H)
    [/code]
Working...