Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Minimize Maximize buttons

How to add Minimize and Maximize/Restore Down buttons to a user form?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Minimize Maximize buttons

Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:

How to add Minimize and Maximize/Restore Down buttons to a user form?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Minimize Maximize buttons

Tom,

Thanks very much. The FormFun is very interesting. But the codes are too
complicated for me to adopt. I just want to have the bottons on the form once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:

Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:

How to add Minimize and Maximize/Restore Down buttons to a user form?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes are too
complicated for me to adopt. I just want to have the bottons on the form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:

Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:

How to add Minimize and Maximize/Restore Down buttons to a user form?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Minimize Maximize buttons

Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes are too
complicated for me to adopt. I just want to have the bottons on the form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:

Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:

How to add Minimize and Maximize/Restore Down buttons to a user form?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

If you can show the relevant code I might be able to tell you where you went
wrong.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes are
too
complicated for me to adopt. I just want to have the bottons on the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:

Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:

How to add Minimize and Maximize/Restore Down buttons to a user
form?




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes are
too
complicated for me to adopt. I just want to have the bottons on the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:

Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:

How to add Minimize and Maximize/Restore Down buttons to a user
form?




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Minimize Maximize buttons

RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:

If you can show the relevant code I might be able to tell you where you went
wrong.

RBS

"Scott" wrote in message
...

Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on my
UserForm1.

"RB Smissaert" wrote:


This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...


Tom,

Thanks very much. The FormFun is very interesting. But the codes are
too
complicated for me to adopt. I just want to have the bottons on the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:


Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:


How to add Minimize and Maximize/Restore Down buttons to a user
form?




  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Simple, in your WorkBook_Open code do instead:

Load frmMainUser
frmMainUser.Show 0

AddMinMax frmMainUser.Caption

The declarations and the Sub AddMinMax will have to go to a normal Module.
Keep all the declarations just as they are, no need to make the declarations
Public.

RBS

"Jim May" wrote in message
news:cKLrg.97413$IZ2.41690@dukeread07...
RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:

If you can show the relevant code I might be able to tell you where you
went
wrong.

RBS

"Scott" wrote in message
...

Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on
my
UserForm1.

"RB Smissaert" wrote:


This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...


Tom,

Thanks very much. The FormFun is very interesting. But the codes are
too
complicated for me to adopt. I just want to have the bottons on the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:


Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:


How to add Minimize and Maximize/Restore Down buttons to a user
form?





  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Minimize Maximize buttons

I think I got it, but When I open my Workbook, I get
Compile error - Only Comments may apprear after End Sub,
End Funtion or End Property The Declaration- Code seems
To be the culprit - am I missing the End Function line
After each Public Declare Function (Lines)?



"RB Smissaert" wrote in message
:

Simple, in your WorkBook_Open code do instead:

Load frmMainUser
frmMainUser.Show 0

AddMinMax frmMainUser.Caption

The declarations and the Sub AddMinMax will have to go to a normal Module.
Keep all the declarations just as they are, no need to make the declarations
Public.

RBS

"Jim May" wrote in message
news:cKLrg.97413$IZ2.41690@dukeread07...

RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:


If you can show the relevant code I might be able to tell you where you
went
wrong.

RBS

"Scott" wrote in message
...


Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on
my
UserForm1.

"RB Smissaert" wrote:



This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...


Tom,

Thanks very much. The FormFun is very interesting. But the codes are
too
complicated for me to adopt. I just want to have the bottons on the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:



Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:



How to add Minimize and Maximize/Restore Down buttons to a user
form?








  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Maybe the linebreaks messed it up.
Does it compile OK? This goes with:
Debug, Compile VBAProject.

am I missing the End Function line after each Public Declare Function
(Lines)?


No, there is no such thing as End Function for declarations.

This the same declaration section, but made a bit narrower:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
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)

Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String


RBS


"Jim May" wrote in message
news:1eMrg.97414$IZ2.13653@dukeread07...
I think I got it, but When I open my Workbook, I get
Compile error - Only Comments may apprear after End Sub,
End Funtion or End Property The Declaration- Code seems
To be the culprit - am I missing the End Function line
After each Public Declare Function (Lines)?



"RB Smissaert" wrote in message
:

