VB中如何在一个菜单里面有小的位图

发表于:2007-06-21来源:作者:点击数: 标签:
下面的这段代码将picture1的图形作为菜单项。 首先建立一个模块,并加入下面的语句。 declare function getmenu lib "user32" _ (byval hwnd as long) as long declare function getsubmenu lib "user32" _ (byval hmenu as long, byval npos as long) as lo

   
  下面的这段代码将picture1的图形作为菜单项。
   首先建立一个模块,并加入下面的语句。
   declare function getmenu lib "user32" _
    (byval hwnd as long) as long

   declare function getsubmenu lib "user32" _
    (byval hmenu as long, byval npos as long) as long
   declare function getmenuitemid lib "user32" _
    (byval hmenu as long, byval npos as long) as long
   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
   
   public const mf_bitmap = &h4&
   
   type menuiteminfo
    cbsize as long
    fmask as long
    ftype as long
    fstate as long
    wid as long
    hsubmenu as long
    hbmpchecked as long
    hbmpunchecked as long
    dwitemdata as long
    dwtypedata as string
    clearcase/" target="_blank" >cch as long
   end type
   
   declare function getmenuitemcount lib "user32" _
    (byval hmenu as long) as long
   declare function getmenuiteminfo lib "user32" _
    alias "getmenuiteminfoa" (byval hmenu as long, _
    byval un as long, byval b as boolean, _
    lpmenuiteminfo as menuiteminfo) as boolean
   
   public const miim_id = &h2
   public const miim_type = &h10
   public const mft_string = &h0&
   将下面的代码加入一个按钮的click事件:
   private sub command1_click()
   
   ' 获得你的菜单的句柄
   hmenu& = getmenu(form1.hwnd)
   
   ' 获得第一个子菜单的句柄
   hsubmenu& = getsubmenu(hmenu&, 0)
   
   ' 获得第一个菜单项
   hid& = getmenuitemid(hsubmenu&, 0)
   
   '加入位图
   
   setmenuitembitmaps hmenu&, hid&, mf_bitmap, _
    picture1.picture, _
    picture1.picture
   end sub
   上面的代码使菜单项为图片,如果你只希望菜单项的左边有一个小位图,而右边仍为文字。可以先在picture1绘制图片,在利用picture1.print加上文字,然后用picture1.picture加入菜单项

原文转自:http://www.ltesting.net