Results 1 to 12 of 12

Thread: RESOLVED - Resize/repos controls with API form min width/height

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    RESOLVED - Resize/repos controls with API form min width/height

    I implemented a minimum form size by like so:

    VB Code:
    1. 'An excerpt, not everything.
    2. Private booResize
    3.  
    4. Private Sub Form_Resize()
    5.  
    6.    If booResize Then    'To prevent an infinite loop due to Form_Resize().
    7.       If Me.WindowState <> vbMinimized Then
    8.          booResize = False
    9.          If Me.Height < 5400 Then
    10.             Me.Height = 5400
    11.          End If
    12.          If Me.Width < 6150 Then
    13.             Me.Width = 6150
    14.          End If
    15.          'blah blah code for controls
    16.       End If
    17.    End If
    18. End Sub

    Problem is, you can still drag the border to less than the minimum. And that causes a flicker. The effect I wanted was something similar to Yahoo chat windows, wherein you can't drag into the minimum. Can someone pls help me and give me code, especially if its API?
    Last edited by leinad31; May 3rd, 2003 at 04:34 AM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    *bump

  3. #3
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    This has been answered numerous times.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    I couldn't get crptcblade's to work. I'm waiting for his reply.

    I also couldn't get this to work.

    http://www.vbforums.com/showthread.p...oto=nextoldest

    I got "Invalid property value", but it hanged so I don't know where in the code.

    What I need is the code that will apply to several instances of a template form. Its for a chat program, min dimensions for each chat form.

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by leinad31
    I couldn't get crptcblade's to work. I'm waiting for his reply.
    If it can wait, then I'll be able to put together a more flexible version later on tonight.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    It can wait. Thanks.

  7. #7
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    The code you're trying to use is setup to handle subclassing a single form/window.

    In order to use this on multiple instances, you need to add handling for each window, i.e.

    In a Module
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const GWL_WNDPROC = (-4)
    4. Private Const WM_GETMINMAXINFO = &H24
    5.  
    6. Private Type POINTAPI
    7.         x As Long
    8.         y As Long
    9. End Type
    10.  
    11. Private Type MINMAXINFO
    12.         ptReserved As POINTAPI
    13.         ptMaxSize As POINTAPI
    14.         ptMaxPosition As POINTAPI
    15.         ptMinTrackSize As POINTAPI
    16.         ptMaxTrackSize As POINTAPI
    17. End Type
    18.  
    19. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    20. 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
    21. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    22. Private Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    23. Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    24. Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
    25.  
    26. Public Sub SubClass(ByVal hwnd As Long)
    27.   Dim lPrevWndProc As Long
    28.  
    29.   If GetProp(hwnd, "MinSizeHandler") <> 0 Then Exit Sub
    30.   lPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
    31.   Call SetProp(hwnd, "MinSizeHandler", lPrevWndProc)
    32. End Sub
    33.  
    34. Public Sub RemoveSubClass(ByVal hwnd As Long)
    35.   If GetProp(hwnd, "MinSizeHandler") = 0 Then Exit Sub
    36.   Call SetWindowLong(hwnd, GWL_WNDPROC, GetProp(hwnd, "MinSizeHandler"))
    37.   Call SetProp(hwnd, "MinSizeHandler", 0)
    38. End Sub
    39.  
    40. Private Function WindowProc(ByVal hwnd As Long, ByVal nMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    41.   Dim tMINMAX As MINMAXINFO
    42.   Dim lPrevWndProc As Long
    43.  
    44.   lPrevWndProc = GetProp(hwnd, "MinSizeHandler")
    45.  
    46.   If nMsg = WM_GETMINMAXINFO Then
    47.     Call CallWindowProc(lPrevWndProc, hwnd, nMsg, wParam, lParam)
    48.     Call CopyMemory(tMINMAX, ByVal lParam, Len(tMINMAX))
    49.     tMINMAX.ptMinTrackSize.x = 200
    50.     tMINMAX.ptMinTrackSize.y = 200
    51.     Call CopyMemory(ByVal lParam, tMINMAX, Len(tMINMAX))
    52.     WindowProc = DefWindowProc(hwnd, nMsg, wParam, lParam)
    53.   Else
    54.     WindowProc = CallWindowProc(lPrevWndProc, hwnd, nMsg, wParam, lParam)
    55.   End If
    56. End Function
    Example Usage:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.   Dim oForm As Form1
    5.  
    6.   Set oForm = New Form1
    7.   oForm.Show
    8. End Sub
    9.  
    10. Private Sub Form_Load()
    11.   SubClass hwnd
    12. End Sub
    13.  
    14. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    15.   RemoveSubClass hwnd
    16. End Sub

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Thanks. I think I figured out why I got the "Invalid property value". I hadn't deleted my Form_Resize() code, stupid me.

    In my original code, I also resized and/or repositioned controls on the form. Where do I insert the code for this with your function? And how do I refer to the controls? I'm resizing/repositioning 2 frames and their contents: richtextbox, labels, command button, image controls (control arrays), and line controls (control arrays).
    Last edited by leinad31; May 2nd, 2003 at 03:00 PM.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    *bump

  10. #10
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    VB Code:
    1. Private Sub Form_Resize()
    2.      If Me.WindowState = vbNormal Then
    3.         Me.Width = 4800
    4.         Me.Height = 3600
    5.      End If
    6. End Sub

    Works for me

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Thanks, it does work. Strangely I kept getting erros last night.

  12. #12
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Perphaps u were just checking for the windowstate = vb minimzed and not for vbmaximized...I have put for vbnormal....hence it works...

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