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
Solved

Resizing form

Posted on 2004-09-29
5
214 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
Error when passing an argument to a vb6 that contains  '/' 7 40
VB6 ListBox Question 4 48
Dinamic report to Crosstab query 9 33
transition to visual .net from vb6 5 38
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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

860 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