Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188406
  • 博文数量: 106
  • 博客积分: 3810
  • 博客等级: 中校
  • 技术积分: 1007
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 13:35
文章分类

全部博文(106)

文章存档

2014年(17)

2011年(5)

2010年(75)

2009年(9)

我的朋友

分类:

2010-04-30 00:10:45

不复杂,记录在这里以备以后要用时懒得重写....

效果图:





Option Explicit

'在菜单上添加自绘图形的例子

'窗体上添加一个Picture1,一个Command1,一个至少带一个下级菜单的顶级菜单.

'BY 嗷嗷叫的老马
'http://www.m5home.com/

Private Declare Function GetSubMenu Lib "user32.dll" ( _
     ByVal hMenu As Long, _
     ByVal nPos As Long) As Long
Private Declare Function GetMenu Lib "user32.dll" ( _
     ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemID Lib "user32.dll" ( _
     ByVal hMenu As Long, _
     ByVal nPos As Long) As Long
Private Declare Function SetMenuItemBitmaps Lib "user32.dll" ( _
     ByVal hMenu As Long, _
     ByVal nPosition As Long, _
     ByVal wFlags As Long, _
     ByVal hBitmapUnchecked As Long, _
     ByVal hBitmapChecked As Long) As Long
Private Declare Function DrawIcon Lib "user32.dll" ( _
     ByVal hdc As Long, _
     ByVal x As Long, _
     ByVal y As Long, _
     ByVal hIcon As Long) As Long
Private Const MF_BITMAP As Long = &H4&

Private Sub Command1_Click()
    Dim hMenu As Long, hSubMenu As Long, hID As Long
    
    '效果一:绘上当前窗体图标
' DrawIcon Picture1.hdc, -5, -5, Me.Icon.Handle
    
    '效果二:画个小图....
    Picture1.Line (1, 1)-(11, 11), vbBlue, B
    Picture1.Line (1, 1)-(11, 11), vbRed
    Picture1.Line (1, 11)-(11, 1), vbRed
    
    Set Picture1.Picture = Picture1.Image '这一句是关键
    
    hMenu = GetMenu(Me.hwnd)
    hSubMenu = GetSubMenu(hMenu, 0)
    hID = GetMenuItemID(hSubMenu, 0)
    SetMenuItemBitmaps hMenu, hID, MF_BITMAP, Picture1.Picture, Picture1.Picture
End Sub

Private Sub Form_Load()
    With Picture1
        .Move .Left, .Top, 15 * 15, 15 * 15
        .Appearance = 0
        .AutoRedraw = True
        .ScaleMode = vbPixels
    End With
End Sub


阅读(745) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~