View Single Post
  #33   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Hi Peter,

Like Tom O, I think minimizing a modal userform doesn't really serve much
purpose.
I am sure though with some tinkering it can work, but don't think it is
worth the trouble.

Bart

"Peter T" <peter_t@discussions wrote in message
...
Hi Bart,

Would be interested if anybody could tell me how to make this work

properly
with a normal modal userform.


Lightly tested, to allow modeless use while the modal form is minimized

Replace all code in your normal module with following (userform code
as-was)

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong _
Lib "user32" Alias _
"SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function ShowWindow _
Lib "user32" (ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long
Private Declare Function IsIconic Lib "user32" (ByVal hWnd As Long) _
As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Declare Function FindWindowA Lib "user32" (ByVal _
lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function EnableWindow Lib "user32" (ByVal _
hWnd As Long, ByVal bEnable As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal _
hWnd As Long) As Long


Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = -16

Sub LoadFormModal()

Load UserForm1
AddMinMax
UserForm1.Show vbModal

End Sub

Sub AddMinMax()

Dim hWnd As Long
Dim lngStyle As Long

hWnd = UserForm1.propFormHwnd

lngStyle = GetWindowLong(hWnd, GWL_STYLE)
lngStyle = lngStyle Or WS_MAXIMIZEBOX
lngStyle = lngStyle Or WS_MINIMIZEBOX

SetWindowLong hWnd, GWL_STYLE, lngStyle
DrawMenuBar hWnd

End Sub

Sub SetMinimize(Optional bNormal As Boolean)

Dim hWnd As Long

hWnd = UserForm1.propFormHwnd

If IsIconic(hWnd) Then
ShowWindow hWnd, 0
SetWindowLong hWnd, -20, &H40101
ShowWindow hWnd, 6
ChangeMode 1&

Else
ChangeMode 0
If bNormal Then
ShowWindow hWnd, 0
SetWindowLong hWnd, -20, &H40101
ShowWindow hWnd, 1
End If
End If

End Sub

Sub ChangeMode(mode As Long)
Dim appWin As Long

appWin = FindWindowA("XLMAIN", Application.Caption)
EnableWindow appWin, mode
If mode = 1 Then
SetForegroundWindow appWin
End If

End Sub

Seems to work but not sure why the slight difference between first &
subsequent minimize actions.

Regards,
Peter T