Simple, in your WorkBook_Open code do instead:

Load frmMainUser
frmMainUser.Show 0

AddMinMax frmMainUser.Caption

The declarations and the Sub AddMinMax will have to go to a normal
Module.
Keep all the declarations just as they are, no need to make the
declarations
Public.

RBS

"Jim May" wrote in message
news:cKLrg.97413$IZ2.41690@dukeread07...

RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to
False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:


If you can show the relevant code I might be able to tell you where
you
went
wrong.

RBS

"Scott" wrote in message
...


Thanks for the help.

I copied your codes to my file, but I still did not get the buttons
on
my
UserForm1.

"RB Smissaert" wrote:



This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...


Tom,

Thanks very much. The FormFun is very interesting. But the codes
are
too
complicated for me to adopt. I just want to have the bottons on
the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:



Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:



How to add Minimize and Maximize/Restore Down buttons to a
user
form?







  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Minimize Maximize buttons

RB,
Got it!!
One last Q;
My Userform on Load (Wb Open) comes up partial screen (3 X 5)
When I minimize it, then Restore it comes up Full screen (7 X 10, say)
Can this aspect be controlled to where the Restore could re-produce
The 3 X 5 Size?
Really do appreciate your help on this.
Jim

"RB Smissaert" wrote in message
:

Maybe the linebreaks messed it up.
Does it compile OK? This goes with:
Debug, Compile VBAProject.


am I missing the End Function line after each Public Declare Function
(Lines)?



No, there is no such thing as End Function for declarations.

This the same declaration section, but made a bit narrower:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
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)

Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String


RBS


"Jim May" wrote in message
news:1eMrg.97414$IZ2.13653@dukeread07...

I think I got it, but When I open my Workbook, I get
Compile error - Only Comments may apprear after End Sub,
End Funtion or End Property The Declaration- Code seems
To be the culprit - am I missing the End Function line
After each Public Declare Function (Lines)?



"RB Smissaert" wrote in message
:


Simple, in your WorkBook_Open code do instead:

Load frmMainUser
frmMainUser.Show 0

AddMinMax frmMainUser.Caption

The declarations and the Sub AddMinMax will have to go to a normal
Module.
Keep all the declarations just as they are, no need to make the
declarations
Public.

RBS

"Jim May" wrote in message
news:cKLrg.97413$IZ2.41690@dukeread07...


RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to
False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:



If you can show the relevant code I might be able to tell you where
you
went
wrong.

RBS

"Scott" wrote in message
...



Thanks for the help.

I copied your codes to my file, but I still did not get the buttons
on
my
UserForm1.

"RB Smissaert" wrote:




This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...



Tom,

Thanks very much. The FormFun is very interesting. But the codes
are
too
complicated for me to adopt. I just want to have the bottons on
the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:




Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:




How to add Minimize and Maximize/Restore Down buttons to a
user
form?








  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Minimize Maximize buttons

RB,
Never mind...
I do now see that I have the ability to choose
My UF size with the icons;
Thanks for all your help.
Jim

"Jim May" wrote in message
news:ASMrg.97415$IZ2.21570@dukeread07:

RB,
Got it!!
One last Q;
My Userform on Load (Wb Open) comes up partial screen (3 X 5)
When I minimize it, then Restore it comes up Full screen (7 X 10, say)
Can this aspect be controlled to where the Restore could re-produce
The 3 X 5 Size?
Really do appreciate your help on this.
Jim

"RB Smissaert" wrote in message
:


Maybe the linebreaks messed it up.
Does it compile OK? This goes with:
Debug, Compile VBAProject.



am I missing the End Function line after each Public Declare Function
(Lines)?




No, there is no such thing as End Function for declarations.

This the same declaration section, but made a bit narrower:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
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)

Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String


RBS


"Jim May" wrote in message
news:1eMrg.97414$IZ2.13653@dukeread07...


I think I got it, but When I open my Workbook, I get
Compile error - Only Comments may apprear after End Sub,
End Funtion or End Property The Declaration- Code seems
To be the culprit - am I missing the End Function line
After each Public Declare Function (Lines)?



"RB Smissaert" wrote in message
:



Simple, in your WorkBook_Open code do instead:

