Solved

Resizing form

Posted on 2004-09-29
5
211 Views
Last Modified: 2010-05-02
Hi
I am using Vb6 and created a SDI form. i would like my form to be resized and Controls in the form to be arranged and positioned properly according to the form size. i have written code for arranging and positioning controls. But i need to restrict the users from resizing(reducing) the form after a specified Hieght and width. i tried the following statements in the Form resize event
 
    If Me.Width <= 9000 Then Me.Width = 9000
    If Me.Height < 8000 Then Me.Height = 8000

it works, but when Form is tried to resize below this range, Form continues to blink and only on the release of mouse drag it retains to size Width =9000 and height =8000.
Hoping for a solution
Thanks

 
0
Comment
Question by:riyasjef
  • 3
  • 2
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12182810
' -------------------------------------------------------
' Form1
' -------------------------------------------------------
Option Explicit

Private Sub Form_Load()
    HookWindow Me.hWnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
    HookWindow Me.hWnd
End Sub

' -------------------------------------------------------
' Module1
' -------------------------------------------------------
Option Explicit

Public Type POINTAPI
    x As Long
    y As Long
End Type

Public Type MINMAXINFO
    ptReserved As POINTAPI
    ptMaxSize As POINTAPI
    ptMaxPosition As POINTAPI
    ptMinTrackSize As POINTAPI
    ptMaxTrackSize As POINTAPI
End Type

Public 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
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)

Public Const GWL_WNDPROC As Long = (-4)
Public Const WM_GETMINMAXINFO = &H24

Public lPrevProc As Long

Public Sub HookWindow(ByVal lHandle As Long)
    If lPrevProc = 0 Then
        lPrevProc = SetWindowLong(lHandle, GWL_WNDPROC, AddressOf HookProc)
    Else
        Call SetWindowLong(lHandle, GWL_WNDPROC, lPrevProc)
    End If
End Sub

Public Function HookProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim minMax As MINMAXINFO

    Select Case uMsg
        Case WM_GETMINMAXINFO
            CopyMemory minMax, ByVal lParam, LenB(minMax)
                       
            ' don't allow form to be sized below minimum size
            minMax.ptMinTrackSize.x = 400                                         ' <-------------- Change these values
            minMax.ptMinTrackSize.y = 250
                       
            CopyMemory ByVal lParam, minMax, LenB(minMax)
            HookProc = 1
            Exit Function
                         
    End Select
   
    HookProc = CallWindowProc(lPrevProc, hWnd, uMsg, wParam, lParam)
End Function
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 12182820
The values are measured in Pixels, not Twips.

~IM
0
 
LVL 9

Author Comment

by:riyasjef
ID: 12183182
Thanks
0
 
LVL 9

Author Comment

by:riyasjef
ID: 12187496
Hi

With that, program gets hanged when  tried to use break points  Any idea?

Riyasjef
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12189567
What we have done is subclassed the form.  This means that we have replaced the forms normal message processing loop with our own.  You have to be careful when working with subclassed forms and the IDE as you may get funny results.  Do not press the Stop button in the IDE as this will prevent the old message loop from being placed back into the system.  Since the IDE is tied in the the app in debug mode with breakpoints, you can cause the app to crash.  Instead, always use the close button on the form.

When working with subclassing/hooking, always save your work before running the app since it may cause the app and the IDE to crash and close immediately.  Sometimes the only way to do something is with subclassing so you just have to learn to live with it.

What are you troubleshooting?  Perhaps I can help...

~IM
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now