• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

vb实现菜单右对齐

发布: 2007-7-14 20:28 | 作者: 佚名    | 来源: 网络转载     | 查看: 8次 | 进入软件测试论坛讨论

领测软件测试网 传统的窗口菜单都是左对齐,是否可以右对齐,或窗口菜单左右分开呢?

当然可以!

新建一个工程,添加菜单(本例需要3列),添加四个按钮控件,一个时间控件

添加以下代码:

Option Explicit

Private 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 Long

End Type

Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal

bool As Boolean, lpcMenuItemInfo As menuItemInfo) As Long
Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal

b As Long, lpMenuItemInfo As menuItemInfo) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Public a As Integer

Private Sub Command1_Click()

Unload Me
Me.Show

Dim my_menuItemInfo As menuItemInfo
Dim return_value As Long

With my_menuItemInfo

.cbSize = 44
.fMask = 16
.cch = 128
.dwTypeData = Space$(128)

End With

return_value = GetMenuItemInfo(GetMenu(Me.hwnd), 3, 1, my_menuItemInfo)

my_menuItemInfo.fType = 16384
return_value = SetMenuItemInfo(GetMenu(Me.hwnd), 3, 1, my_menuItemInfo)

DrawMenuBar GetMenu(Me.hwnd)
Me.Refresh
Me.WindowState = 1
End Sub

Private Sub Command2_Click()

Dim my_menuItemInfo As menuItemInfo
Dim return_value As Long

With my_menuItemInfo

.cbSize = 44
.fMask = 16
.cch = 128
.dwTypeData = Space$(128)

End With

return_value = GetMenuItemInfo(GetMenu(Me.hwnd), 0, 1, my_menuItemInfo)

my_menuItemInfo.fType = 16384
return_value = SetMenuItemInfo(GetMenu(Me.hwnd), 0, 1, my_menuItemInfo)

DrawMenuBar GetMenu(Me.hwnd)
Me.Refresh
Me.WindowState = 1
End Sub

Private Sub Command3_Click()
Unload Me
Me.Show
Dim my_menuItemInfo As menuItemInfo
Dim return_value As Long

With my_menuItemInfo

.cbSize = 44
.fMask = 16
.cch = 128
.dwTypeData = Space$(128)

End With

return_value = GetMenuItemInfo(GetMenu(Me.hwnd), 1, 1, my_menuItemInfo)

my_menuItemInfo.fType = 16384
return_value = SetMenuItemInfo(GetMenu(Me.hwnd), 1, 1, my_menuItemInfo)

DrawMenuBar GetMenu(Me.hwnd)
Me.Refresh
Me.WindowState = 1

End Sub

Private Sub Command4_Click()
Unload Me
Me.Show


Dim my_menuItemInfo As menuItemInfo
Dim return_value As Long

With my_menuItemInfo

.cbSize = 44
.fMask = 16
.cch = 128
.dwTypeData = Space$(128)

End With

return_value = GetMenuItemInfo(GetMenu(Me.hwnd), 2, 1, my_menuItemInfo)

my_menuItemInfo.fType = 16384
return_value = SetMenuItemInfo(GetMenu(Me.hwnd), 2, 1, my_menuItemInfo)

DrawMenuBar GetMenu(Me.hwnd)
Me.Refresh
Me.WindowState = 1

End Sub



Private Sub Timer1_Timer()

If Me.WindowState = 1 Then Me.WindowState = 0

End Sub

运行一下,如何?

注意四个按钮不同的一个参数,那表示左边有几个菜单项

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网