Load frmMainUser
frmMainUser.Show 0

AddMinMax frmMainUser.Caption

The declarations and the Sub AddMinMax will have to go to a normal
Module.
Keep all the declarations just as they are, no need to make the
declarations
Public.

RBS

"Jim May" wrote in message
news:cKLrg.97413$IZ2.41690@dukeread07...



RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to
False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:




If you can show the relevant code I might be able to tell you where
you
went
wrong.

RBS

"Scott" wrote in message
...




Thanks for the help.

I copied your codes to my file, but I still did not get the buttons
on
my
UserForm1.

"RB Smissaert" wrote:





This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...




Tom,

Thanks very much. The FormFun is very interesting. But the codes
are
too
complicated for me to adopt. I just want to have the bottons on
the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:





Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:





How to add Minimize and Maximize/Restore Down buttons to a
user
form?









  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Yes, you can do that with:

ShowWindow hwnd, 3

This will have to go in the UserForm_Resize event code of the form and
should
run when you want the form maximized.

If you run it in the UserForm then the declaration in the module should be
made public.

It all will take a bit of experimentation, but it should all work in the
end.

RBS


"Jim May" wrote in message
news:ASMrg.97415$IZ2.21570@dukeread07...
RB,
Got it!!
One last Q;
My Userform on Load (Wb Open) comes up partial screen (3 X 5)
When I minimize it, then Restore it comes up Full screen (7 X 10, say)
Can this aspect be controlled to where the Restore could re-produce
The 3 X 5 Size?
Really do appreciate your help on this.
Jim

"RB Smissaert" wrote in message
:

Maybe the linebreaks messed it up.
Does it compile OK? This goes with:
Debug, Compile VBAProject.


am I missing the End Function line after each Public Declare Function
(Lines)?



No, there is no such thing as End Function for declarations.

This the same declaration section, but made a bit narrower:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
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)

Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String


RBS


"Jim May" wrote in message
news:1eMrg.97414$IZ2.13653@dukeread07...

I think I got it, but When I open my Workbook, I get
Compile error - Only Comments may apprear after End Sub,
End Funtion or End Property The Declaration- Code seems
To be the culprit - am I missing the End Function line
After each Public Declare Function (Lines)?



"RB Smissaert" wrote in message
:


Simple, in your WorkBook_Open code do instead:

Load frmMainUser
frmMainUser.Show 0

AddMinMax frmMainUser.Caption

The declarations and the Sub AddMinMax will have to go to a normal
Module.
Keep all the declarations just as they are, no need to make the
declarations
Public.

RBS

"Jim May" wrote in message
news:cKLrg.97413$IZ2.41690@dukeread07...


RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to
False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:



If you can show the relevant code I might be able to tell you where
you
went
wrong.

RBS

"Scott" wrote in message
...



Thanks for the help.

I copied your codes to my file, but I still did not get the
buttons
on
my
UserForm1.

"RB Smissaert" wrote:




This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As
Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...



Tom,

Thanks very much. The FormFun is very interesting. But the
codes
are
too
complicated for me to adopt. I just want to have the bottons
on
the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:




Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:




How to add Minimize and Maximize/Restore Down buttons to a
user
form?









  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

You also might be interested to minimize to the taskbar rather than having a
floating form.
That can be done with code like this:

Sub SetMinimize(strFormCaption As String)

Dim hwnd As Long

hwnd = FindWindow(strFormType, strFormCaption)

If IsIconic(hwnd) Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 6
End If

End Sub

All this works nicely in large app I have, but when I test in a simple test
setup
the first time this runs it still minimizes to the floating window. After
that it
will miminize to the taskbar. Not sure why this is.


RBS


"Jim May" wrote in message
news:ASMrg.97415$IZ2.21570@dukeread07...
RB,
Got it!!
One last Q;
My Userform on Load (Wb Open) comes up partial screen (3 X 5)
When I minimize it, then Restore it comes up Full screen (7 X 10, say)
Can this aspect be controlled to where the Restore could re-produce
The 3 X 5 Size?
Really do appreciate your help on this.
Jim

"RB Smissaert" wrote in message
:

Maybe the linebreaks messed it up.
Does it compile OK? This goes with:
Debug, Compile VBAProject.


