我看到个例子,但忘记了
我想利用API实现位图菜单,即在菜单的文字前面放置一个图标(美化程序)

解决方案 »

  1.   

    源代码:
    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 GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private 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
    Const SRCCOPY = &HCC0020
    Const MF_BYPOSITION = &H400&
    Const MF_BITMAP = &H4&
    '--------------------------------
        Dim nLoopCtr As Integer
        Dim lResult As Long
        Dim hTempDC As Long
        Dim nWidth As Integer
        Dim nHeight As Integer
        Dim lTempID As Long
        Dim hMenuID As Long
        Dim lItemCount As Long
        Dim hBitmap As Long
        nWidth = Picture1(nLoopCtr).Width \ Screen.TwipsPerPixelX
        nHeight = Picture1(nLoopCtr).Height \ Screen.TwipsPerPixelY
        hMenuID = GetSubMenu(GetMenu((Me.hwnd)), 1)
        hTempDC = CreateCompatibleDC(Picture1(nLoopCtr).hdc)
        For nLoopCtr = 0 To 3
            hBitmap = CreateCompatibleBitmap(Picture1(nLoopCtr).hdc, nWidth, nHeight)
            lTempID = SelectObject(hTempDC, hBitmap)
            lResult = BitBlt(hTempDC, 0, 0, nWidth, nHeight, (Picture1(nLoopCtr).hdc), 0, 0, SRCCOPY)
            lTempID = SelectObject(hTempDC, lTempID)
            SystemSetSub(nLoopCtr).Caption = ""
            lResult = ModifyMenu(hMenuID, nLoopCtr, MF_BYPOSITION Or MF_BITMAP, GetMenuItemID(hMenuID, nLoopCtr), hBitmap)
        Next nLoopCtr
        lResult = DeleteDC(hTempDC)
    上面的怎么运行不起来
    我在form中加了4个图片框,名为pictrue1,索引为:0,1,2,3 菜单名为SystemSetSub,索引也为0,1,2,3
    现在效果出不来,望各位帮忙