MenuApi.bas
资源名称:IE_VB.rar [点击查看]
上传用户:davilee3
上传日期:2015-04-22
资源大小:986k
文件大小:13k
源码类别:
浏览器
开发平台:
Visual Basic
- Attribute VB_Name = "mMenuApi"
- '---------------------------------------------------------------------------------------
- ' Module : mMenuApi
- ' DateTime : 2005-4-19 19:02
- ' Author : Lingll
- ' Purpose :
- '---------------------------------------------------------------------------------------
- Option Explicit
- '== 菜单 =======================================
- '-= 取得ID =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- 'GetMenu 取得窗口中一个菜单的句柄。返回值:Long,依附于指定窗口的一个菜单的句柄(如果有菜单);否则返回零。
- 'GetSubMenu 取得一个弹出式菜单的句柄,它位于菜单中指定的位置。返回值:Long,位于指定位置的弹出式菜单的句柄(如果有的话);否则返回零
- Public Declare Function GetMenuInfo Lib "user32.dll" (ByVal hMenu As Long, ByRef LPMENUINFO As MENUINFO) As Long
- Public Declare Function SetMenuInfo Lib "user32.dll" (ByVal hMenu As Long, ByRef LPCMENUINFO As MENUINFO) As Long
- Public Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
- Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
- Public Declare Function InsertMenuItem Lib "user32" Alias "InsertMenuItemA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, ByRef lpcMenuItemInfo As MENUITEMINFO) As Long
- Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
- Public Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
- Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
- Public Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
- Public Declare Function CreatePopupMenu Lib "user32" () As Long
- Public Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
- Public Declare Function CreateMenu Lib "user32" () As Long
- Public Declare Function SetMenu Lib "user32" (ByVal hWnd As Long, ByVal hMenu As Long) As Long
- Public Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
- Public 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
- Public 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 Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
- Public Declare Function CheckMenuItem Lib "user32" (ByVal hMenu As Long, ByVal wIDCheckItem As Long, ByVal wCheck As Long) As Long
- Public Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
- Public Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
- Public Declare Function IsMenu Lib "user32" (ByVal hMenu As Long) As Long
- Public Declare Function MenuItemFromPoint Lib "user32" (ByVal hWnd As Long, ByVal hMenu As Long, ByVal ptX As Long, ByVal ptY As Long) As Long
- Public Declare Function GetMenuItemRect Lib "user32.dll" (ByVal hWnd As Long, ByVal hMenu As Long, ByVal uItem As Long, ByRef lprcItem As RECT) As Long
- '-= 属性 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- 'GetMenuItemInfo 用一个MENUITEMINFO结构取得(接收)与一个菜单条目有关的特定信息。返回值:Long,TRUE(非零)表示成功,否则返回零。
- 'SetMenuItemInfo 为一个菜单条目设置指定的信息,具体信息保存于MENUITEMINFO结构中。返回值:Long,TRUE(非零)表示成功,否则返回零。
- Public Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Long, lpMenuItemInfo As MENUITEMINFO) As Long
- Public Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
- '-- ODS_ ---------------------------------------
- Public Const ODS_SELECTED = &H1 '菜单被选择
- Public Const ODS_GRAYED = &H2 '灰色字
- Public Const ODS_DISABLED = &H4 '禁用
- Public Const ODS_CHECKED = &H8 '选中
- Public Const ODS_FOCUS = &H10 '聚焦
- '-= ODT_ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Public Const ODT_MENU = 1
- Public Const ODT_LISTBOX = 2
- Public Const ODT_COMBOBOX = 3
- Public Const ODT_BUTTON = 4
- '-- MF_ ----------------------------------------
- Public Const MF_BYCOMMAND = &H0& '菜单条目由菜单的命令ID指定
- Public Const MF_BYPOSITION = &H400& '菜单条目由条目在菜单中的位置决定。零代表菜单中的第一个条目
- Public Const MF_CHECKED = &H8& '检查指定的菜单条目。不能与VB的Checked属性兼容
- Public Const MF_DISABLED = &H2& '禁止指定的菜单条目。不与VB的Enabled属性兼容
- Public Const MF_ENABLED = &H0& '允许指定的菜单条目。不与VB的Enabled属性兼容
- Public Const MF_GRAYED = &H1& '禁止指定的菜单条目,并用浅灰色描述它。不与VB的Enabled属性兼容
- Public Const MF_HILITE = &H80&
- Public Const MF_SEPARATOR = &H800& '在指定的条目处显示一条分隔线
- Public Const MF_STRING = &H0& '在指定的条目处放置一个字串。不与VB的Caption属性兼容
- Public Const MF_UNCHECKED = &H0& '检查指定的条目。不能与VB的Checked属性兼容
- Public Const MF_UNHILITE = &H0&
- Public Const MF_BITMAP = &H4& '菜单条目是一幅位图。一旦设入菜单,这幅位图就绝对不能删除。所以不应该使用由VB的Image属性返回的值
- Public Const MF_OWNERDRAW = &H100& '创建一个物主绘图菜单(由您设计的程序负责描绘每个菜单条目)
- Public Const MF_USECHECKBITMAPS = &H200&
- Public Const MF_MENUBARBREAK = &H20& '在弹出式菜单中,将指定的条目放置于一个新列,并用一条垂直线分隔不同的列
- Public Const MF_MENUBREAK = &H40& '在弹出式菜单中,将指定的条目放置于一个新列。在顶级菜单中,将条目放置到一个新行
- Public Const MF_POPUP = &H10& '将一个弹出式菜单置于指定的条目。可用于创建子菜单及弹出式菜单
- Public Const MF_HELP = &H4000&
- Public Const MF_DEFAULT = &H1000
- Public Const MF_RIGHTJUSTIFY = &H4000
- '-- MIIM_ -------------------------------------
- Public Const MIIM_STATE = &H1& '设置或取得 fState | Sets or gets the fState field
- Public Const MIIM_ID = &H2 '设置或取得 wID | Sets or gets the wID field
- Public Const MIIM_SUBMENU = &H4 '设置或取得 hSubMenu | Sets or gets the hSubMenu field
- Public Const MIIM_CHECKMARKS = &H8 '设置或取得 hbmpChecked 与 hbmpUnchecked | Sets or gets the hbmpChecked and hbmpUnchecked fields
- Public Const MIIM_TYPE = &H10 '设置或取得 fType 与 dwTypeData | Sets or gets the fType and dwTypeData fields
- Public Const MIIM_DATA = &H20 '设置或取得 dwItemData | Sets or gets the dwItemData field
- Public Const MIIM_STRING = &H40
- Public Const MIIM_BITMAP = &H80
- Public Const MIIM_FTYPE = &H100
- '-- MFT_ ---------------------------------------
- Public Const MFT_STRING = MF_STRING
- Public Const MFT_BITMAP = MF_BITMAP
- Public Const MFT_MENUBARBREAK = MF_MENUBARBREAK
- Public Const MFT_MENUBREAK = MF_MENUBREAK
- Public Const MFT_OWNERDRAW = MF_OWNERDRAW
- Public Const MFT_RADIOCHECK = &H200
- Public Const MFT_SEPARATOR = MF_SEPARATOR
- Public Const MFT_RIGHTORDER = &H2000
- Public Const MFT_RIGHTJUSTIFY = MF_RIGHTJUSTIFY
- '-- MFS_ ---------------------------------------
- Public Const MFS_GRAYED = MF_GRAYED
- Public Const MFS_DISABLED = MF_DISABLED
- Public Const MFS_CHECKED = MF_CHECKED
- Public Const MFS_HILITE = MF_HILITE
- Public Const MFS_ENABLED = MF_ENABLED
- Public Const MFS_UNCHECKED = MF_UNCHECKED
- Public Const MFS_UNHILITE = MF_UNHILITE
- Public Const MFS_DEFAULT = MF_DEFAULT
- 'Public Const MFS_MASK = &H108B
- 'Public Const MFS_HOTTRACKDRAWN = &H10000000
- 'Public Const MFS_CACHEDBMP = &H20000000
- 'Public Const MFS_BOTTOMGAPDROP = &H40000000
- 'Public Const MFS_TOPGAPDROP = &H80000000
- 'Public Const MFS_GAPDROP = &HC0000000
- Public Const MNS_NOTIFYBYPOS As Long = &H8000000
- Public Const MIM_STYLE As Long = &H10
- Public Const MIM_MENUDATA As Long = &H8
- Public Type MENUITEMINFO
- cbSize As Long '结构大小,通常为44字节
- fMask As Long '设置或取得某些参数,以 MIIM_ 开始的常量。
- fType As Long '类型,以 MFT_ 开始的常量。如:MFT_OWNERDRAW
- fState As Long '属性,以 MFS_ 开始的常量。如:MFS_CHECKED
- wID As Long '菜单的ID,高16位没有使用 | Menu entry identifier. The high 16 bits are not used.
- hSubMenu As Long '是否有子菜单,若有为wID,否则为0 | Handle to a pop-up menu if one is associated with the menu entry
- hbmpChecked As Long '选中图标的hBitMap
- hbmpUnchecked As Long '非选中图标的hBitMap
- dwItemData As Long '这个项目关于用户定义的值 | User-defined value associated with this entry.
- dwTypeData As Long '根据fType的值而定 | Depends on the menu type
- cch As Long '如果fType为MFT_STRING,则为字符串的长度,否则为0 | Length of the menu string when MFT_STRING is specified. Zero for other menu types.
- End Type
- Public Type MENUINFO
- cbSize As Long
- fMask As Long
- dwStyle As Long
- cyMax As Long
- hbrBack As Long
- dwContextHelpID As Long
- dwMenuData As Long
- End Type
- Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As NONCLIENTMETRICS, ByVal fuWinIni As Long) As Long
- Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
- Private Const LF_FACESIZE As Long = 32
- Private Const SPI_GETNONCLIENTMETRICS As Long = 41
- Private Type LOGFONT
- lfHeight As Long
- lfWidth As Long
- lfEscapement As Long
- lfOrientation As Long
- lfWeight As Long
- lfItalic As Byte
- lfUnderline As Byte
- lfStrikeOut As Byte
- lfCharSet As Byte
- lfOutPrecision As Byte
- lfClipPrecision As Byte
- lfQuality As Byte
- lfPitchAndFamily As Byte
- lfFaceName(1 To LF_FACESIZE) As Byte
- End Type
- Private Type NONCLIENTMETRICS
- cbSize As Long
- iBorderWidth As Long
- iScrollWidth As Long
- iScrollHeight As Long
- iCaptionWidth As Long
- iCaptionHeight As Long
- lfCaptionFont As LOGFONT
- iSMCaptionWidth As Long
- iSMCaptionHeight As Long
- lfSMCaptionFont As LOGFONT
- iMenuWidth As Long
- iMenuHeight As Long
- lfMenuFont As LOGFONT
- lfStatusFont As LOGFONT
- lfMessageFont As LOGFONT
- End Type
- '---------------------------------------------------------------------------------------
- ' Procedure : SetMenuType
- ' DateTime : 2005-4-19 19:10
- ' Author : Lingll
- ' Purpose : 设置menu类型
- '---------------------------------------------------------------------------------------
- Public Sub SetMenuType(hMenu&, iItem&, fByPosition As Long, typeMask&, typeVal&)
- Dim mInfo As MENUITEMINFO
- With mInfo
- .cbSize = Len(mInfo)
- .fMask = MIIM_FTYPE
- End With
- Call GetMenuItemInfo(hMenu, iItem, fByPosition, mInfo)
- mInfo.fMask = MIIM_FTYPE
- mInfo.fType = ((mInfo.fType Or typeMask) Xor typeMask) Or typeVal
- Call SetMenuItemInfo(hMenu, iItem, fByPosition, mInfo)
- End Sub
- '---------------------------------------------------------------------------------------
- ' Procedure : GetMenuItemHeight
- ' DateTime : 2005-4-19 21:55
- ' Author : Lingll
- ' Purpose :
- '---------------------------------------------------------------------------------------
- Public Function GetMenuItemHeight() As Long
- Dim nm As NONCLIENTMETRICS
- nm.cbSize = Len(nm)
- Call SystemParametersInfo(SPI_GETNONCLIENTMETRICS, nm.cbSize, nm, 0)
- If nm.iMenuHeight > 19 Then
- GetMenuItemHeight = nm.iMenuHeight
- Else
- GetMenuItemHeight = 19
- End If
- End Function
- '---------------------------------------------------------------------------------------
- ' Procedure : GetMenuParam
- ' DateTime : 2005-8-3 12:07
- ' Author : Lingll
- ' Purpose :
- '---------------------------------------------------------------------------------------
- Public Function GetMenuParam(hMenu&) As Long
- Dim tMnuInfo As MENUINFO
- With tMnuInfo
- .cbSize = Len(tMnuInfo)
- .fMask = MIM_MENUDATA
- Call GetMenuInfo(hMenu, tMnuInfo)
- GetMenuParam = .dwMenuData
- End With
- End Function
- '---------------------------------------------------------------------------------------
- ' Procedure : SetMenuParam
- ' DateTime : 2005-8-3 12:07
- ' Author : Lingll
- ' Purpose :
- '---------------------------------------------------------------------------------------
- Public Function SetMenuParam(hMenu&, vData&) As Boolean
- Dim tMnuInfo As MENUINFO
- With tMnuInfo
- .cbSize = Len(tMnuInfo)
- .fMask = MIM_MENUDATA
- .dwMenuData = vData
- End With
- SetMenuParam = _
- (SetMenuInfo(hMenu, tMnuInfo) <> 0)
- End Function