am I missing the End Function line after each Public Declare Function
(Lines)?



No, there is no such thing as End Function for declarations.

This the same declaration section, but made a bit narrower:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
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)

Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String


RBS


"Jim May" wrote in message
news:1eMrg.97414$IZ2.13653@dukeread07...

I think I got it, but When I open my Workbook, I get
Compile error - Only Comments may apprear after End Sub,
End Funtion or End Property The Declaration- Code seems
To be the culprit - am I missing the End Function line
After each Public Declare Function (Lines)?



"RB Smissaert" wrote in message
:


Simple, in your WorkBook_Open code do instead:

Load frmMainUser
frmMainUser.Show 0

AddMinMax frmMainUser.Caption

The declarations and the Sub AddMinMax will have to go to a normal
Module.
Keep all the declarations just as they are, no need to make the
declarations
Public.

RBS

"Jim May" wrote in message
news:cKLrg.97413$IZ2.41690@dukeread07...


RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to
False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:



If you can show the relevant code I might be able to tell you where
you
went
wrong.

RBS

"Scott" wrote in message
...



Thanks for the help.

I copied your codes to my file, but I still did not get the
buttons
on
my
UserForm1.

"RB Smissaert" wrote:




This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As
Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...



Tom,

Thanks very much. The FormFun is very interesting. But the
codes
are
too
complicated for me to adopt. I just want to have the bottons
on
the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:




Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:




How to add Minimize and Maximize/Restore Down buttons to a
user
form?











  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

One last tip:
What you may want to do is to avoid getting every time again that hwnd of
your
form is make this a property of the form like this:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Then in your module or where ever you can always do something like this:

hwnd = UserForm1.propFormHwnd

Saving you all the extra code with FindWindow. You could achieve the same
with a public variable, but this is neater.


RBS



"Jim May" wrote in message
news:ASMrg.97415$IZ2.21570@dukeread07...
RB,
Got it!!
One last Q;
My Userform on Load (Wb Open) comes up partial screen (3 X 5)
When I minimize it, then Restore it comes up Full screen (7 X 10, say)
Can this aspect be controlled to where the Restore could re-produce
The 3 X 5 Size?
Really do appreciate your help on this.
Jim

"RB Smissaert" wrote in message
:

Maybe the linebreaks messed it up.
Does it compile OK? This goes with:
Debug, Compile VBAProject.


am I missing the End Function line after each Public Declare Function
(Lines)?



No, there is no such thing as End Function for declarations.

This the same declaration section, but made a bit narrower:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
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)

Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String


RBS


"Jim May" wrote in message
news:1eMrg.97414$IZ2.13653@dukeread07...

I think I got it, but When I open my Workbook, I get
Compile error - Only Comments may apprear after End Sub,
End Funtion or End Property The Declaration- Code seems
To be the culprit - am I missing the End Function line
After each Public Declare Function (Lines)?



"RB Smissaert" wrote in message
:


Simple, in your WorkBook_Open code do instead:

Load frmMainUser
frmMainUser.Show 0

AddMinMax frmMainUser.Caption

The declarations and the Sub AddMinMax will have to go to a normal
Module.
Keep all the declarations just as they are, no need to make the
declarations
Public.

RBS

"Jim May" wrote in message
news:cKLrg.97413$IZ2.41690@dukeread07...


RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to
False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:



If you can show the relevant code I might be able to tell you where
you
went
wrong.

RBS

"Scott" wrote in message
...



Thanks for the help.

I copied your codes to my file, but I still did not get the
buttons
on
my
UserForm1.

"RB Smissaert" wrote:




This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As
Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...



Tom,

Thanks very much. The FormFun is very interesting. But the
codes
are
too
complicated for me to adopt. I just want to have the bottons
on
the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:




Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:




How to add Minimize and Maximize/Restore Down buttons to a
user
form?









  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Minimize Maximize buttons

RBS,

I have a form called "UserForm1" under folder "Forms". I copied your codes
to "Module2" in folder Modules. And I tried to run your codes, which brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes are
too
complicated for me to adopt. I just want to have the bottons on the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:

Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:

How to add Minimize and Maximize/Restore Down buttons to a user
form?




  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Minimize Maximize buttons

