|
-
Aug 16th, 2000, 09:30 AM
#1
Does anyone know how I can limit the resizing of a form?
I tried using the Form_Resize event but it triggers only after the user resizes the form.
Any ideas?
-
Aug 16th, 2000, 09:51 AM
#2
Lively Member
you can use subclassing, which i think is mentioned in this web siote....
or you can set the width and height in the resize event programmitically...
YC Sim
Teenage Programmer
UIN 37903254
-
Aug 16th, 2000, 09:57 AM
#3
Try this:
Code:
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Dim LockWindow As Boolean
Dim iWidth As Integer
Dim iHeight As Integer
Private Sub Form_Load()
'Save the initial dimensions
iWidth = Me.Width
iHeight = Me.Height
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Unlock the Window when the Mouse is moved over it
LockWindowUpdate 0&
End Sub
Private Sub Form_Resize()
If Me.WindowState <> vbMinimized Then
Static FirstLoad
'If this is the First time the Window is loading then don't lock it
If FirstLoad = False Then
FirstLoad = True
LockWindow = True
Exit Sub
End If
'Lock the Window when the User tries to resize it
If LockWindow = True Then
'Restore the dimensions
Me.Width = iWidth
Me.Height = iHeight
LockWindowUpdate Me.hwnd
End If
Else: FirstLoad = False
End If
End Sub
-
Aug 16th, 2000, 10:02 AM
#4
Or you can Subclass it (a little better than using LockWindowUpdate)
Code for a Module.
Code:
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong 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
Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Const GWL_WNDPROC = (-4)
Const WM_SYSCOMMAND = &H112
Const WM_SIZE = &H5
Const WM_ENTERSIZEMOVE = &H231
Const WM_SIZING = &H214
Const WM_EXITSIZEMOVE = &H232
Public fHeight As Integer
Public fWidth As Integer
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_SIZING Then
LockWindowUpdate hwnd
End If
If wMsg& = WM_EXITSIZEMOVE Then
Form1.Width = fWidth
Form1.Height = fHeight
LockWindowUpdate 0&
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
Code for Form.
Code:
Private Sub Form_Load()
fHeight = Me.Height
fWidth = Me.Width
SubClassWnd Me.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd Me.hwnd
End Sub
-
Aug 16th, 2000, 10:17 AM
#5
_______
<?>
this would require a little work as you would need to add ctrl buttons, but you could just use a form with no border.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 16th, 2000, 10:19 AM
#6
I thought he meant limiting the resizing when the BorderStyle is set to 2. Otherwise, you can just change it to Fixed Single or Fixed Dialog.
-
Aug 16th, 2000, 10:44 AM
#7
_______
<?>
I don't know exactly what he means either.....I've just used the fixed or no border from time to time so it was just a thought.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 16th, 2000, 03:15 PM
#8
V(ery) Basic:
In the code you pasted above, what type should lParam be in the WindowProc?
Because if I say "lParam As MINMAXINFO" then I can't CallWindowProc if I get other messages that their lParam is of Long type.
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
|