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

时间:2022-06-22 19:06:46
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

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

 

(接上篇)

 

 

' 属性: 菜单总体风格<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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 Draw,Windows将不会替我们写字,不会替我们画图标,一切都由我们自己来。

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

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

 

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

 

(待续)

 

相关链接:

(一)

(二)

(三)

(四)

(五)

(六)

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>