RB,
Thanks for such a full explanation of things;
I've printed out for this and other Source (future) documentation/
Needs.


"RB Smissaert" wrote in message
:

One last tip:
What you may want to do is to avoid getting every time again that hwnd of
your
form is make this a property of the form like this:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Then in your module or where ever you can always do something like this:

hwnd = UserForm1.propFormHwnd

Saving you all the extra code with FindWindow. You could achieve the same
with a public variable, but this is neater.


RBS



"Jim May" wrote in message
news:ASMrg.97415$IZ2.21570@dukeread07...

RB,
Got it!!
One last Q;
My Userform on Load (Wb Open) comes up partial screen (3 X 5)
When I minimize it, then Restore it comes up Full screen (7 X 10, say)
Can this aspect be controlled to where the Restore could re-produce
The 3 X 5 Size?
Really do appreciate your help on this.
Jim

"RB Smissaert" wrote in message
:


Maybe the linebreaks messed it up.
Does it compile OK? This goes with:
Debug, Compile VBAProject.



am I missing the End Function line after each Public Declare Function
(Lines)?



No, there is no such thing as End Function for declarations.

This the same declaration section, but made a bit narrower:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
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)

Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String


RBS


"Jim May" wrote in message
news:1eMrg.97414$IZ2.13653@dukeread07...


I think I got it, but When I open my Workbook, I get
Compile error - Only Comments may apprear after End Sub,
End Funtion or End Property The Declaration- Code seems
To be the culprit - am I missing the End Function line
After each Public Declare Function (Lines)?



"RB Smissaert" wrote in message
:



Simple, in your WorkBook_Open code do instead:

Load frmMainUser
frmMainUser.Show 0

AddMinMax frmMainUser.Caption

The declarations and the Sub AddMinMax will have to go to a normal
Module.
Keep all the declarations just as they are, no need to make the
declarations
Public.

RBS

"Jim May" wrote in message
news:cKLrg.97413$IZ2.41690@dukeread07...



RB;
I'd love to incorporate your code into a app I've got going.
I see 3 code sections:
1) The Public Declare - Constants
2) The AddMinMax
3) The Load Form

In My Open Workbook Code I have:
frmMainUser.show ' where frmMainUser - Show Modal prop is set to
False

There is no other Userform code attached to frmMainUser

How would I proceed to incorporate the above.
I am fairly VB understanding, so keep it simple, PLEASE..
Thanks for your assistance.


"RB Smissaert" wrote in message
:




If you can show the relevant code I might be able to tell you where
you
went
wrong.

RBS

"Scott" wrote in message
...




Thanks for the help.

I copied your codes to my file, but I still did not get the
buttons
on
my
UserForm1.

"RB Smissaert" wrote:





This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As
Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...




Tom,

Thanks very much. The FormFun is very interesting. But the
codes
are
too
complicated for me to adopt. I just want to have the bottons
on
the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:





Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:





How to add Minimize and Maximize/Restore Down buttons to a
user
form?










  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

What is your Excel version?

Try changing this:
hwnd = FindWindow(strFormType, strFormCaption)
to this:
hwnd = FindWindow(vbNullString, strFormCaption)

RBS

"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes are
too
complicated for me to adopt. I just want to have the bottons on the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:

Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:

How to add Minimize and Maximize/Restore Down buttons to a user
form?





  #20   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Figured out now how to let it minimize to the taskbar and this is all the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes are
too
complicated for me to adopt. I just want to have the bottons on the
form
once
the form is initialized.

Anyway, I apprecite your help.

Scott

"Tom Ogilvy" wrote:

Stephen Bullen's site:
http://www.oaltd.co.uk/MVP/Default.htm
download FormFun.zip

uncompress it. Run/look at the code. Use the class module.

--
Regards,
Tom Ogilvy


"Scott" wrote:

How to add Minimize and Maximize/Restore Down buttons to a user
form?







  #21   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Minimize Maximize buttons

RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes are
too
complicated for me to adopt. I just want to have the bottons on the
form
once
the form is initialized.

Anyway, I apprecite your help.

  #22   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

No trouble, I wanted to get this clear myself.

RBS

"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your
codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons
on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes
are
too
complicated for me to adopt. I just want to have the bottons on
the
form
once
the form is initialized.

