让菜单条用图片显示
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function CreateCompatibleDC 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
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 DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Const SRCCOPY = &HCC0020
Const MF_BITMAP = &H4&
Const MF_BYPOSITION = &H400&
Private Sub Form_Click()
Dim nLoopCtr As Integer
Dim lResult As Long
Dim hTempDC As Long
Dim nWidth As Long
Dim nHeight As Long
Dim lTempID As Long
Dim hMenuID As Long
Dim lItemCount As Long
Dim hBitmap As Long
nWidth = Pic.Width \ Screen.TwipsPerPixelX
nHeight = Pic.Height \ Screen.TwipsPerPixelY
hMenuID = GetSubMenu(GetMenu(Me.hwnd), 0)
hTempDC = CreateCompatibleDC(Pic.hdc)
For i = 0 To 1
hBitmap = CreateCompatibleBitmap(Pic.hdc, nWidth, nHeight)
lTempID = SelectObject(hTempDC, hBitmap)
lResult = BitBlt(hTempDC, 0, 0, nWidth, nHeight, Pic.hdc, 0, 0, SRCCOPY)
lTempID = SelectObject(hTempDC, lTempID)
' M_Item1(i).Caption = ""
lResult = ModifyMenu(hMenuID, i, MF_BYPOSITION Or MF_BITMAP, GetMenuItemID(hMenuID, i), hBitmap)
Next i
lResult = DeleteDC(hTempDC)
End Sub
第二章-4.rar
(12.89 KB)