+ Reply to Thread
Results 1 to 16 of 16

Minimize and maximize buttons userforms

  1. #1
    RB Smissaert
    Guest

    Minimize and maximize buttons userforms

    How do I add minimize and maximize buttons to a VBA userform?
    I have this code that does it, but when I change the caption of the userform
    the buttons don't work anymore. I am slowly coming to the conclusion that
    it probably is not worth the trouble and that it is better to make your own
    buttons.

    Public Declare Function FindWindow _
    Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As Long, _
    ByVal lpWindowName 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 Sub UserForm_Initialize()

    Dim hWnd as Long

    hWnd = FindWindow(vbNullString, UserForm1.Caption)
    SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080

    End Sub


    RBS


  2. #2
    RB Smissaert
    Guest

    Re: Minimize and maximize buttons userforms

    Sorry, the FindWindow API declaration should be:

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

    RBS


    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    > How do I add minimize and maximize buttons to a VBA userform?
    > I have this code that does it, but when I change the caption of the
    > userform
    > the buttons don't work anymore. I am slowly coming to the conclusion that
    > it probably is not worth the trouble and that it is better to make your
    > own buttons.
    >
    > Public Declare Function FindWindow _
    > Lib "user32" Alias _
    > "FindWindowA" (ByVal lpClassName As Long, _
    > ByVal lpWindowName 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 Sub UserForm_Initialize()
    >
    > Dim hWnd as Long
    >
    > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >
    > End Sub
    >
    >
    > RBS
    >



  3. #3
    Bob Phillips
    Guest

    Re: Minimize and maximize buttons userforms

    If you change the name of the form, you cannot use the old name in the
    initialize code.

    Why not use?

    Private Sub UserForm_Initialize()
    Dim hWnd As Long

    hWnd = FindWindow(vbNullString, Me.Caption)
    SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080

    End Sub



    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    > How do I add minimize and maximize buttons to a VBA userform?
    > I have this code that does it, but when I change the caption of the

    userform
    > the buttons don't work anymore. I am slowly coming to the conclusion that
    > it probably is not worth the trouble and that it is better to make your

    own
    > buttons.
    >
    > Public Declare Function FindWindow _
    > Lib "user32" Alias _
    > "FindWindowA" (ByVal lpClassName As Long, _
    > ByVal lpWindowName 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 Sub UserForm_Initialize()
    >
    > Dim hWnd as Long
    >
    > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >
    > End Sub
    >
    >
    > RBS
    >




  4. #4
    RB Smissaert
    Guest

    Re: Minimize and maximize buttons userforms

    I am not changing the name of the form, just the caption.
    Doing Me.Caption won't make a difference.

    RBS


    "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    news:OsgSLNBHFHA.2356@TK2MSFTNGP12.phx.gbl...
    > If you change the name of the form, you cannot use the old name in the
    > initialize code.
    >
    > Why not use?
    >
    > Private Sub UserForm_Initialize()
    > Dim hWnd As Long
    >
    > hWnd = FindWindow(vbNullString, Me.Caption)
    > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >
    > End Sub
    >
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    >> How do I add minimize and maximize buttons to a VBA userform?
    >> I have this code that does it, but when I change the caption of the

    > userform
    >> the buttons don't work anymore. I am slowly coming to the conclusion that
    >> it probably is not worth the trouble and that it is better to make your

    > own
    >> buttons.
    >>
    >> Public Declare Function FindWindow _
    >> Lib "user32" Alias _
    >> "FindWindowA" (ByVal lpClassName As Long, _
    >> ByVal lpWindowName 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 Sub UserForm_Initialize()
    >>
    >> Dim hWnd as Long
    >>
    >> hWnd = FindWindow(vbNullString, UserForm1.Caption)
    >> SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >>
    >> End Sub
    >>
    >>
    >> RBS
    >>

    >
    >



  5. #5
    Ken Macksey
    Guest

    Re: Minimize and maximize buttons userforms

    Hi

    Go here and get FlexmenuE and flexgrabberE. They are free controls that you
    can drop on your vba form and make it resizeable and add min and max buttons
    with no code.
    The newest version also lets you minimize and maximize your form with code
    if you wish to.

    http://www.vbusers.com/downloads/download.asp#item3\

    HTH

    Ken

    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    > How do I add minimize and maximize buttons to a VBA userform?
    > I have this code that does it, but when I change the caption of the
    > userform
    > the buttons don't work anymore. I am slowly coming to the conclusion that
    > it probably is not worth the trouble and that it is better to make your
    > own buttons.
    >
    > Public Declare Function FindWindow _
    > Lib "user32" Alias _
    > "FindWindowA" (ByVal lpClassName As Long, _
    > ByVal lpWindowName 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 Sub UserForm_Initialize()
    >
    > Dim hWnd as Long
    >
    > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >
    > End Sub
    >
    >
    > RBS
    >




  6. #6
    RB Smissaert
    Guest

    Re: Minimize and maximize buttons userforms

    Thanks, but I had a look at these controls a long time ago and decided they
    weren't worth the extra overhead.
    I have downloaded and installed again and had a look if they suffer from the
    same problem, that is that changing
    the form caption makes the minimize and maximize buttons stop working.
    Unfortunately it shows exactly the same problem.

    RBS


    "Ken Macksey" <KenMacksey@tnt21.com> wrote in message
    news:O3zlQgBHFHA.2744@tk2msftngp13.phx.gbl...
    > Hi
    >
    > Go here and get FlexmenuE and flexgrabberE. They are free controls that
    > you can drop on your vba form and make it resizeable and add min and max
    > buttons with no code.
    > The newest version also lets you minimize and maximize your form with code
    > if you wish to.
    >
    > http://www.vbusers.com/downloads/download.asp#item3\
    >
    > HTH
    >
    > Ken
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    >> How do I add minimize and maximize buttons to a VBA userform?
    >> I have this code that does it, but when I change the caption of the
    >> userform
    >> the buttons don't work anymore. I am slowly coming to the conclusion that
    >> it probably is not worth the trouble and that it is better to make your
    >> own buttons.
    >>
    >> Public Declare Function FindWindow _
    >> Lib "user32" Alias _
    >> "FindWindowA" (ByVal lpClassName As Long, _
    >> ByVal lpWindowName 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 Sub UserForm_Initialize()
    >>
    >> Dim hWnd as Long
    >>
    >> hWnd = FindWindow(vbNullString, UserForm1.Caption)
    >> SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >>
    >> End Sub
    >>
    >>
    >> RBS
    >>

    >
    >



  7. #7
    RB Smissaert
    Guest

    Re: Minimize and maximize buttons userforms

    Forgot to say that if you try to set the min/max buttons again after
    changing the form's caption
    you get some really strange effects. Definitely not healthy to do that with
    the code as it is.

    RBS


    "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    news:OsgSLNBHFHA.2356@TK2MSFTNGP12.phx.gbl...
    > If you change the name of the form, you cannot use the old name in the
    > initialize code.
    >
    > Why not use?
    >
    > Private Sub UserForm_Initialize()
    > Dim hWnd As Long
    >
    > hWnd = FindWindow(vbNullString, Me.Caption)
    > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >
    > End Sub
    >
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    >> How do I add minimize and maximize buttons to a VBA userform?
    >> I have this code that does it, but when I change the caption of the

    > userform
    >> the buttons don't work anymore. I am slowly coming to the conclusion that
    >> it probably is not worth the trouble and that it is better to make your

    > own
    >> buttons.
    >>
    >> Public Declare Function FindWindow _
    >> Lib "user32" Alias _
    >> "FindWindowA" (ByVal lpClassName As Long, _
    >> ByVal lpWindowName 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 Sub UserForm_Initialize()
    >>
    >> Dim hWnd as Long
    >>
    >> hWnd = FindWindow(vbNullString, UserForm1.Caption)
    >> SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >>
    >> End Sub
    >>
    >>
    >> RBS
    >>

    >
    >



  8. #8
    RB Smissaert
    Guest

    Re: Minimize and maximize buttons userforms

    Maybe I am on the right path now with this. If I do this:

    Unload UserForm1
    UserForm1.Caption = "Testing"
    AddMaxMin
    UserForm1.Show 0

    Sub AddMaxMin()

    Dim hWnd As Long

    hWnd = FindWindow(vbNullString, UserForm1.Caption)
    SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080

    End Sub

    It seems to work. Will see if this is all really workable.


    RBS


    "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    news:OsgSLNBHFHA.2356@TK2MSFTNGP12.phx.gbl...
    > If you change the name of the form, you cannot use the old name in the
    > initialize code.
    >
    > Why not use?
    >
    > Private Sub UserForm_Initialize()
    > Dim hWnd As Long
    >
    > hWnd = FindWindow(vbNullString, Me.Caption)
    > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >
    > End Sub
    >
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    >> How do I add minimize and maximize buttons to a VBA userform?
    >> I have this code that does it, but when I change the caption of the

    > userform
    >> the buttons don't work anymore. I am slowly coming to the conclusion that
    >> it probably is not worth the trouble and that it is better to make your

    > own
    >> buttons.
    >>
    >> Public Declare Function FindWindow _
    >> Lib "user32" Alias _
    >> "FindWindowA" (ByVal lpClassName As Long, _
    >> ByVal lpWindowName 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 Sub UserForm_Initialize()
    >>
    >> Dim hWnd as Long
    >>
    >> hWnd = FindWindow(vbNullString, UserForm1.Caption)
    >> SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >>
    >> End Sub
    >>
    >>
    >> RBS
    >>

    >
    >



  9. #9
    RB Smissaert
    Guest

    Re: Minimize and maximize buttons userforms

    I think I have this now all worked out.
    This is the code that does it:


    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 Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_MINIMIZEBOX = &H20000
    Private Const GWL_STYLE = (-16)

    Sub AddMinMax()

    Dim hWnd As Long
    Dim lngStyle As Long

    hWnd = FindWindow(vbNullString, MainForm.Caption)

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

    DrawMenuBar hWnd

    End Sub

    Just have to run AddMinMax from the Userform Activate event and after any
    code that alters the caption
    of the userform via Userform.Caption =
    It works very nice indeed.
    Just have to make my keyboard shortcuts now to run these menubar buttons.


    RBS


    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    > How do I add minimize and maximize buttons to a VBA userform?
    > I have this code that does it, but when I change the caption of the
    > userform
    > the buttons don't work anymore. I am slowly coming to the conclusion that
    > it probably is not worth the trouble and that it is better to make your
    > own buttons.
    >
    > Public Declare Function FindWindow _
    > Lib "user32" Alias _
    > "FindWindowA" (ByVal lpClassName As Long, _
    > ByVal lpWindowName 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 Sub UserForm_Initialize()
    >
    > Dim hWnd as Long
    >
    > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >
    > End Sub
    >
    >
    > RBS
    >



  10. #10
    Bob Phillips
    Guest

    Re: Minimize and maximize buttons userforms

    Two questions.

    Why do you need to change the caption?

    Where is DrawMenuBar defined?

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:Oe6GucEHFHA.4084@TK2MSFTNGP14.phx.gbl...
    > I think I have this now all worked out.
    > This is the code that does it:
    >
    >
    > 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 Const WS_MAXIMIZEBOX = &H10000
    > Private Const WS_MINIMIZEBOX = &H20000
    > Private Const GWL_STYLE = (-16)
    >
    > Sub AddMinMax()
    >
    > Dim hWnd As Long
    > Dim lngStyle As Long
    >
    > hWnd = FindWindow(vbNullString, MainForm.Caption)
    >
    > lngStyle = GetWindowLong(hWnd, GWL_STYLE)
    > lngStyle = lngStyle Or WS_MAXIMIZEBOX
    > lngStyle = lngStyle Or WS_MINIMIZEBOX
    > SetWindowLong hWnd, GWL_STYLE, lngStyle
    >
    > DrawMenuBar hWnd
    >
    > End Sub
    >
    > Just have to run AddMinMax from the Userform Activate event and after any
    > code that alters the caption
    > of the userform via Userform.Caption =
    > It works very nice indeed.
    > Just have to make my keyboard shortcuts now to run these menubar buttons.
    >
    >
    > RBS
    >
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    > > How do I add minimize and maximize buttons to a VBA userform?
    > > I have this code that does it, but when I change the caption of the
    > > userform
    > > the buttons don't work anymore. I am slowly coming to the conclusion

    that
    > > it probably is not worth the trouble and that it is better to make your
    > > own buttons.
    > >
    > > Public Declare Function FindWindow _
    > > Lib "user32" Alias _
    > > "FindWindowA" (ByVal lpClassName As Long, _
    > > ByVal lpWindowName 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 Sub UserForm_Initialize()
    > >
    > > Dim hWnd as Long
    > >
    > > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    > > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    > >
    > > End Sub
    > >
    > >
    > > RBS
    > >

    >




  11. #11
    RB Smissaert
    Guest

    Re: Minimize and maximize buttons userforms


    Two answers.

    I use the userform title bar (caption) to display all kind of messages for
    the users.

    Public Declare Function DrawMenuBar Lib "user32" _
    (ByVal hwnd As Long) As Long

    RBS


    "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    news:%23%23s0aiEHFHA.3592@TK2MSFTNGP10.phx.gbl...
    > Two questions.
    >
    > Why do you need to change the caption?
    >
    > Where is DrawMenuBar defined?
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:Oe6GucEHFHA.4084@TK2MSFTNGP14.phx.gbl...
    >> I think I have this now all worked out.
    >> This is the code that does it:
    >>
    >>
    >> 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 Const WS_MAXIMIZEBOX = &H10000
    >> Private Const WS_MINIMIZEBOX = &H20000
    >> Private Const GWL_STYLE = (-16)
    >>
    >> Sub AddMinMax()
    >>
    >> Dim hWnd As Long
    >> Dim lngStyle As Long
    >>
    >> hWnd = FindWindow(vbNullString, MainForm.Caption)
    >>
    >> lngStyle = GetWindowLong(hWnd, GWL_STYLE)
    >> lngStyle = lngStyle Or WS_MAXIMIZEBOX
    >> lngStyle = lngStyle Or WS_MINIMIZEBOX
    >> SetWindowLong hWnd, GWL_STYLE, lngStyle
    >>
    >> DrawMenuBar hWnd
    >>
    >> End Sub
    >>
    >> Just have to run AddMinMax from the Userform Activate event and after any
    >> code that alters the caption
    >> of the userform via Userform.Caption =
    >> It works very nice indeed.
    >> Just have to make my keyboard shortcuts now to run these menubar buttons.
    >>
    >>
    >> RBS
    >>
    >>
    >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    >> > How do I add minimize and maximize buttons to a VBA userform?
    >> > I have this code that does it, but when I change the caption of the
    >> > userform
    >> > the buttons don't work anymore. I am slowly coming to the conclusion

    > that
    >> > it probably is not worth the trouble and that it is better to make your
    >> > own buttons.
    >> >
    >> > Public Declare Function FindWindow _
    >> > Lib "user32" Alias _
    >> > "FindWindowA" (ByVal lpClassName As Long, _
    >> > ByVal lpWindowName 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 Sub UserForm_Initialize()
    >> >
    >> > Dim hWnd as Long
    >> >
    >> > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    >> > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >> >
    >> > End Sub
    >> >
    >> >
    >> > RBS
    >> >

    >>

    >
    >



  12. #12
    Bob Phillips
    Guest

    Re: Minimize and maximize buttons userforms

    I appreciate that it doesn't solve the problem, but would it not have been
    better (easier?) to have a status area and display your messages there
    rather than change the caption. I tend to subscribe to KISS personally.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:%23Xr7w0EHFHA.1396@TK2MSFTNGP10.phx.gbl...
    >
    > Two answers.
    >
    > I use the userform title bar (caption) to display all kind of messages for
    > the users.
    >
    > Public Declare Function DrawMenuBar Lib "user32" _
    > (ByVal hwnd As Long) As Long
    >
    > RBS
    >
    >
    > "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    > news:%23%23s0aiEHFHA.3592@TK2MSFTNGP10.phx.gbl...
    > > Two questions.
    > >
    > > Why do you need to change the caption?
    > >
    > > Where is DrawMenuBar defined?
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > > news:Oe6GucEHFHA.4084@TK2MSFTNGP14.phx.gbl...
    > >> I think I have this now all worked out.
    > >> This is the code that does it:
    > >>
    > >>
    > >> 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 Const WS_MAXIMIZEBOX = &H10000
    > >> Private Const WS_MINIMIZEBOX = &H20000
    > >> Private Const GWL_STYLE = (-16)
    > >>
    > >> Sub AddMinMax()
    > >>
    > >> Dim hWnd As Long
    > >> Dim lngStyle As Long
    > >>
    > >> hWnd = FindWindow(vbNullString, MainForm.Caption)
    > >>
    > >> lngStyle = GetWindowLong(hWnd, GWL_STYLE)
    > >> lngStyle = lngStyle Or WS_MAXIMIZEBOX
    > >> lngStyle = lngStyle Or WS_MINIMIZEBOX
    > >> SetWindowLong hWnd, GWL_STYLE, lngStyle
    > >>
    > >> DrawMenuBar hWnd
    > >>
    > >> End Sub
    > >>
    > >> Just have to run AddMinMax from the Userform Activate event and after

    any
    > >> code that alters the caption
    > >> of the userform via Userform.Caption =
    > >> It works very nice indeed.
    > >> Just have to make my keyboard shortcuts now to run these menubar

    buttons.
    > >>
    > >>
    > >> RBS
    > >>
    > >>
    > >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > >> news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    > >> > How do I add minimize and maximize buttons to a VBA userform?
    > >> > I have this code that does it, but when I change the caption of the
    > >> > userform
    > >> > the buttons don't work anymore. I am slowly coming to the conclusion

    > > that
    > >> > it probably is not worth the trouble and that it is better to make

    your
    > >> > own buttons.
    > >> >
    > >> > Public Declare Function FindWindow _
    > >> > Lib "user32" Alias _
    > >> > "FindWindowA" (ByVal lpClassName As Long, _
    > >> > ByVal lpWindowName 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 Sub UserForm_Initialize()
    > >> >
    > >> > Dim hWnd as Long
    > >> >
    > >> > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    > >> > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    > >> >
    > >> > End Sub
    > >> >
    > >> >
    > >> > RBS
    > >> >
    > >>

    > >
    > >

    >




  13. #13
    RB Smissaert
    Guest

    Re: Minimize and maximize buttons userforms

    This is a very busy userform and I don't want to add another label or
    textbox.
    Also the titlebar is just nice for this purpose as it stands out and is
    clear.
    It is no trouble as all I have to do is add the line AddMinMax after any
    code
    that alters the caption.

    > I tend to subscribe to KISS personally


    What is that?

    RBS


    "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    news:u2qIn9EHFHA.2976@TK2MSFTNGP15.phx.gbl...
    >I appreciate that it doesn't solve the problem, but would it not have been
    > better (easier?) to have a status area and display your messages there
    > rather than change the caption. I tend to subscribe to KISS personally.
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:%23Xr7w0EHFHA.1396@TK2MSFTNGP10.phx.gbl...
    >>
    >> Two answers.
    >>
    >> I use the userform title bar (caption) to display all kind of messages
    >> for
    >> the users.
    >>
    >> Public Declare Function DrawMenuBar Lib "user32" _
    >> (ByVal hwnd As Long) As Long
    >>
    >> RBS
    >>
    >>
    >> "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    >> news:%23%23s0aiEHFHA.3592@TK2MSFTNGP10.phx.gbl...
    >> > Two questions.
    >> >
    >> > Why do you need to change the caption?
    >> >
    >> > Where is DrawMenuBar defined?
    >> >
    >> > --
    >> >
    >> > HTH
    >> >
    >> > RP
    >> > (remove nothere from the email address if mailing direct)
    >> >
    >> >
    >> > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> > news:Oe6GucEHFHA.4084@TK2MSFTNGP14.phx.gbl...
    >> >> I think I have this now all worked out.
    >> >> This is the code that does it:
    >> >>
    >> >>
    >> >> 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 Const WS_MAXIMIZEBOX = &H10000
    >> >> Private Const WS_MINIMIZEBOX = &H20000
    >> >> Private Const GWL_STYLE = (-16)
    >> >>
    >> >> Sub AddMinMax()
    >> >>
    >> >> Dim hWnd As Long
    >> >> Dim lngStyle As Long
    >> >>
    >> >> hWnd = FindWindow(vbNullString, MainForm.Caption)
    >> >>
    >> >> lngStyle = GetWindowLong(hWnd, GWL_STYLE)
    >> >> lngStyle = lngStyle Or WS_MAXIMIZEBOX
    >> >> lngStyle = lngStyle Or WS_MINIMIZEBOX
    >> >> SetWindowLong hWnd, GWL_STYLE, lngStyle
    >> >>
    >> >> DrawMenuBar hWnd
    >> >>
    >> >> End Sub
    >> >>
    >> >> Just have to run AddMinMax from the Userform Activate event and after

    > any
    >> >> code that alters the caption
    >> >> of the userform via Userform.Caption =
    >> >> It works very nice indeed.
    >> >> Just have to make my keyboard shortcuts now to run these menubar

    > buttons.
    >> >>
    >> >>
    >> >> RBS
    >> >>
    >> >>
    >> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> >> news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    >> >> > How do I add minimize and maximize buttons to a VBA userform?
    >> >> > I have this code that does it, but when I change the caption of the
    >> >> > userform
    >> >> > the buttons don't work anymore. I am slowly coming to the conclusion
    >> > that
    >> >> > it probably is not worth the trouble and that it is better to make

    > your
    >> >> > own buttons.
    >> >> >
    >> >> > Public Declare Function FindWindow _
    >> >> > Lib "user32" Alias _
    >> >> > "FindWindowA" (ByVal lpClassName As Long, _
    >> >> > ByVal lpWindowName 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 Sub UserForm_Initialize()
    >> >> >
    >> >> > Dim hWnd as Long
    >> >> >
    >> >> > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    >> >> > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >> >> >
    >> >> > End Sub
    >> >> >
    >> >> >
    >> >> > RBS
    >> >> >
    >> >>
    >> >
    >> >

    >>

    >
    >



  14. #14
    Bob Phillips
    Guest

    Re: Minimize and maximize buttons userforms

    KISS - Keep It Simple Stupid :-)

    Bob

    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:%2335cFDFHFHA.2356@TK2MSFTNGP12.phx.gbl...
    > This is a very busy userform and I don't want to add another label or
    > textbox.
    > Also the titlebar is just nice for this purpose as it stands out and is
    > clear.
    > It is no trouble as all I have to do is add the line AddMinMax after any
    > code
    > that alters the caption.
    >
    > > I tend to subscribe to KISS personally

    >
    > What is that?
    >
    > RBS
    >




  15. #15
    Tom Ogilvy
    Guest

    Re: Minimize and maximize buttons userforms

    In the US it is a common acronym meaning:

    Keep it simple stupid

    --
    Regards,
    Tom Ogilvy


    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:%2335cFDFHFHA.2356@TK2MSFTNGP12.phx.gbl...
    > This is a very busy userform and I don't want to add another label or
    > textbox.
    > Also the titlebar is just nice for this purpose as it stands out and is
    > clear.
    > It is no trouble as all I have to do is add the line AddMinMax after any
    > code
    > that alters the caption.
    >
    > > I tend to subscribe to KISS personally

    >
    > What is that?
    >
    > RBS
    >
    >
    > "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    > news:u2qIn9EHFHA.2976@TK2MSFTNGP15.phx.gbl...
    > >I appreciate that it doesn't solve the problem, but would it not have

    been
    > > better (easier?) to have a status area and display your messages there
    > > rather than change the caption. I tend to subscribe to KISS personally.
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > > news:%23Xr7w0EHFHA.1396@TK2MSFTNGP10.phx.gbl...
    > >>
    > >> Two answers.
    > >>
    > >> I use the userform title bar (caption) to display all kind of messages
    > >> for
    > >> the users.
    > >>
    > >> Public Declare Function DrawMenuBar Lib "user32" _
    > >> (ByVal hwnd As Long) As Long
    > >>
    > >> RBS
    > >>
    > >>
    > >> "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    > >> news:%23%23s0aiEHFHA.3592@TK2MSFTNGP10.phx.gbl...
    > >> > Two questions.
    > >> >
    > >> > Why do you need to change the caption?
    > >> >
    > >> > Where is DrawMenuBar defined?
    > >> >
    > >> > --
    > >> >
    > >> > HTH
    > >> >
    > >> > RP
    > >> > (remove nothere from the email address if mailing direct)
    > >> >
    > >> >
    > >> > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > >> > news:Oe6GucEHFHA.4084@TK2MSFTNGP14.phx.gbl...
    > >> >> I think I have this now all worked out.
    > >> >> This is the code that does it:
    > >> >>
    > >> >>
    > >> >> 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 Const WS_MAXIMIZEBOX = &H10000
    > >> >> Private Const WS_MINIMIZEBOX = &H20000
    > >> >> Private Const GWL_STYLE = (-16)
    > >> >>
    > >> >> Sub AddMinMax()
    > >> >>
    > >> >> Dim hWnd As Long
    > >> >> Dim lngStyle As Long
    > >> >>
    > >> >> hWnd = FindWindow(vbNullString, MainForm.Caption)
    > >> >>
    > >> >> lngStyle = GetWindowLong(hWnd, GWL_STYLE)
    > >> >> lngStyle = lngStyle Or WS_MAXIMIZEBOX
    > >> >> lngStyle = lngStyle Or WS_MINIMIZEBOX
    > >> >> SetWindowLong hWnd, GWL_STYLE, lngStyle
    > >> >>
    > >> >> DrawMenuBar hWnd
    > >> >>
    > >> >> End Sub
    > >> >>
    > >> >> Just have to run AddMinMax from the Userform Activate event and

    after
    > > any
    > >> >> code that alters the caption
    > >> >> of the userform via Userform.Caption =
    > >> >> It works very nice indeed.
    > >> >> Just have to make my keyboard shortcuts now to run these menubar

    > > buttons.
    > >> >>
    > >> >>
    > >> >> RBS
    > >> >>
    > >> >>
    > >> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > >> >> news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    > >> >> > How do I add minimize and maximize buttons to a VBA userform?
    > >> >> > I have this code that does it, but when I change the caption of

    the
    > >> >> > userform
    > >> >> > the buttons don't work anymore. I am slowly coming to the

    conclusion
    > >> > that
    > >> >> > it probably is not worth the trouble and that it is better to make

    > > your
    > >> >> > own buttons.
    > >> >> >
    > >> >> > Public Declare Function FindWindow _
    > >> >> > Lib "user32" Alias _
    > >> >> > "FindWindowA" (ByVal lpClassName As Long, _
    > >> >> > ByVal lpWindowName 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 Sub UserForm_Initialize()
    > >> >> >
    > >> >> > Dim hWnd as Long
    > >> >> >
    > >> >> > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    > >> >> > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    > >> >> >
    > >> >> > End Sub
    > >> >> >
    > >> >> >
    > >> >> > RBS
    > >> >> >
    > >> >>
    > >> >
    > >> >
    > >>

    > >
    > >

    >




  16. #16
    RB Smissaert
    Guest

    Re: Minimize and maximize buttons userforms

    I had heard about "It is the economy stupid", but not this one.
    It is is simple enough for me though.
    The only thing I haven't figured out yet is how to get the focus in a
    treeview
    control when I press the restore up button from the minimized position.
    Tried numerous construction, but no success yet.

    RBS


    "Tom Ogilvy" <twogilvy@msn.com> wrote in message
    news:ucu4wXFHFHA.4032@TK2MSFTNGP12.phx.gbl...
    > In the US it is a common acronym meaning:
    >
    > Keep it simple stupid
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:%2335cFDFHFHA.2356@TK2MSFTNGP12.phx.gbl...
    >> This is a very busy userform and I don't want to add another label or
    >> textbox.
    >> Also the titlebar is just nice for this purpose as it stands out and is
    >> clear.
    >> It is no trouble as all I have to do is add the line AddMinMax after any
    >> code
    >> that alters the caption.
    >>
    >> > I tend to subscribe to KISS personally

    >>
    >> What is that?
    >>
    >> RBS
    >>
    >>
    >> "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    >> news:u2qIn9EHFHA.2976@TK2MSFTNGP15.phx.gbl...
    >> >I appreciate that it doesn't solve the problem, but would it not have

    > been
    >> > better (easier?) to have a status area and display your messages there
    >> > rather than change the caption. I tend to subscribe to KISS personally.
    >> >
    >> > --
    >> >
    >> > HTH
    >> >
    >> > RP
    >> > (remove nothere from the email address if mailing direct)
    >> >
    >> >
    >> > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> > news:%23Xr7w0EHFHA.1396@TK2MSFTNGP10.phx.gbl...
    >> >>
    >> >> Two answers.
    >> >>
    >> >> I use the userform title bar (caption) to display all kind of messages
    >> >> for
    >> >> the users.
    >> >>
    >> >> Public Declare Function DrawMenuBar Lib "user32" _
    >> >> (ByVal hwnd As Long) As Long
    >> >>
    >> >> RBS
    >> >>
    >> >>
    >> >> "Bob Phillips" <bob.phillips@notheretiscali.co.uk> wrote in message
    >> >> news:%23%23s0aiEHFHA.3592@TK2MSFTNGP10.phx.gbl...
    >> >> > Two questions.
    >> >> >
    >> >> > Why do you need to change the caption?
    >> >> >
    >> >> > Where is DrawMenuBar defined?
    >> >> >
    >> >> > --
    >> >> >
    >> >> > HTH
    >> >> >
    >> >> > RP
    >> >> > (remove nothere from the email address if mailing direct)
    >> >> >
    >> >> >
    >> >> > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> >> > news:Oe6GucEHFHA.4084@TK2MSFTNGP14.phx.gbl...
    >> >> >> I think I have this now all worked out.
    >> >> >> This is the code that does it:
    >> >> >>
    >> >> >>
    >> >> >> 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 Const WS_MAXIMIZEBOX = &H10000
    >> >> >> Private Const WS_MINIMIZEBOX = &H20000
    >> >> >> Private Const GWL_STYLE = (-16)
    >> >> >>
    >> >> >> Sub AddMinMax()
    >> >> >>
    >> >> >> Dim hWnd As Long
    >> >> >> Dim lngStyle As Long
    >> >> >>
    >> >> >> hWnd = FindWindow(vbNullString, MainForm.Caption)
    >> >> >>
    >> >> >> lngStyle = GetWindowLong(hWnd, GWL_STYLE)
    >> >> >> lngStyle = lngStyle Or WS_MAXIMIZEBOX
    >> >> >> lngStyle = lngStyle Or WS_MINIMIZEBOX
    >> >> >> SetWindowLong hWnd, GWL_STYLE, lngStyle
    >> >> >>
    >> >> >> DrawMenuBar hWnd
    >> >> >>
    >> >> >> End Sub
    >> >> >>
    >> >> >> Just have to run AddMinMax from the Userform Activate event and

    > after
    >> > any
    >> >> >> code that alters the caption
    >> >> >> of the userform via Userform.Caption =
    >> >> >> It works very nice indeed.
    >> >> >> Just have to make my keyboard shortcuts now to run these menubar
    >> > buttons.
    >> >> >>
    >> >> >>
    >> >> >> RBS
    >> >> >>
    >> >> >>
    >> >> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> >> >> news:%23HpgJ3AHFHA.1392@TK2MSFTNGP10.phx.gbl...
    >> >> >> > How do I add minimize and maximize buttons to a VBA userform?
    >> >> >> > I have this code that does it, but when I change the caption of

    > the
    >> >> >> > userform
    >> >> >> > the buttons don't work anymore. I am slowly coming to the

    > conclusion
    >> >> > that
    >> >> >> > it probably is not worth the trouble and that it is better to
    >> >> >> > make
    >> > your
    >> >> >> > own buttons.
    >> >> >> >
    >> >> >> > Public Declare Function FindWindow _
    >> >> >> > Lib "user32" Alias _
    >> >> >> > "FindWindowA" (ByVal lpClassName As Long, _
    >> >> >> > ByVal lpWindowName 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 Sub UserForm_Initialize()
    >> >> >> >
    >> >> >> > Dim hWnd as Long
    >> >> >> >
    >> >> >> > hWnd = FindWindow(vbNullString, UserForm1.Caption)
    >> >> >> > SetWindowLong hWnd, -16, &H20000 Or &H10000 Or &H84C80080
    >> >> >> >
    >> >> >> > End Sub
    >> >> >> >
    >> >> >> >
    >> >> >> > RBS
    >> >> >> >
    >> >> >>
    >> >> >
    >> >> >
    >> >>
    >> >
    >> >

    >>

    >
    >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1