-
Apr 26th, 2007, 11:48 AM
#1
Thread Starter
Lively Member
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.
-
Apr 26th, 2007, 12:00 PM
#2
Re: Setting max/min buttons on form
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:
Option Explicit
Public Const GWL_STYLE = -16
Public Const WS_CAPTION = &HC00000
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Declare Function DrawMenuBar Lib "user32" ( _
ByVal hWnd As Long) As Long
Public Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
2) Place this in the normal code area
vb Code:
Option Explicit
Private Sub UserForm_Initialize()
HideTitleBar Me
End Sub
Private Sub UserForm_Click()
'Close this userform
Unload Me
End Sub
Sub Form_Show()
'Hide Excel
Application.Visible = False
'To close a form automatically
Application.OnTime Now, "Form_Close"
UserForm1.Show
End Sub
Sub Form_Close()
'To close a form automatically
Dim datWaitTime As Date
datWaitTime = TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 3)
Application.Wait datWaitTime
Unload UserForm1
Application.Visible = True
End Sub
Sub HideTitleBar(frm As Object)
Dim lngWindow As Long
Dim lFrmHdl As Long
lFrmHdl = FindWindowA(vbNullString, frm.Caption)
lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)
lngWindow = lngWindow And (Not WS_CAPTION)
Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow)
Call DrawMenuBar(lFrmHdl)
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
-
Apr 27th, 2007, 03:54 AM
#3
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|