Solved

Resizing form

Posted on 2004-09-29
5
210 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
Comment Utility
' -------------------------------------------------------
' 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
Comment Utility
The values are measured in Pixels, not Twips.

~IM
0
 
LVL 9

Author Comment

by:riyasjef
Comment Utility
Thanks
0
 
LVL 9

Author Comment

by:riyasjef
Comment Utility
Hi

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

Riyasjef
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

763 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

14 Experts available now in Live!

Get 1:1 Help Now