|
-
Aug 25th, 2000, 05:22 PM
#1
Thread Starter
Frenzied Member
here is the link:
http://www.vb-world.net/tips/tip489.html
now what I wanted to know was, how can I stop my form from going smaller then what I set it to in diesign time, and how can I make it enlarge it evenly, like so they cant make it into a rectange becuase my form is squarem, so I dont want my form to go from:
Code:
_____________
| |
| |
| |
| |
| |
|____________|
to:
______________________________________
| |
| |
| |
| |
| |
| |
| |
| |
| |
|_____________________________________|
NXSupport - Your one-stop source for computer help
-
Aug 25th, 2000, 05:29 PM
#2
Fanatic Member
This takes care of the minimum width / height:
Code:
Public Sub Form_Resize()
If Me.Width < minWid Then Me.Width = minWid
If Me.Height < minHgt Then Me.Height = minHgt
End Sub
Where minHgt is the minimum height and minWid is the minimum width.
Now there is a factor, such as Form.Height / Form.Width that you can add to the Form_Resize event to make sure it always has a fixed Aspect Ratio, as graphics artists call it.
[Edited by HaxSoft on 08-25-2000 at 06:32 PM]
-
Aug 25th, 2000, 05:29 PM
#3
Code:
Private Sub Form_Resize()
Me.Height = Me.Width
End Sub
-
Aug 25th, 2000, 09:04 PM
#4
Changing the Width and Height properties in the Resize event is the simple way of doing it. It does cause some flickering and it doesn't keep your form in a square form when it's maximized.
To manage this you have to resort to API and sub-classing your form. If you haven't done any subclassing before then here's a bit of an advice: Do NOT use the End statement in your code and do NOT use the End button on the VB toolbar.
Unload the form with the Unload statement or use the close button of the form. Otherwise you will get a GPF.
Now that this have been mentioned lets go over to the code.
Add the following to a BAS code module:
Code:
Private Declare Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private 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" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long)
Private Const GWL_WNDPROC = (-4)
Private Const WM_GETMINMAXINFO = &H24
Private Const WM_SIZING = &H214
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Private lngHwnd As Long
Private lngPrevWndProc As Long
Public Sub HookForm(frm As Form)
lngHwnd = frm.hwnd
lngPrevWndProc = SetWindowLong(lngHwnd, GWL_WNDPROC, AddressOf WinProc)
End Sub
Public Sub UnhookForm()
SetWindowLong lngHwnd, GWL_WNDPROC, lngPrevWndProc
End Sub
Public Function WinProc( _
ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Select Case uMsg
Case WM_GETMINMAXINFO
Dim inf As MINMAXINFO
CopyMemory inf, ByVal lParam, Len(inf)
inf.ptMaxSize.x = Screen.Height \ Screen.TwipsPerPixelX
inf.ptMaxTrackSize.x = Screen.Height \ Screen.TwipsPerPixelX
inf.ptMinTrackSize.x = 30 'min width in pixels
inf.ptMinTrackSize.y = 30 'min height in pixels
CopyMemory ByVal lParam, inf, Len(inf)
Case WM_SIZING
Dim r As RECT, iWidth%, iHeight%
CopyMemory r, ByVal lParam, Len(r)
iWidth = r.Right - r.Left
iHeight = r.Bottom - r.Top
If iWidth < iHeight Then
iHeight = iWidth
Else
iWidth = iHeight
End If
r.Bottom = r.Top + iHeight
r.Right = r.Left + iWidth
CopyMemory ByVal lParam, r, Len(r)
End Select
WinProc = CallWindowProc(lngPrevWndProc, hw, uMsg, wParam, lParam)
End Function
To use the code add the following code to the Load and Unload events of the form:
Code:
Private Sub Form_Load()
HookForm Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookForm
End Sub
Do not forget to call the UnhookForm procedure in the Unload event.
Good luck!
-
Aug 25th, 2000, 09:06 PM
#5
Thread Starter
Frenzied Member
NXSupport - Your one-stop source for computer help
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
|