-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMenuHelper.bas
More file actions
83 lines (61 loc) · 2.49 KB
/
MenuHelper.bas
File metadata and controls
83 lines (61 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Attribute VB_Name = "MenuHelper"
'--------------------------------------------------------------------------------
' Component : MenuHelper
' Project : ViDock
'
' Description: [type_description_here]
'
'--------------------------------------------------------------------------------
Option Explicit
Public Function CreateSystemMenu(ByVal hMenu As Long, _
ByVal WindowState As FormWindowStateConstants) As clsMenu
Dim itemCount As Long
Dim objNewMenu As New clsMenu
Dim itemIndex As Long
Dim itemID As Long
Dim bufferString As String
Dim itemLength As Long
Dim itemState As Long
Dim menuDefault As Long
itemCount = GetMenuItemCount(hMenu)
For itemIndex = 0 To itemCount - 1
itemLength = GetMenuString(hMenu, itemIndex, ByVal 0, 0, MF_BYPOSITION) + 1
bufferString = String(itemLength, 0)
itemState = GetMenuState(hMenu, itemIndex, MF_BYPOSITION)
itemID = GetMenuItemID(hMenu, itemIndex)
GetMenuString hMenu, itemIndex, bufferString, itemLength, MF_BYPOSITION
If WindowState = vbNormal Then
If itemID = SC_RESTORE Then
itemState = MF_GRAYED Or MF_STRING
ElseIf itemID = SC_CLOSE Then
menuDefault = itemID
End If
ElseIf WindowState = vbMinimized Then
If itemID = SC_MOVE Then
itemState = MF_GRAYED Or MF_STRING
ElseIf itemID = SC_SIZE Then
itemState = MF_GRAYED Or MF_STRING
ElseIf itemID = SC_MINIMIZE Then
itemState = MF_GRAYED Or MF_STRING
ElseIf itemID = SC_RESTORE Then
itemState = MF_STRING
menuDefault = itemID
ElseIf itemID = SC_MAXIMIZE Then
itemState = MF_STRING
End If
ElseIf WindowState = vbMaximized Then
If itemID = SC_MAXIMIZE Then
itemState = MF_GRAYED Or MF_STRING
ElseIf itemID = SC_MOVE Then
itemState = MF_GRAYED Or MF_STRING
ElseIf itemID = SC_SIZE Then
itemState = MF_GRAYED Or MF_STRING
End If
End If
AppendMenu objNewMenu.Handle, itemState, itemID, bufferString
If itemID = menuDefault Then
SetMenuDefaultItem objNewMenu.Handle, itemIndex, True
End If
Next
Set CreateSystemMenu = objNewMenu
End Function