Results 1 to 2 of 2

Thread: Someone wanted code to set minimum width and height of form

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Lightbulb Someone wanted code to set minimum width and height of form

    I'm pretty sure someone asked for this, but I can't find the original thread....

    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 = 200
    81.               MinMax.ptMinTrackSize.y = 200
    82.  
    83.               'Specify new maximum size for window.
    84.               MinMax.ptMaxTrackSize.x = 250
    85.               MinMax.ptMaxTrackSize.y = 250
    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

    Hope that works for whoever it was

  2. #2
    Dreamlax
    Guest
    Hey wow cool... I'll take that! lol .

    I'm working on a shell, and I've got as far as changing what all the standard windows look like (IE the title bar has changed and so has the border) but if it's resized to small, VB crashes... and if I just do a:

    VB Code:
    1. If Me.Height > 500 Then Me.Height = 500

    It looks all flickery dickery dock.

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