Anyway, I apprecite your help.


  #23   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

It looks it can actually work with a normal modal form as well, but as you
can
see it needs some adjustments as it doesn't work first time.

RBS

"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your
codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons
on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes
are
too
complicated for me to adopt. I just want to have the bottons on
the
form
once
the form is initialized.

Anyway, I apprecite your help.


  #24   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Would be interested if anybody could tell me how to make this work properly
with a normal modal userform.

RBS

"RB Smissaert" wrote in message
...
It looks it can actually work with a normal modal form as well, but as you
can
see it needs some adjustments as it doesn't work first time.

RBS

"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all
the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or
to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your
codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons
on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes
are
too
complicated for me to adopt. I just want to have the bottons on
the
form
once
the form is initialized.

Anyway, I apprecite your help.



  #25   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Had a look at the file FormFun.xls, but even that doesn't handle this
(maximize and minimize with a modal form) properly, as you can see
when you tick modal and minimize the form.

RBS

"RB Smissaert" wrote in message
...
Would be interested if anybody could tell me how to make this work
properly with a normal modal userform.

RBS

"RB Smissaert" wrote in message
...
It looks it can actually work with a normal modal form as well, but as
you can
see it needs some adjustments as it doesn't work first time.

RBS

"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all
the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or
to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your
codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the
buttons on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As
Long, _
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the
codes are
too
complicated for me to adopt. I just want to have the bottons on
the
form
once
the form is initialized.

Anyway, I apprecite your help.






  #26   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

I suppose there is little point in minimizing a modal userform as you
can't do anything outside the form.

RBS

"RB Smissaert" wrote in message
...
Had a look at the file FormFun.xls, but even that doesn't handle this
(maximize and minimize with a modal form) properly, as you can see
when you tick modal and minimize the form.

RBS

"RB Smissaert" wrote in message
...
Would be interested if anybody could tell me how to make this work
properly with a normal modal userform.

RBS

"RB Smissaert" wrote in message
...
It looks it can actually work with a normal modal form as well, but as
you can
see it needs some adjustments as it doesn't work first time.

RBS

"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all
the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or
to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your
codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like
doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the
buttons on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As
Long, _
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the
codes are
too
complicated for me to adopt. I just want to have the bottons
on the
form
once
the form is initialized.

Anyway, I apprecite your help.




  #27   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Minimize Maximize buttons

Bingo!

--
Regards,
Tom Ogilvy

"RB Smissaert" wrote in message
...
I suppose there is little point in minimizing a modal userform as you
can't do anything outside the form.

RBS

"RB Smissaert" wrote in message
...
Had a look at the file FormFun.xls, but even that doesn't handle this
(maximize and minimize with a modal form) properly, as you can see
when you tick modal and minimize the form.

RBS

"RB Smissaert" wrote in message
...
Would be interested if anybody could tell me how to make this work
properly with a normal modal userform.

RBS

"RB Smissaert" wrote in message
...
It looks it can actually work with a normal modal form as well, but as
you can
see it needs some adjustments as it doesn't work first time.

RBS

"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all
the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window
or to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied
your codes
to "Module2" in folder Modules. And I tried to run your codes,
which
brought
up UserForm1, but there were no Min/Max buttons. Here are the
codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like
doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the
buttons on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As
Long, _
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the
codes are
too
complicated for me to adopt. I just want to have the bottons
on the
form
once
the form is initialized.

Anyway, I apprecite your help.






  #28   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Well, you could have a peek in the sheet without moving or closing the form,
but that really is all.

RBS

"Tom Ogilvy" wrote in message
...
Bingo!

--
Regards,
Tom Ogilvy

"RB Smissaert" wrote in message
...
I suppose there is little point in minimizing a modal userform as you
can't do anything outside the form.

RBS

"RB Smissaert" wrote in message
...
Had a look at the file FormFun.xls, but even that doesn't handle this
(maximize and minimize with a modal form) properly, as you can see
when you tick modal and minimize the form.

RBS

"RB Smissaert" wrote in message
...
Would be interested if anybody could tell me how to make this work
properly with a normal modal userform.

RBS

