Solved

Resizing form

Posted on 2004-09-29
5
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

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 86

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 86

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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