Hello,
I got the following code to maximize, minimize and resize the form, but it didn't work well, every time I ran it, I got a popup msg "Sub or Function not defined" and highlight "GetWindowLong"
Note: I have 64bit system, so I added "PtrSafe" to the "Private Declare Function" but keep getting the same error above
Please, help me fixing this issue and let me know if I can add all this code to a module and just Call it from each form, because I have a lot of forms and lot of codes on my project, and don't need to add it to all of them
Many thanks in advanced
[TABLE="width: 800"]
<tbody>[TR]
[TD]Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function GetWindow Lib "user32" Alias "GetWindowA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindow Lib "user32" Alias "SetWindowA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_THICKFRAME As Long = &H40000
Const MIN_BOX As Long = &H20000
Const MAC_BOX As Long = &H10000
Private Declare PtrSafe Function DrawMenuBar Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare PtrSafe Function GetForegroundWindow Lib "user32.dll" () As Long
Public Sub AddToForm(ByVal Box_Type As Long)
Dim BisMask As Long
Dim Window_Handle As Long
Dim WindowStyle As Long
Dim Ret As Long
If Box_Type = MIN_BOX Or Box_Type = MAX_BOX Then
Window_Handle = GetForegroundWindow()
WindowStyle = GetWindowLong(Window_Handle, GWL_STYLE)
BisMask = WindowStyle Or Box_Type
Ret = SetWindowLong(Window_Handle, GWL_STYLE, BisMask)
Ret = DrawMenuBar(Window_Handle)
End If
End Sub
Private Sub UserForm_Activate()
Call AddToForm(MIN_BOX)
Call AddToForm(MAX_BOX)
End Sub
Sub Resize()
Dim hWndForm As Long
Dim istyle As Long
If Val(Application.Version) < 9 Then
hWndForm = FindWindow("ThunderXFrame", Me.Caption)
Else
hWndForm = FindWindow("ThunderDFrame", Me.Caption)
End If
istyle = GetWindowLong(hWndForm, GWL_STYLE)
istyle = istyle Or WS_THICKFRAME
Call SetWindowLong(hWndForm, GWL_STYLE, istyle)
End Sub
Private Sub UserForm_Initialize()
Call Resize
End Sub
[/TD]
[/TR]
</tbody>[/TABLE]
I got the following code to maximize, minimize and resize the form, but it didn't work well, every time I ran it, I got a popup msg "Sub or Function not defined" and highlight "GetWindowLong"
Note: I have 64bit system, so I added "PtrSafe" to the "Private Declare Function" but keep getting the same error above
Please, help me fixing this issue and let me know if I can add all this code to a module and just Call it from each form, because I have a lot of forms and lot of codes on my project, and don't need to add it to all of them
Many thanks in advanced
[TABLE="width: 800"]
<tbody>[TR]
[TD]Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function GetWindow Lib "user32" Alias "GetWindowA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindow Lib "user32" Alias "SetWindowA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_THICKFRAME As Long = &H40000
Const MIN_BOX As Long = &H20000
Const MAC_BOX As Long = &H10000
Private Declare PtrSafe Function DrawMenuBar Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare PtrSafe Function GetForegroundWindow Lib "user32.dll" () As Long
Public Sub AddToForm(ByVal Box_Type As Long)
Dim BisMask As Long
Dim Window_Handle As Long
Dim WindowStyle As Long
Dim Ret As Long
If Box_Type = MIN_BOX Or Box_Type = MAX_BOX Then
Window_Handle = GetForegroundWindow()
WindowStyle = GetWindowLong(Window_Handle, GWL_STYLE)
BisMask = WindowStyle Or Box_Type
Ret = SetWindowLong(Window_Handle, GWL_STYLE, BisMask)
Ret = DrawMenuBar(Window_Handle)
End If
End Sub
Private Sub UserForm_Activate()
Call AddToForm(MIN_BOX)
Call AddToForm(MAX_BOX)
End Sub
Sub Resize()
Dim hWndForm As Long
Dim istyle As Long
If Val(Application.Version) < 9 Then
hWndForm = FindWindow("ThunderXFrame", Me.Caption)
Else
hWndForm = FindWindow("ThunderDFrame", Me.Caption)
End If
istyle = GetWindowLong(hWndForm, GWL_STYLE)
istyle = istyle Or WS_THICKFRAME
Call SetWindowLong(hWndForm, GWL_STYLE, istyle)
End Sub
Private Sub UserForm_Initialize()
Call Resize
End Sub
[/TD]
[/TR]
</tbody>[/TABLE]