大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> VB打造超酷个性化菜单(五)

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

时间: 2021-07-31 作者:daque

此刻到了最要害,最精粹,也是最搀杂的局部了。咱们最关怀的即是还好吗“画”菜单,还好吗处置菜单事变,在menuwndproc这个处置动静的因变量里,咱们要处置如次动静:wm_command(单击菜单项),wm_measureitem(处置菜单莫大和宽窄),wm_menuselect(采用菜单项),wm_drawitem(绘制菜单项)。    翻开上回建好的工程,增添一个规范模块,并将其称呼树立为mmenu,代码如次:

'**************************************************************************************************************'* 本模块共同 cmenu 菜单类模块'*'**************************************************************************************************************

option explicit

' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- api 因变量证明 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

public declare function bitblt lib "gdi32" (byval hdestdc as long, byval x as long, byval y as long, byval nwidth as long, byval nheight as long, byval hsrcdc as long, byval xsrc as long, byval ysrc as long, byval dwrop as long) as longpublic declare function callwindowproc lib "user32" alias "callwindowproca" (byval lpprevwndfunc as long, byval hwnd as long, byval msg as long, byval wparam as long, byval lparam as long) as longpublic declare function createcompatibledc lib "gdi32" (byval hdc as long) as longpublic declare function createpen lib "gdi32" (byval npenstyle as long, byval nwidth as long, byval crcolor as long) as longpublic declare function createpopupmenu lib "user32" () as longpublic declare function createsolidbrush lib "gdi32" (byval crcolor as long) as longpublic declare function deletedc lib "gdi32" (byval hdc as long) as longpublic declare function deletemenu lib "user32" (byval hmenu as long, byval nposition as long, byval wflags as long) as longpublic declare function deleteobject lib "gdi32" (byval hobject as long) as longpublic declare function destroymenu lib "user32" (byval hmenu as long) as longpublic declare function drawedge lib "user32" (byval hdc as long, qrc as rect, byval edge as long, byval grfflags as long) as longpublic declare function drawiconex lib "user32" (byval hdc as long, byval xleft as long, byval ytop as long, byval hicon as long, byval cxwidth as long, byval cywidth as long, byval istepifanicur as long, byval hbrflickerfreedraw as long, byval diflags as long) as longpublic declare function drawstate lib "user32" alias "drawstatea" (byval hdc as long, byval hbrush as long, byval lpdrawstateproc as long, byval lparam as long, byval wparam as long, byval n1 as long, byval n2 as long, byval n3 as long, byval n4 as long, byval un as long) as longpublic declare function drawtext lib "user32" alias "drawtexta" (byval hdc as long, byval lpstr as string, byval ncount as long, lprect as rect, byval wformat as long) as longpublic declare function fillrect lib "user32" (byval hdc as long, lprect as rect, byval hbrush as long) as longpublic declare function getdc lib "user32" (byval hwnd as long) as longpublic declare function getmenuitemcount lib "user32" (byval hmenu as long) as longpublic declare function getmenuitemid lib "user32" (byval hmenu as long, byval npos as long) as longpublic declare function getmenuiteminfo lib "user32" alias "getmenuiteminfoa" (byval hmenu as long, byval un as long, byval b as long, lpmenuiteminfo as menuiteminfo) as longpublic declare function getsyscolor lib "user32" (byval nindex as long) as longpublic declare function getsystemmetrics lib "user32" (byval nindex as long) as longpublic declare function inflaterect lib "user32" (lprect as rect, byval x as long, byval y as long) as longpublic declare function insertmenuitem lib "user32" alias "insertmenuitema" (byval hmenu as long, byval un as long, byval bool as boolean, byref lpcmenuiteminfo as menuiteminfo) as longpublic declare function lineto lib "gdi32" (byval hdc as long, byval x as long, byval y as long) as longpublic declare function lstrlen lib "kernel32" alias "lstrlena" (byval lpstring as string) as longpublic declare function movetoex lib "gdi32" (byval hdc as long, byval x as long, byval y as long, lppoint as long) as longpublic declare function rectangle lib "gdi32" (byval hdc as long, byval x1 as long, byval y1 as long, byval x2 as long, byval y2 as long) as longpublic declare function releasedc lib "user32" (byval hwnd as long, byval hdc as long) as longpublic declare function selectobject lib "gdi32" (byval hdc as long, byval hobject as long) as longpublic declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as longpublic declare function setbkmode lib "gdi32" (byval hdc as long, byval nbkmode as long) as longpublic declare function setmenuiteminfo lib "user32" alias "setmenuiteminfoa" (byval hmenu as long, byval un as long, byval bool as boolean, lpcmenuiteminfo as menuiteminfo) as longpublic declare function settextcolor lib "gdi32" (byval hdc as long, byval crcolor as long) as longpublic declare function setwindowlong lib "user32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long

