How to put a picture in a menu?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nagarwal
    New Member
    • Jun 2007
    • 13

    #1

    How to put a picture in a menu?

    Hi all:)

    I just want to put a picture in a menu list against the menu item i want...
    any suggestions? plz let me
    Thanx is advance:)
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    There is no direct method to achieve the same.

    You need to use API functions.

    Comment

    • nagarwal
      New Member
      • Jun 2007
      • 13

      #3
      Originally posted by debasisdas
      There is no direct method to achieve the same.

      You need to use API functions.
      hi frnd,

      can u plz tell me the API name & it's implementation: )

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        You need to use the following API

        [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]

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by debasisdas
          You need to use the following API...
          Could you provide a quick sample of how to do it? I'd like to put it in the Articles section.

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            You can try this following sample.

            [CODE=vb]Private Sub Form_Load()
            Picture1.Pictur e = LoadPicture("C: \Program Files\Microsoft Visual Studio\Common\G raphics\Bitmaps \OffCtlBr\Small \Color\CUT.BMP" )
            Dim D 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)
            End Sub[/CODE]

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              What is DU?

              Do you work without Option Explicit? If so, I think it's a really bad idea. Makes it much too easy to accidentally slip in non-existent variables.

              Comment

              • debasisdas
                Recognized Expert Expert
                • Dec 2006
                • 8119

                #8
                that is also LONG type.


                thanx for pointing to the mistake...

                Comment

                Working...