"RB Smissaert" wrote in message
...
It looks it can actually work with a normal modal form as well, but as
you can
see it needs some adjustments as it doesn't work first time.

RBS

"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is
all the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window
or to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied
your codes
to "Module2" in folder Modules. And I tried to run your codes,
which
brought
up UserForm1, but there were no Min/Max buttons. Here are the
codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long,
_
ByVal nIndex As
Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like
doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the
buttons on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As
Long, _
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the
codes are
too
complicated for me to adopt. I just want to have the bottons
on the
form
once
the form is initialized.

Anyway, I apprecite your help.







  #29   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Actually it can be done a bit simpler still as it looks we don't need any
code
in the UserForm Resize event.

In UserForm:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

=========================================

In normal Module:

Option Explicit
Private 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = -16

Sub LoadForm()

Dim hwnd As Long
Dim bTaskBarMinimize As Boolean

Load UserForm1
UserForm1.Show 0

AddMinMax

hwnd = UserForm1.propFormHwnd

'set to False for floating minimize
'----------------------------------
bTaskBarMinimize = True

If bTaskBarMinimize Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If

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


RBS


"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your
codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "UserForm1"

End Sub


"RB Smissaert" wrote:

Did you do:
UserForm1.Show 0

So did you load the form as a modeless form?
A modeless form means you can do things outside the form (like doing
things
in the sheet) while the form is loaded.
It doesn't work with a normal modal form, not sure now if it can.

RBS

"Scott" wrote in message
...
Thanks for the help.

I copied your codes to my file, but I still did not get the buttons
on
my
UserForm1.

"RB Smissaert" wrote:

This is simplest code to add those buttons:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long,
_
ByVal nIndex As
Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
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 LoadForm()

Load UserForm1
UserForm1.Show 0

AddMinMax "Userform1"

End Sub


RBS


"Scott" wrote in message
...
Tom,

Thanks very much. The FormFun is very interesting. But the codes
are
too
complicated for me to adopt. I just want to have the bottons on
the
form
once
the form is initialized.

Anyway, I apprecite your help.


  #30   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Minimize Maximize buttons

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




  #31   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Minimize Maximize buttons

When I click the close button, the program is gone. Is there a way to give a
warning, like "Do you want to save before exit? Yes/No"

"RB Smissaert" wrote:

Actually it can be done a bit simpler still as it looks we don't need any
code
in the UserForm Resize event.

In UserForm:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

=========================================

In normal Module:

Option Explicit
Private 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = -16

Sub LoadForm()

Dim hwnd As Long
Dim bTaskBarMinimize As Boolean

Load UserForm1
UserForm1.Show 0

AddMinMax

hwnd = UserForm1.propFormHwnd

'set to False for floating minimize
'----------------------------------
bTaskBarMinimize = True

If bTaskBarMinimize Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If

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


RBS


"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your
codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
lngStyle = GetWindowLong(hwnd, GWL_STYLE)
lngStyle = lngStyle Or WS_MAXIMIZEBOX
lngStyle = lngStyle Or WS_MINIMIZEBOX

SetWindowLong hwnd, GWL_STYLE, lngStyle
DrawMenuBar hwnd

  #32   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Minimize Maximize buttons

Yes, put this code in your UserForm module:

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Or _
CloseMode = vbAppTaskManager Then
If MsgBox("Are you sure you want to close this window?", _
vbQuestion + vbYesNo + vbDefaultButton1, _
"") = vbNo Then
Cancel = 1
End If
End If
End Sub

RBS


"Scott" wrote in message
...
When I click the close button, the program is gone. Is there a way to give
a
warning, like "Do you want to save before exit? Yes/No"

"RB Smissaert" wrote:

Actually it can be done a bit simpler still as it looks we don't need any
code
in the UserForm Resize event.

In UserForm:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

=========================================

In normal Module:

Option Explicit
Private 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = -16

Sub LoadForm()

Dim hwnd As Long
Dim bTaskBarMinimize As Boolean

Load UserForm1
UserForm1.Show 0

AddMinMax

hwnd = UserForm1.propFormHwnd

'set to False for floating minimize
'----------------------------------
bTaskBarMinimize = True

If bTaskBarMinimize Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If

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


RBS


