• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 25 رای - 2.88 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: ساخت منوهای چند ستونی
حالت موضوعی
#1
Lightbulb 
س !!!!!!!!!! دوستان خسته نباشید!!!!!!!!!!!!
هنگامی که تعداد منو ها زیاد است و ممکن است از صفحه اصلی برنامه بیرون بزند، استفاده از منوهای چند ستونی کار بسیار مفیدی است.
VB خود تابعی برای این کار ندارد اما با Api ها می توان چنین کاری کرد.

روش ساخت منوهای چند ستونی:
1- یک پروژه جدید ایجاد کنید.
2- یک CommandButton به فرم اضافه کنید.
3- با استفاده از Menu Editor، دو منو ایجاد کنید و برای هر منو چهار زیر منو انتخاب کنید.
4- کدهای زیر را در قسمت General فرم وارد کنید:
کد:
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 Const MF_MENUBARBREAK = &H20& ' columns with a separator line
Private Const MF_MENUBREAK = &H40& ' columns w/o a separator line
Private Const MF_STRING = &H0&
Private Const MF_HELP = &H4000&
Private Const MFS_DEFAULT = &H1000&
Private Const MIIM_ID = &H2
Private Const MIIM_SUBMENU = &H4
Private Const MIIM_TYPE = &H10
Private Const MIIM_DATA = &H20
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" _
Alias "GetMenuItemInfoA" _
(ByVal hMenu As Long, ByVal un As Long, ByVal B As Boolean, _
lpMenuItemInfo As MENUITEMINFO) As Long
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 DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Sub Command1_Click()
' Splitting a menu here demonstrates that this can be done dynamically.
Dim mnuItemInfo As MENUITEMINFO, hMenu As Long, hSubMenu As Long
Dim BuffStr As String * 80 ' Define as largest possible menu text.
hMenu = GetMenu(Me.hwnd) ' retrieve menu handle.
BuffStr = Space(80)
With mnuItemInfo ' Initialize the UDT.
.cbSize = Len(mnuItemInfo) ' 44
.dwTypeData = BuffStr & Chr(0)
.fType = MF_STRING
.cch = Len(mnuItemInfo.dwTypeData) ' 80
.fState = MFS_DEFAULT
.fMask = MIIM_ID Or MIIM_DATA Or MIIM_TYPE Or MIIM_SUBMENU
End With
' Use item break point position for the '3' below (zero-based list).
hSubMenu = GetSubMenu(hMenu, 0)
If GetMenuItemInfo(hSubMenu, 2, True, mnuItemInfo) = 0 Then
MsgBox "GetMenuItemInfo failed. Error: " & Err.LastDllError, , _
"Error"
Else
mnuItemInfo.fType = mnuItemInfo.fType Or MF_MENUBARBREAK
If SetMenuItemInfo(hSubMenu, 2, True, mnuItemInfo) = 0 Then
MsgBox "SetMenuItemInfo failed. Error: " & Err.LastDllError, , _
"Error"
End If
End If
DrawMenuBar (Me.hwnd) ' Repaint top level Menu.
End Sub
Private Sub Form_Load()
' This works for either an API-created menu or a native VB Menu.
Dim mnuItemInfo As MENUITEMINFO, hMenu As Long, hSubMenu As Long
Dim BuffStr As String * 80 ' Define as largest possible menu text.
hMenu = GetMenu(Me.hwnd) ' Retrieve menu handle.
BuffStr = Space(80)
With mnuItemInfo ' Initialize the UDT
.cbSize = Len(mnuItemInfo) ' 44
.dwTypeData = BuffStr & Chr(0)
.fType = MF_STRING
.cch = Len(mnuItemInfo.dwTypeData) ' 80
.fState = MFS_DEFAULT
.fMask = MIIM_ID Or MIIM_DATA Or MIIM_TYPE Or MIIM_SUBMENU
End With
' Use item break point position for the '3' below (zero-based list).
hSubMenu = GetSubMenu(hMenu, 1)
If GetMenuItemInfo(hSubMenu, 2, True, mnuItemInfo) = 0 Then
MsgBox "GetMenuItemInfo failed. Error: " & Err.LastDllError, , _
"Error"
Else
mnuItemInfo.fType = mnuItemInfo.fType Or MF_MENUBREAK
If SetMenuItemInfo(hSubMenu, 2, True, mnuItemInfo) = 0 Then
MsgBox "SetMenuItemInfo failed. Error: " & Err.LastDllError, , _
"Error"
End If
End If
DrawMenuBar (Me.hwnd) ' Repaint top level Menu.
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
If Button = vbRightButton Then
PopupMenu saf ' Use the name of one of your menus.
End If
End Sub
5- عبارت "Aaa" را در آخرین کد (در بخش Form_MouseDown) به نام یکی از منوهای اصلی تغییر دهید.

خب
حال اگر برنامه را اجرا کنید و روی منو ها کلیک کنید هیچ تغییری را مشاهده
نمی کنید. اما اگر روی CommandButton کلیک کنید سپس روی منو ها کلیک کنید،
تغییر را مشاهده خواهید کرد.

(برای اطلاعات بیشتر و اطلاعات مفید در مورد منو ها به کتاب "کار با منو ها" که از سایت "Parsbook" قابل دانلود است، مراجعه نمایید.)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
:::::::::::::::::::::::::   دیگه میرم ...   :::::::::::::::::::::::::

 
پاسخ
  


موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
  دانلود فایل اکسس برای ساخت دیکشنری sajad-kh 0 4,912 01-28-2014، 01:24 PM
آخرین ارسال: sajad-kh
  آموزش ساخت اسپمر تبلیغاتی برای بلاگفا Amin_Mansouri 14 22,678 12-27-2013، 08:46 PM
آخرین ارسال: SnipeR
  ساخت برنامه پرتابل از برنامه های نوشته شده sajad-kh 2 4,293 09-15-2013، 06:14 AM
آخرین ارسال: Amin_Mansouri
  ساخت shortcut gachboy 1 3,448 02-11-2013، 10:47 AM
آخرین ارسال: Amin_Mansouri
Photo کمک برای ساخت نرم افزار amolhackers 7 8,194 01-19-2013، 11:19 PM
آخرین ارسال: amolhackers
  ساخت نوشته 3D در VB 6 Thewolf 0 2,384 06-20-2012، 07:35 PM
آخرین ارسال: Thewolf
  ساخت MsgBox دلخواه با VB 6 Thewolf 0 2,691 06-16-2012، 03:33 PM
آخرین ارسال: Thewolf
  طریقه ساخت لیبل هایپرلینک(ویژوال یسیک 6) Amin_Mansouri 1 5,147 06-12-2012، 11:40 PM
آخرین ارسال: Amin_Mansouri
  ساخت فایل EXE در ویبی 2005 keyhanifar 2 4,528 06-03-2012، 10:49 PM
آخرین ارسال: Ghoghnus
  سورس کد ساخت فایل پی دی اف با ویژوال بیسیک 6 Amin_Mansouri 0 6,008 01-05-2012، 05:18 PM
آخرین ارسال: Amin_Mansouri

پرش به انجمن:


Browsing: 1 مهمان