Results 1 to 5 of 5

Thread: I read tip number 489 on how to resize the form, and I have a few questions about it

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    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

  2. #2
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593
    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]

  3. #3
    Guest
    Code:
    Private Sub Form_Resize()
        Me.Height = Me.Width
    End Sub

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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!

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks alot
    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
  •  



Click Here to Expand Forum to Full Width