"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all
the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or
to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your
codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = (-16)
Private strFormType As String

Sub AddMinMax(strFormCaption As String)

Dim hwnd As Long
Dim lngStyle As Long

'this is not really necessary, vbNullString will do
If Val(Application.Version) = 9 Then
strFormType = "ThunderDFrame"
Else
strFormType = "ThunderXFrame"
End If

hwnd = FindWindow(strFormType, strFormCaption)
lngStyle = GetWindowLong(hwnd, GWL_STYLE)
lngStyle = lngStyle Or WS_MAXIMIZEBOX
lngStyle = lngStyle Or WS_MINIMIZEBOX

SetWindowLong hwnd, GWL_STYLE, lngStyle
DrawMenuBar hwnd


  #33   Report Post  
Posted to microsoft.public.excel.programming
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



  #34   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default Minimize Maximize buttons

Cool!

Thanks a lot.

"RB Smissaert" wrote:

Yes, put this code in your UserForm module:

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Or _
CloseMode = vbAppTaskManager Then
If MsgBox("Are you sure you want to close this window?", _
vbQuestion + vbYesNo + vbDefaultButton1, _
"") = vbNo Then
Cancel = 1
End If
End If
End Sub

RBS


"Scott" wrote in message
...
When I click the close button, the program is gone. Is there a way to give
a
warning, like "Do you want to save before exit? Yes/No"

"RB Smissaert" wrote:

Actually it can be done a bit simpler still as it looks we don't need any
code
in the UserForm Resize event.

In UserForm:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

=========================================

In normal Module:

Option Explicit
Private 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 Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = -16

Sub LoadForm()

Dim hwnd As Long
Dim bTaskBarMinimize As Boolean

Load UserForm1
UserForm1.Show 0

AddMinMax

hwnd = UserForm1.propFormHwnd

'set to False for floating minimize
'----------------------------------
bTaskBarMinimize = True

If bTaskBarMinimize Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If

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


RBS


"Scott" wrote in message
...
RBS,

Great! It works perfect. Thanks a lot.

"RB Smissaert" wrote:

Figured out now how to let it minimize to the taskbar and this is all
the
code in my test Wb:

In the UserForm1 code:

Option Explicit
Private lFormHwnd As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub UserForm_Initialize()

Dim hwnd As Long

If Val(Application.Version) = 9 Then
hwnd = FindWindow("ThunderDFrame", Caption)
Else
hwnd = FindWindow("ThunderXFrame", Caption)
End If

Me.propFormHwnd = hwnd

End Sub

Private Sub UserForm_Resize()
SetMinimize 'leave out for floating minimize
End Sub

'=====================================

In the normal module:

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)

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

Sub LoadForm()

Load UserForm1
UserForm1.Show 0
AddMinMax
SetMinimize True 'leave out for floating minimize

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
Else
If bNormal Then
ShowWindow hwnd, 0
SetWindowLong hwnd, -20, &H40101
ShowWindow hwnd, 1
End If
End If

End Sub


So, you now have the options to minimize to a small floating window or
to
the taskbar and this
depends on running SetMinimize in the 2 places as mentioned.
I think it now all should work.


RBS



"Scott" wrote in message
...
RBS,

I have a form called "UserForm1" under folder "Forms". I copied your
codes
to "Module2" in folder Modules. And I tried to run your codes, which
brought
up UserForm1, but there were no Min/Max buttons. Here are the codes:

Option Explicit
Public Declare Function GetWindowLong _
Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long)
As
Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) 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" _

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
minimize and maximize buttons missing KR4d Excel Discussion (Misc queries) 8 October 9th 09 03:32 PM
how do i minimize/maximize a workbook from vba? I want to minimize it durring processing to speed things up a bit Daniel Excel Worksheet Functions 2 July 9th 05 03:35 AM
Minimize and maximize buttons userforms RB Smissaert Excel Programming 15 February 26th 05 11:13 PM
Maximize & Minimize buttons where are they? Don Bowyer Excel Programming 3 July 18th 04 01:28 AM
How to get Maximize and Minimize buttons on Userform TBA[_2_] Excel Programming 1 September 9th 03 08:13 PM


All times are GMT +1. The time now is 09:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"