public declare sub copymemory lib "kernel32" alias "rtlmovememory" (destination as any, source as any, byval length as long)

' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- api 恒量证明 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

public const gwl_wndproc = (-4)                     ' setwindowlong 树立窗口因变量进口地方public const sm_cymenu = 15                         ' getsystemmetrics 赢得体例菜单项莫大

public const wm_command = &h111                     ' 动静: 单击菜单项public const wm_drawitem = &h2b                     ' 动静: 绘制菜单项public const wm_exitmenuloop = &h212                ' 动静: 退出菜单动静轮回public const wm_measureitem = &h2c                  ' 动静: 处置菜单莫大和宽窄public const wm_menuselect = &h11f                  ' 动静: 采用菜单项

' odtpublic const odt_menu = 1                           ' 菜单public const odt_listbox = 2                        ' 列表框public const odt_combobox = 3                       ' 拉拢框public const odt_button = 4                         ' 按钮

' odspublic const ods_selected = &h1                     ' 菜单被采用public const ods_grayed = &h2                       ' 灰色字public const ods_disabled = &h4                     ' 禁止使用public const ods_checked = &h8                      ' 选中public const ods_focus = &h10                       ' 聚焦

' diflags to drawiconexpublic const di_mask = &h1                          ' 画图时运用图目标mask局部 (如独立运用, 可赢得图目标掩模)public const di_image = &h2                         ' 画图时运用图目标xor局部 (即图标没有通明地区)public const di_normal = di_mask or di_image        ' 用惯例办法画图 (兼并 di_image 和 di_mask)

' nbkmode to setbkmodepublic const transparent = 1                        ' 通明处置, 即不作上述弥补public const opaque = 2                             ' 用暂时的背局面弥补虚线画笔、暗影刷子以及字符的间隙public const newtransparent = 3                     ' 在有脸色的菜单上画通明笔墨

' 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 = &h1000public const mf_rightjustify = &h4000

' fmask to insertmenuitem                           ' 指定 menuiteminfo 中哪些分子灵验public const miim_state = &h1public const miim_id = &h2public const miim_submenu = &h4public const miim_checkmarks = &h8public const miim_type = &h10public const miim_data = &h20public const miim_string = &h40public const miim_bitmap = &h80public const miim_ftype = &h100

' ftype to insertmenuitem                           ' menuiteminfo 中菜单项典型public const mft_bitmap = &h4&public const mft_menubarbreak = &h20&public const mft_menubreak = &h40&public const mft_ownerdraw = &h100&public const mft_separator = &h800&public const mft_string = &h0&

' fstate to insertmenuitem                          ' menuiteminfo 中菜单项状况public const mfs_checked = &h8&public const mfs_disabled = &h2&public const mfs_enabled = &h0&public const mfs_grayed = &h1&public const mfs_hilite = &h80&public const mfs_unchecked = &h0&public const mfs_unhilite = &h0&

' nformat to drawtextpublic const dt_left = &h0                          ' 程度左对齐public const dt_center = &h1                        ' 程度居中对齐public const dt_right = &h2                         ' 程度右对齐

public const dt_singleline = &h20                   ' 单列

