争怎路由网/网站教程/内容

VB打造超酷个性化菜单(4)

网站教程2024-06-20 阅读
属性: 菜单总体风格

Public Property Get Style() As MenuUserStyle

    Style = MenuStyle

End Property

 

Public Property Let Style(ByVal nMenuStyle As MenuUserStyle)

    MenuStyle = nMenuStyle

    Select Case nMenuStyle

        Case STYLE_WINDOWS                                              ' Windows 默认风格

            Set BarImage = LoadPicture()

            BarWidth = 20

            BarStyle = LBS_NONE

            BarStartColor = GetSysColor(COLOR_MENU)

            BarEndColor = BarStartColor

            SelectScope = ISS_ICON_TEXT

            TextEnabledColor = GetSysColor(COLOR_MENUTEXT)

            TextDisabledColor = GetSysColor(COLOR_GRAYTEXT)

            TextSelectColor = GetSysColor(COLOR_HIGHLIGHTTEXT)

            IconStyle = IIS_NONE

            EdgeStyle = ISES_SOLID

            EdgeColor = GetSysColor(COLOR_HIGHLIGHT)

            FillStyle = ISFS_SOLIDCOLOR

            FillStartColor = EdgeColor

            FillEndColor = FillStartColor

            BkColor = GetSysColor(COLOR_MENU)

            SepColor = TextDisabledColor

            SepStyle = MSS_DEFAULT

        Case STYLE_XP                                                   ' XP 风格

            Set BarImage = LoadPicture()

            BarWidth = 20

            BarStyle = LBS_NONE

            BarStartColor = GetSysColor(COLOR_MENU)

            BarEndColor = BarStartColor

            SelectScope = ISS_ICON_TEXT

            TextEnabledColor = GetSysColor(COLOR_MENUTEXT)

            TextDisabledColor = GetSysColor(COLOR_GRAYTEXT)

            TextSelectColor = TextEnabledColor

            IconStyle = IIS_SHADOW

            EdgeStyle = ISES_SOLID

            EdgeColor = RGB(49, 106, 197)

            FillStyle = ISFS_SOLIDCOLOR

            FillStartColor = RGB(180, 195, 210)

            FillEndColor = FillStartColor

            BkColor = GetSysColor(COLOR_MENU)

            SepColor = RGB(192, 192, 192)

            SepStyle = MSS_SOLID

        Case STYLE_SHADE                                                ' 渐变风格

            Set BarImage = LoadPicture()

            BarWidth = 20

            BarStyle = LBS_VERTICALCOLOR

            BarStartColor = vbBlack

            BarEndColor = vbWhite

            SelectScope = ISS_ICON_TEXT

            TextEnabledColor = GetSysColor(COLOR_MENUTEXT)

            TextDisabledColor = GetSysColor(COLOR_GRAYTEXT)

            TextSelectColor = GetSysColor(COLOR_HIGHLIGHTTEXT)

            IconStyle = IIS_NONE

            EdgeStyle = ISES_NONE

            EdgeColor = GetSysColor(COLOR_HIGHLIGHT)

            FillStyle = ISFS_HORIZONTALCOLOR

            FillStartColor = vbBlack

            FillEndColor = vbWhite

            BkColor = GetSysColor(COLOR_MENU)

            SepColor = TextDisabledColor

            SepStyle = MSS_DEFAULT

        Case STYLE_3D                                                   ' 3D 立体风格

            Set BarImage = LoadPicture()

            BarWidth = 20

            BarStyle = LBS_NONE

            BarStartColor = GetSysColor(COLOR_MENU)

            BarEndColor = BarStartColor

            SelectScope = ISS_TEXT

            TextEnabledColor = GetSysColor(COLOR_MENUTEXT)

            TextDisabledColor = GetSysColor(COLOR_GRAYTEXT)

            TextSelectColor = vbBlue

            IconStyle = IIS_RAISED

            EdgeStyle = ISES_SUNKEN

            EdgeColor = GetSysColor(COLOR_HIGHLIGHT)

            FillStyle = ISFS_NONE

            FillStartColor = EdgeColor

            FillEndColor = FillStartColor

            BkColor = GetSysColor(COLOR_MENU)

            SepColor = TextDisabledColor

            SepStyle = MSS_DEFAULT

        Case STYLE_COLORFUL                                             ' 炫彩风格

            Set BarImage = frmMenu.Picture

            BarWidth = 20

            BarStyle = LBS_IMAGE

            BarStartColor = GetSysColor(COLOR_MENU)

            BarEndColor = BarStartColor

            SelectScope = ISS_ICON_TEXT

            TextEnabledColor = vbBlue

            TextDisabledColor = RGB(49, 106, 197)

            TextSelectColor = vbRed

            IconStyle = IIS_NONE

            EdgeStyle = ISES_DOT

            EdgeColor = vbBlack

            FillStyle = ISFS_VERTICALCOLOR

            FillStartColor = vbYellow

            FillEndColor = vbGreen

            BkColor = RGB(230, 230, 255)

            SepColor = vbMagenta

            SepStyle = MSS_DASHDOTDOT

    End Select

End Property

 

    这个类模块中包含了各种属性和方法及关于菜单的一些枚举类型,我想强调的有以下几点:

    1、在CreateMenu方法中用SetWindowLong重新定义了frmMenu的窗口入口函数的地址,MenuWndProc是标准模块中的一个函数,就是处理消息的那个函数。

    2AddItem这个方法是添加菜单项的,使用一个叫做MyItemInfo的动态数组存储菜单项的内容,在“画”菜单项的时候要用到它。在AddItem方法的最后,将菜单项的fType设置成了MFT_OWNERDRAW,也就是物主绘图,这一步最关键,因为将菜单项设置成了Owner DrawWindows将不会替我们写字,不会替我们画图标,一切都由我们自己来。

    3、在PopupMenu方法中,调用了API函数中的TrackPopupMenu,看到第6个参数了吗?将处理菜单消息的窗口设置成了frmMenu,而我们又对frmMenu进行了子类处理,一切都在我们的掌握之中。

    4、记得要在Class_Terminate中还原frmMenu的窗口入口函数的地址,并释放和菜单相关的资源。

 

    好了,类模块已经OK了,大家可能对这个菜单类有了更多的了解,也看到了它的属性和方法。怎么样?还算比较丰富吧。如果觉得不够丰富的话,自己加就好了,呵呵。不过,最核心的部分还不在这里,而是在那个处理消息的函数,也就是MenuWndProc,它将完成复杂地“画”菜单的任务以及处理各种菜单事件。看看右边的滚动条,已经够窄了,下一篇再讨论吧。  :)




……

相关阅读