sing_web
asked on
two simple question !
A vb program has three form, named main, left and right form. When
the program is executed, all form should appear on the screen.
- How to disable user to resize main form, while I want to select
sizeable for form and still have minimize, maximize and close button ?
- When minimal button is pressed in main form, other forms will also
be minimized ? And when main form is maximized, all other forms
should also be maximized ?
Thanks !
the program is executed, all form should appear on the screen.
- How to disable user to resize main form, while I want to select
sizeable for form and still have minimize, maximize and close button ?
- When minimal button is pressed in main form, other forms will also
be minimized ? And when main form is maximized, all other forms
should also be maximized ?
Thanks !
Simplest and most straightforward approach would be to use a MDI form to hold the three forms. Assuming the forms are equal size.. you can issue Tile Horizontal commands to always keep the three properly aligned and sized.. <smile>.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If your form has a fixed border, you can change the MinButton and MaxButton properties True in design time.
In the Resize event of the main form, you can set the WindowState of the other forms as well:
Option Explicit
Private Sub Form_Load()
Form2.Show
End Sub
Private Sub Form_Resize()
Form2.WindowState = Me.WindowState
End Sub
In the Resize event of the main form, you can set the WindowState of the other forms as well:
Option Explicit
Private Sub Form_Load()
Form2.Show
End Sub
Private Sub Form_Resize()
Form2.WindowState = Me.WindowState
End Sub
Actually, you can stop the user from resizing the form even if the BorderStyle is set to Sizable:
"HOWTO: Limit a Window's Minimum and Maximum Size"
http://support.microsoft.com/support/kb/articles/Q185/7/33.ASP
"HOWTO: Limit a Window's Minimum and Maximum Size"
http://support.microsoft.com/support/kb/articles/Q185/7/33.ASP
ASKER
bhess1 :
I think this code will not work because I had this idea before.
Sub Form1_Resize()
If Me.Height <> LockedFormHeight Or Me.Width<>LockedFormWidth Then
Me.Height=LockedFormHeight
Me.Width=LockedFormWidth
End If
End Sub
when you try to minimize it, you will get error.
I think this code will not work because I had this idea before.
Sub Form1_Resize()
If Me.Height <> LockedFormHeight Or Me.Width<>LockedFormWidth Then
Me.Height=LockedFormHeight
Me.Width=LockedFormWidth
End If
End Sub
when you try to minimize it, you will get error.
ASKER
bhee1 :
your second answer should put in the form_activate, right ?
your second answer should put in the form_activate, right ?
Why not set the form to Fixed-Single, and enable the min and max buttons?
"when you try to minimize it, you will get error."
That's why you check the WindowState, and only reset the size if it is vbNormal.
This code works best in the form_resize event. You could add the resizing code to form_load, but form_resize is called the first time you show a form as well.
That's why you check the WindowState, and only reset the size if it is vbNormal.
This code works best in the form_resize event. You could add the resizing code to form_load, but form_resize is called the first time you show a form as well.
Hi
Your question is not simple, and Complete solytion require subclassing, because Form_resize event occure AFTER resizing, so you'll see changing size. Anyway, here is a code
'--bas module code
Type POINTAPI
x As Long
y As Long
End Type
Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Const WM_SYSCOMMAND = &H112
Const SC_MINIMIZE = &HF020&
Const SC_MAXIMIZE = &HF030&
Const SC_CLOSE = &HF060&
Public Const GWL_WNDPROC = (-4)
Const GWL_STYLE = (-16)
Const WS_MAXIMIZE = &H1000000
Const WM_GETMINMAXINFO = &H24
Public OldProc As Long
Public StartWidth As Long
Public StartHeight As Long
Dim MMinfo As MINMAXINFO
Public Function WndProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case wMsg
Case WM_GETMINMAXINFO
If GetWindowLong(hwnd, GWL_STYLE) And WS_MAXIMIZE Then
WndProc = CallWindowProc(OldProc, hwnd, wMsg, wParam, lParam)
Exit Function
End If
CopyMemory MMinfo, ByVal lParam, LenB(MMinfo)
' Max/Min size when tracking
MMinfo.ptMinTrackSize.x = StartWidth
MMinfo.ptMinTrackSize.y = StartHeight
MMinfo.ptMaxTrackSize.x = StartWidth
MMinfo.ptMaxTrackSize.y = StartHeight
CopyMemory ByVal lParam, MMinfo, LenB(MMinfo)
Exit Function
Case WM_SYSCOMMAND
Select Case wParam
Case SC_MINIMIZE
'All your code here to minimize other windows
Case SC_CLOSE
'Close code
Case SC_MAXIMIZE
'Max_Code
'All your code here to maximize other windows
End Select
End Select
WndProc = CallWindowProc(OldProc, hwnd, wMsg, wParam, lParam)
End Function
'--Form code--
Private Sub Form_Load()
StartWidth = Width / Screen.TwipsPerPixelX
StartHeight = Height / Screen.TwipsPerPixelY
OldProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
SetWindowLong Me.hwnd, GWL_WNDPROC, OldProc
End Sub
'Don't stop this code from IDE - it cause GPF
' I thing it's a complete solution, but post it as comment because you can choose more easy (but not complite) way from previous code
Cheers
Your question is not simple, and Complete solytion require subclassing, because Form_resize event occure AFTER resizing, so you'll see changing size. Anyway, here is a code
'--bas module code
Type POINTAPI
x As Long
y As Long
End Type
Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Const WM_SYSCOMMAND = &H112
Const SC_MINIMIZE = &HF020&
Const SC_MAXIMIZE = &HF030&
Const SC_CLOSE = &HF060&
Public Const GWL_WNDPROC = (-4)
Const GWL_STYLE = (-16)
Const WS_MAXIMIZE = &H1000000
Const WM_GETMINMAXINFO = &H24
Public OldProc As Long
Public StartWidth As Long
Public StartHeight As Long
Dim MMinfo As MINMAXINFO
Public Function WndProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case wMsg
Case WM_GETMINMAXINFO
If GetWindowLong(hwnd, GWL_STYLE) And WS_MAXIMIZE Then
WndProc = CallWindowProc(OldProc, hwnd, wMsg, wParam, lParam)
Exit Function
End If
CopyMemory MMinfo, ByVal lParam, LenB(MMinfo)
' Max/Min size when tracking
MMinfo.ptMinTrackSize.x = StartWidth
MMinfo.ptMinTrackSize.y = StartHeight
MMinfo.ptMaxTrackSize.x = StartWidth
MMinfo.ptMaxTrackSize.y = StartHeight
CopyMemory ByVal lParam, MMinfo, LenB(MMinfo)
Exit Function
Case WM_SYSCOMMAND
Select Case wParam
Case SC_MINIMIZE
'All your code here to minimize other windows
Case SC_CLOSE
'Close code
Case SC_MAXIMIZE
'Max_Code
'All your code here to maximize other windows
End Select
End Select
WndProc = CallWindowProc(OldProc, hwnd, wMsg, wParam, lParam)
End Function
'--Form code--
Private Sub Form_Load()
StartWidth = Width / Screen.TwipsPerPixelX
StartHeight = Height / Screen.TwipsPerPixelY
OldProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf WndProc
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
SetWindowLong Me.hwnd, GWL_WNDPROC, OldProc
End Sub
'Don't stop this code from IDE - it cause GPF
' I thing it's a complete solution, but post it as comment because you can choose more easy (but not complite) way from previous code
Cheers
ASKER
bhee1 :
your second answer should put in the form_activate, right ?
your second answer should put in the form_activate, right ?
No, the second answer also goes into the resize event