public const dt_top = &h0                           ' 笔直上对齐 (仅单列时灵验)public const dt_vcenter = &h4                       ' 笔直居中对齐 (仅单列时灵验)public const dt_bottom = &h8                        ' 笔直下对齐 (仅单列时灵验)

public const dt_calcrect = &h400                    ' 多行画图时矩形的底边按照须要举行延长, 再不容下一切笔墨; 单列画图时, 延长矩形的右侧, 不刻画笔墨, 由lprect参数指定的矩形会载入计划出来的值.public const dt_wordbreak = &h10                    ' 举行机动换行. 如用settextalign因变量树立了ta_updatecp标记, 这边的树立则失效.

public const dt_noclip = &h100                      ' 刻画笔墨时不剪切到指定的矩形public const dt_noprefix = &h800                    ' 常常, 因变量觉得 & 字符表白应为下一个字符加左右划线, 该标记遏止这种动作.

public const dt_expandtabs = &h40                   ' 刻画笔墨的功夫, 对构图站举行扩充. 默许的构图站间距是8个字符. 然而, 可用dt_tabstop标记变换这项设定.public const dt_tabstop = &h80                      ' 指定新的构图站间距, 沿用这个平头的高 8 位.public const dt_externalleading = &h200             ' 计划文本行莫大的功夫, 运用暂时字体的外部间距属性.

' nindex to getsyscolor  规范: 0--20public const color_activeborder = 10                ' 震动窗口的边框public const color_activecaption = 2                ' 震动窗口的题目public const color_appworkspace = 12                ' mdi桌面包车型的士后台public const color_background = 1                   ' windows 桌面public const color_btnface = 15                     ' 按钮public const color_btnhighlight = 20                ' 按钮的3d加亮区public const color_btnshadow = 16                   ' 按钮的3d暗影public const color_btntext = 18                     ' 按钮笔墨public const color_captiontext = 9                  ' 窗口题目中的笔墨public const color_graytext = 17                    ' 灰色笔墨; 如运用了颤动本领则为零public const color_highlight = 13                   ' 选定的名目后台public const color_highlighttext = 14               ' 选定的名目笔墨public const color_inactiveborder = 11              ' 不震动窗口的边框public const color_inactivecaption = 3              ' 不震动窗口的题目public const color_inactivecaptiontext = 19         ' 不震动窗口的笔墨public const color_menu = 4                         ' 菜单public const color_menutext = 7                     ' 菜单笔墨public const color_scrollbar = 0                    ' 震动条public const color_window = 5                       ' 窗口后台public const color_windowframe = 6                  ' 窗棂public const color_windowtext = 8                   ' 窗口笔墨

' un to drawstatepublic const dst_complex = &h0                      ' 画图在由lpdrawstateproc参数指定的回调因变量功夫实行, lparam和wparam会传播给回调事变.public const dst_text = &h1                         ' lparam代办笔墨的地方(可运用一个字串别号),wparam代办字串的长度.public const dst_prefixtext = &h2                   ' 与dst_text一致, 不过 & 字符指出为下各字符加左右划线.public const dst_icon = &h3                         ' lparam囊括图目标句柄public const dst_bitmap = &h4                       ' lparam囊括位图的句柄public const dss_normal = &h0                       ' 普遍图像public const dss_union = &h10                       ' 图像举行颤动处置public const dss_disabled = &h20                    ' 图象具备浮雕功效public const dss_mono = &h80                        ' 用hbrush刻画图像public const dss_right = &h8000                     ' 无任何效率

' edge to drawedgepublic const bdr_raisedouter = &h1                  ' 外层凸public const bdr_sunkenouter = &h2                  ' 外层凹public const bdr_raisedinner = &h4                  ' 内层凸public const bdr_sunkeninner = &h8                  ' 内层凹public const bdr_outer = &h3public const bdr_raised = &h5public const bdr_sunken = &hapublic const bdr_inner = &hcpublic const edge_bump = (bdr_raisedouter or bdr_sunkeninner)public const edge_etched = (bdr_sunkenouter or bdr_raisedinner)public const edge_raised = (bdr_raisedouter or bdr_raisedinner)public const edge_sunken = (bdr_sunkenouter or bdr_sunkeninner)

