装扮你的程序菜单 2001年 16期 现在许多软件的菜单条中有图形,比如Windows的开始菜单就是如此。现在就让我们用VB在自己的程序菜单中也加入图形吧(^16020502a^)。   1.新建一个工程,将Form1的Caption属性设为:“图形菜单”,其它不变。   2 .打开菜单设计器,为窗体添加两个菜单项:第1项的标题设置为&File名称设置为mnuFile其下添加3个子菜单项,它们的标题分别设置为:&New、&Open、&Save,名称为:mnuNew、mnuOpen、mnuSave。第2项的标题设置为&Edit,名称设置为mnuEdit,其下添加3个子菜单项,它们的标题分别设置为:&Copy、&Cut、&Paste,名称为:mnuCopy、mnuCut、mnuPaste。   3.在窗体上任意位置添加6个Image控件,利用属性框的Picture属性装入图片(这里选择Windows中默认的新建、打开、保存、复制、剪切、粘贴等图形,可在VB的安装目录下找到),并将它们的Name属性分别设置为:imgNew、imgOpen、imgSave、imgCopy、imgCut、imgPaste,然后将它们的Visible属性设置为False,即在程序运行过程中不可见。   4. 添加代码。   首先,我们要引用3个API函数:GetMenu、GetSubMenu、SetMenuItemBitmaps,它们的作用分别是:获得菜单的句柄、获得子菜单项的句柄、设置菜单项图形。在程序中的声明部分添加如下代码:   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 SetMenuItemBitmaps Lib “user32” (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long   Const myflag = &H400&   接着,在Form_Load事件中添加如下代码,为菜单加入图形:   Private Sub Form_Load()   Dim mHandle As Long, lRet As Long, sHandle As Long   mHandle = GetMenu(hwnd)   sHandle = GetSubMenu(mHandle, 0)   lRet = SetMenuItemBitmaps(sHandle, 2, myflag, imgnew.Picture,imgnew.Picture)   lRet = SetMenuItemBitmaps(sHandle, 3, myflag, imgopen.Picture,imgopen.Picture)   lRet = SetMenuItemBitmaps(sHandle,4,myflag, imgsave.Picture, imgsave.Picture)   sHandle = GetSubMenu(mHandle, 1)   lRet = SetMenuItemBitmaps(sHandle,6,myflag,imgcopy.Picture, imgcopy.Picture)   lRet = SetMenuItemBitmaps(sHandle,7, myflag, imgcut.Picture, imgcut.Picture)   lRet = SetMenuItemBitmaps(sHandle,8, myflag,imgpaste.Picture, imgpaste.Picture)   End Sub   好了,就这么简单,按下F5键,看看效果吧。