Public Declare Function GetSystemMenu Lib "User32.dll" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function GetMenuItemInfo Lib "User32.dll" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal B As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
Public Declare Function SetMenuItemInfo Lib "User32.dll" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
Public Declare Function SendMessage Lib "User32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'構造体定義
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 Long
End Type
Public MenuType As MENUITEMINFO
Public hMenu As Long 'メニューハンドル
Public Const xSC_CLOSE As Long = -10
Public Const SwapID As Long = 1
Public Const ResetID As Long = 2
Public Const SC_CLOSE As Long = &HF060&
Public Const Menu_STATE As Long = &H1&
Public Const Menu_ID As Long = &H2&
Public Const MFS_GRAYED As Long = &H3&
Public Const WM_NCACTIVATE As Long = &H86
Sub PgmInit()
Dim Ret As Long
hMenu = GetSystemMenu(Main_Form.hwnd, 0)
With MenuType
.cbSize = Len(MenuType)
.dwTypeData = String(80, 0)
.cch = Len(.dwTypeData)
.fMask = Menu_STATE
.wID = SC_CLOSE
End With
Ret = GetMenuItemInfo(hMenu, MenuType.wID, False, MenuType)
End Sub
Sub Enabled_Proc(ByVal pFlg As Boolean)
Dim Ret As Long
Ret = SetId(SwapID)
If pFlg = False Then
MenuType.fState = (MenuType.fState Or MFS_GRAYED)
Else
MenuType.fState = MenuType.fState - MFS_GRAYED
End If
MenuType.fMask = Menu_STATE
Ret = SetMenuItemInfo(hMenu, MenuType.wID, False, MenuType)
If Ret = 0 Then
Ret = SetId(ResetID)
End If
Ret = SendMessage(Main_Form.hwnd, WM_NCACTIVATE, True, 0)
End Sub
Private Function SetId(Act As Long) As Long
Dim MenuID As Long
Dim Ret As Long
With MenuType
MenuID = .wID
If .fState = (.fState Or MFS_GRAYED) Then
If Act = SwapID Then
.wID = SC_CLOSE
Else
.wID = xSC_CLOSE
End If
Else
If Act = SwapID Then
.wID = xSC_CLOSE
Else
.wID = SC_CLOSE
End If
End If
.fMask = Menu_ID
Ret = SetMenuItemInfo(hMenu, MenuID, False, MenuType)
If Ret = 0 Then
.wID = MenuID
End If
End With
SetId = Ret
End Function
|