Results 1 to 13 of 13

Thread: Keep form from resizing too small

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Keep form from resizing too small

    I am trying to keep my form from being resized below 6000 x 7365. When the user goes below the size I want, the form temporarly get set to the smaller size and then gets reset with the code below. Is there any way to keep the form going smaller then what I want or at least keep the user from seeing the resizing.

    Code:
    Private Sub Form_Resize()
    
        frmMain.AutoRedraw = False
        Call LockWindowUpdate(frmMain.hWnd)
        
        If (frmMain.Width < 6000) Or (frmMain.Height < 7365) Then
            frmMain.Width = 6000
            frmMain.Height = 7365
            Call LockWindowUpdate(0)
            frmMain.AutoRedraw = True
            Exit Sub
        End If
        
        ' Resize rest of controls here...
        
        Call LockWindowUpdate(0)
        frmMain.AutoRedraw = True
    
    End Sub
    This space for rent...

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    Orlando
    Posts
    392

    This is a question for API Section

    Subclass the form, Intercept the GETMINMAXINFO Message, give it the dimension you like, the form won't get smaller than that. You can safely remove the above code in that case. I think VBWorld itself has an example of this. If not, take a moment to search the API intensive sites.

    Hope it helps.
    Abu Haider
    ____________________________
    100% Data Validation for the MS DataGrid Control. Plus Support for Custom and Foreign Lists, DatePicker and much more...
    The DataGridEnhancer


    I often point to a place where the problem has been discussed, instead of giving you the code that solves it. This is for good, may be you will understand some day...

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    You can disable resizing altogether if you want.

    Matthew Gates would probably have a really good answer to this, so i suggest you PM him

  4. #4
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Yeah, making the form static would probably be best.

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Talking

    This would probably be best:

    I posted it as a new thread, because I couldn't find this one, but then when I found this thread again, I adjusted the code so that it is perfect for your needs

    VB Code:
    1. 'In the form's code module
    2. Option Explicit
    3. Private Sub Form_Load()
    4.     'Save handle to the form.
    5.     gHW = Me.hwnd
    6.     'Begin subclassing.
    7.    Hook
    8. End Sub
    9. Private Sub Form_Unload(Cancel As Integer)
    10.     'Stop subclassing.
    11. Unhook
    12. End Sub
    13.  
    14. 'In a module
    15. Option Explicit
    16.  
    17.       Private Const GWL_WNDPROC = -4
    18.       Private Const WM_GETMINMAXINFO = &H24
    19.  
    20.       Private Type POINTAPI
    21.           x As Long
    22.           y As Long
    23.       End Type
    24.  
    25.       Private Type MINMAXINFO
    26.           ptReserved As POINTAPI
    27.           ptMaxSize As POINTAPI
    28.           ptMaxPosition As POINTAPI
    29.           ptMinTrackSize As POINTAPI
    30.           ptMaxTrackSize As POINTAPI
    31.       End Type
    32.  
    33.       Global lpPrevWndProc As Long
    34.       Global gHW As Long
    35.  
    36.       Private Declare Function DefWindowProc Lib "user32" Alias _
    37.          "DefWindowProcA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    38.           ByVal wParam As Long, ByVal lParam As Long) As Long
    39.       Private Declare Function CallWindowProc Lib "user32" Alias _
    40.          "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
    41.           ByVal hwnd As Long, ByVal Msg As Long, _
    42.           ByVal wParam As Long, ByVal lParam As Long) As Long
    43.       Private Declare Function SetWindowLong Lib "user32" Alias _
    44.          "SetWindowLongA" (ByVal hwnd As Long, _
    45.           ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    46.       Private Declare Sub CopyMemoryToMinMaxInfo Lib "KERNEL32" Alias _
    47.          "RtlMoveMemory" (hpvDest As MINMAXINFO, ByVal hpvSource As Long, _
    48.           ByVal cbCopy As Long)
    49.       Private Declare Sub CopyMemoryFromMinMaxInfo Lib "KERNEL32" Alias _
    50.          "RtlMoveMemory" (ByVal hpvDest As Long, hpvSource As MINMAXINFO, _
    51.           ByVal cbCopy As Long)
    52.  
    53.       Public Sub Hook()
    54.           'Start subclassing.
    55.           lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
    56.              AddressOf WindowProc)
    57.       End Sub
    58.  
    59.       Public Sub Unhook()
    60.           Dim temp As Long
    61.  
    62.           'Cease subclassing.
    63.           temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
    64.       End Sub
    65.  
    66.       Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _
    67.          ByVal wParam As Long, ByVal lParam As Long) As Long
    68.           Dim MinMax As MINMAXINFO
    69.  
    70.           'Check for request for min/max window sizes.
    71.           If uMsg = WM_GETMINMAXINFO Then
    72.               'necesary for the caption of an MDI child (when maximized)
    73.               '(Thanks to Marvin Chinchilla for this information)
    74.               WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, _
    75.         wParam, lParam)
    76.               'Retrieve default MinMax settings
    77.               CopyMemoryToMinMaxInfo MinMax, lParam, Len(MinMax)
    78.  
    79.               'Specify new minimum size for window.
    80.               MinMax.ptMinTrackSize.x = (6000 / Screen.TwipsPerPixelX)
    81.               MinMax.ptMinTrackSize.y = (7365 / Screen.TwipsPerPixelY)
    82.  
    83.               'Specify new maximum size for window.
    84.               MinMax.ptMaxTrackSize.x = Screen.Width
    85.               MinMax.ptMaxTrackSize.y = Screen.Height
    86.  
    87.               'Copy local structure back.
    88.               CopyMemoryFromMinMaxInfo lParam, MinMax, Len(MinMax)
    89.  
    90.               WindowProc = DefWindowProc(hw, uMsg, wParam, lParam)
    91.           Else
    92.               WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, _
    93.                  wParam, lParam)
    94.           End If
    95.       End Function

    Tell me what you think

  6. #6
    Matthew Gates
    Guest
    Perhaps this thread will help?

  7. #7
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    I would change your code to this so you dont have a resize to the width of the form just becasue someone went past the minimun size of the Hieght and vice versa.


    If Form1.Width < 6000 Then Form1.Width = 6000
    If Form1.Height < 7365 Then Form1.Height = 7365
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  8. #8

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    Mathew,
    I tried your suggestion from the other thread but one of the problems I had was the form did not seem to redraw right away during the form's mouse_move event. I think some of the problem with this is the mouse_move event for the other controls on my form were firing instead of the form's mouse_move event.

    da_silvy,
    I was able to subclass the form and keep it from resizing but when I did this I lost my status bar at the bottom of the form and a couple of my other controls did not look right.

    Thanks for the help!
    This space for rent...

  9. #9
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    perhaps on the form resize event, reset the control sizes?

    just a thought

  10. #10
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314
    da_silvy...


    Thanks for that code.. Works great!!
    Steve Stunning

  11. #11
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527


    No problems

    been a while since i posted on the board and that snippet was from a while ago

  12. #12
    Junior Member
    Join Date
    Sep 2002
    Location
    Richmond, VA
    Posts
    17

    Without the API...

    Just in case someone wants non api code...

    Put this in the FORM_Resize event and change the form name and sizes of course...

    If frmMDI.Width < 9000 Then
    frmMDI.Enabled = False
    frmMDI.Width = 9000
    frmMDI.Enabled = True
    ElseIf frmMDI.Height < 5300 Then
    frmMDI.Enabled = False
    frmMDI.Height = 5300
    frmMDI.Enabled = True
    End If

    When you disable the form, it won't continue to slide smaller...

    Chris

  13. #13
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Although the api code is longer, it should work more effectively.

    It will not allow them to resize below a predefined size.

    Also, why did you revive a thread that was satisfactorily answered 6 months ago

    Last edited by da_silvy; Dec 21st, 2002 at 07:46 PM.

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