Results 1 to 3 of 3

Thread: Setting max/min buttons on form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Location
    Dublin, Ireland
    Posts
    120

    Setting max/min buttons on form

    Hi,
    Just wondering is it possible to set up min/max button next to the close button on forms in VBA? I know the code to max/min alright, just wonder at run-time is it possible to create these buttons. If not, is it possible to hide the titlebar(which contains the close button) so I can create these buttons myself?
    Thanks.

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Setting max/min buttons on form

    Quote Originally Posted by marktheman
    Hi,
    Just wondering is it possible to set up min/max button next to the close button on forms in VBA? I know the code to max/min alright, just wonder at run-time is it possible to create these buttons. If not, is it possible to hide the titlebar(which contains the close button) so I can create these buttons myself?
    Thanks.

    Does this help?

    1) Place this in a module

    vb Code:
    1. Option Explicit
    2.  
    3. Public Const GWL_STYLE = -16
    4. Public Const WS_CAPTION = &HC00000
    5. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
    6.                                                                            ByVal hWnd As Long, _
    7.                                                                            ByVal nIndex As Long) As Long
    8. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
    9.                                                                            ByVal hWnd As Long, _
    10.                                                                            ByVal nIndex As Long, _
    11.                                                                            ByVal dwNewLong As Long) As Long
    12. Public Declare Function DrawMenuBar Lib "user32" ( _
    13.                                                   ByVal hWnd As Long) As Long
    14. Public Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, _
    15.                                                   ByVal lpWindowName As String) As Long

    2) Place this in the normal code area

    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub UserForm_Initialize()
    4.     HideTitleBar Me
    5. End Sub
    6.  
    7.  
    8. Private Sub UserForm_Click()
    9.     'Close this userform
    10.     Unload Me
    11. End Sub
    12.  
    13. Sub Form_Show()
    14.     'Hide Excel
    15.     Application.Visible = False
    16.     'To close a form automatically
    17.     Application.OnTime Now, "Form_Close"
    18.     UserForm1.Show
    19. End Sub
    20.  
    21.  
    22. Sub Form_Close()
    23.      'To close a form automatically
    24.     Dim datWaitTime As Date
    25.     datWaitTime = TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 3)
    26.     Application.Wait datWaitTime
    27.     Unload UserForm1
    28.     Application.Visible = True
    29. End Sub
    30.  
    31.  
    32. Sub HideTitleBar(frm As Object)
    33.     Dim lngWindow As Long
    34.     Dim lFrmHdl As Long
    35.     lFrmHdl = FindWindowA(vbNullString, frm.Caption)
    36.     lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)
    37.     lngWindow = lngWindow And (Not WS_CAPTION)
    38.     Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow)
    39.     Call DrawMenuBar(lFrmHdl)
    40. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Location
    Dublin, Ireland
    Posts
    120

    Re: Setting max/min buttons on form

    Wow! Cheers, mate! Must learn about those VB dlls and what they do. Thanks once again and hope I can return the favour in the future.
    Cheers.

Posting Permissions

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



Click Here to Expand Forum to Full Width