V
VBA Coder
Has anyone had any success using the AppendMenu API function to add the
Minimize and Maximize button to a Word Form title bar? My sample code is
below which does not seem to add anything.
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal
hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal
lpNewItem As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long)
As Long
' Window styles constants
Private Const WS_MINIMIZEBOX As Long = &H20000 'Style to add a Minimize
box on the title bar
Private Const WS_MAXIMIZEBOX As Long = &H10000 'Style to add a Maximize
box to the title bar
Public Function ShowMinMaxButtons(sTitle As String)
Dim sClass As String
Dim lAppHandle As Long
Dim hWndForm As Long
' Get the Handle to the Form that we want to add the button to. Use the
Caption of the Form (sTitle).
hWndForm = FindWindow(vbNullString, sTitle)
If hWndForm = 0 Then Exit Function
' Get the Class Name of the Window Handle
sClass = sClassName(hWndForm)
lAppHandle = FindWindow(sClass, vbNullString)
AppendMenu hWndForm, WS_MINIMIZEBOX , 1, "Minimze"
AppendMenu hWndForm, WS_MAXIMIZEBOX , 2, "Maximize"
End Function
Public Function sClassName(ByVal hWindow As Long) As String
Dim lLen As Long
Dim sClass As String * 128
lLen = GetClassName(hWindow, sClass, 127)
If lLen Then
sClassName = Left$(sClass, lLen)
Else
sClassName = ""
End If
End Function
Minimize and Maximize button to a Word Form title bar? My sample code is
below which does not seem to add anything.
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal
hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal
lpNewItem As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long)
As Long
' Window styles constants
Private Const WS_MINIMIZEBOX As Long = &H20000 'Style to add a Minimize
box on the title bar
Private Const WS_MAXIMIZEBOX As Long = &H10000 'Style to add a Maximize
box to the title bar
Public Function ShowMinMaxButtons(sTitle As String)
Dim sClass As String
Dim lAppHandle As Long
Dim hWndForm As Long
' Get the Handle to the Form that we want to add the button to. Use the
Caption of the Form (sTitle).
hWndForm = FindWindow(vbNullString, sTitle)
If hWndForm = 0 Then Exit Function
' Get the Class Name of the Window Handle
sClass = sClassName(hWndForm)
lAppHandle = FindWindow(sClass, vbNullString)
AppendMenu hWndForm, WS_MINIMIZEBOX , 1, "Minimze"
AppendMenu hWndForm, WS_MAXIMIZEBOX , 2, "Maximize"
End Function
Public Function sClassName(ByVal hWindow As Long) As String
Dim lLen As Long
Dim sClass As String * 128
lLen = GetClassName(hWindow, sClass, 127)
If lLen Then
sClassName = Left$(sClass, lLen)
Else
sClassName = ""
End If
End Function