View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
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?