' grfflags to drawedgepublic const bf_left = &h1                          ' 左边际public const bf_top = &h2                           ' 上边际public const bf_right = &h4                         ' 右边际public const bf_bottom = &h8                        ' 下边际public const bf_diagonal = &h10                     ' 对角线public const bf_middle = &h800                      ' 弥补矩形里面public const bf_soft = &h1000                       ' msdn: soft buttons instead of tiles.public const bf_adjust = &h2000                     ' 安排矩形, 预留存户区public const bf_flat = &h4000                       ' 平面边际public const bf_mono = &h8000                       ' 一维边际

public const bf_rect = (bf_left or bf_top or bf_right or bf_bottom)public const bf_topleft = (bf_top or bf_left)public const bf_topright = (bf_top or bf_right)public const bf_bottomleft = (bf_bottom or bf_left)public const bf_bottomright = (bf_bottom or bf_right)public const bf_diagonal_endtopleft = (bf_diagonal or bf_top or bf_left)public const bf_diagonal_endtopright = (bf_diagonal or bf_top or bf_right)public const bf_diagonal_endbottomleft = (bf_diagonal or bf_bottom or bf_left)public const bf_diagonal_endbottomright = (bf_diagonal or bf_bottom or bf_right)

' npenstyle to createpenpublic const ps_dash = 1                            ' 画笔典型:虚线 (nwidth必需是1)         -------public const ps_dashdot = 3                         ' 画笔典型:点划线 (nwidth必需是1)       _._._._public const ps_dashdotdot = 4                      ' 画笔典型:点-点-划线 (nwidth必需是1)   _.._.._public const ps_dot = 2                             ' 画笔典型:点线 (nwidth必需是1)         .......public const ps_solid = 0                           ' 画笔典型:实线                         _______

' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- api 典型证明 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

public type rect    left as long    top as long    right as long    bottom as longend type

public type drawitemstruct    ctltype as long    ctlid as long    itemid as long    itemaction as long    itemstate as long    hwnditem as long    hdc as long    rcitem as rect    itemdata as longend type

public 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    cch as longend type

public type measureitemstruct    ctltype as long    ctlid as long    itemid as long    itemwidth as long    itemheight as long    itemdata as longend type

public type size    cx as long    cy as longend type

' 自设置菜单项数据构造public type mymenuiteminfo    itemicon as stdpicture    itemalias as string    itemtext as string    itemtype as menuitemtype    itemstate as menuitemstateend type

' 菜单关系构造private measureinfo as measureitemstructprivate drawinfo as drawitemstruct

public hmenu as longpublic premenuwndproc as longpublic myiteminfo() as mymenuiteminfo

' 菜单类属性public barwidth as long                             ' 菜单附加条宽窄public barstyle as menuleftbarstyle                 ' 菜单附加条作风public barimage as stdpicture                       ' 菜单附加条图像public barstartcolor as long                        ' 菜单附加条过度色开始脸色public barendcolor as long                          ' 菜单附加条过度色中断脸色public selectscope as menuitemselectscope           ' 菜单项高亮条的范畴public textenabledcolor as long                     ' 菜单项可用时笔墨脸色public textdisabledcolor as long                    ' 菜单项不行用时笔墨脸色public textselectcolor as long                      ' 菜单项选中时笔墨脸色public iconstyle as menuitemiconstyle               ' 菜单项图标作风public edgestyle as menuitemselectedgestyle         ' 菜单项边框作风public edgecolor as long                            ' 菜单项边框脸色public fillstyle as menuitemselectfillstyle         ' 菜单项后台弥补作风public fillstartcolor as long                       ' 菜单项过度色开始脸色public fillendcolor as long                         ' 菜单项过度色中断脸色public bkcolor as long                              ' 菜单后台脸色public sepstyle as menuseparatorstyle               ' 菜单分割条作风public sepcolor as long                             ' 菜单分割条脸色public menustyle as menuuserstyle                   ' 菜单总体作风

 

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.