CT SizeManager ActiveX Library
Version 1.0

CT SizeManager ActiveX Library allows you to restrict the minimum and maximum size of a specified window and automatically resizes and moves selected controls from Visual Basic applications. This library file is specifically designed for Visual Basic, but may work in any environment that supports ActiveX technology.



Classes

TrackSizeObject

ResizableControls










TrackSizeObject Class

Properties

Methods

Events

MinWidth

MinHeight

Capture


MaxWidth

MaxHeight







TrackSizeObject Class

This class allows you to restrict the minimum and maximum size of a window. Properties and methods of this class can be invoked after creating or referencing an object. You are free to create as many objects as you wish by declaring them As New.

Note:
• Always save your work before testing your application.
• Release the captured windows before debugging your application.
• If you halt the program instead of unloading the objects referencing this class, it will crash and so will the VB IDE.

As a general rule, define your own conditional compiler constant and set its value to -1 (True) only when your program is free of errors (see the example below).

#Const CT_TRACKSIZERUNTIME = -1 '0 = debug mode
...
#If CT_TRACKSIZERUNTIME Then
  ctTrackSizeManager.Capture hWnd
#End If
...



Properties

MinWidth, MinHeight

The MinWidth and MinHeight properties return/set the minimum width and height of the window to be captured, given in twips.

Syntax

MinWidth As Single
MinHeight As Single

Remarks

Set these properties to 0 whenever you want them to be ignored.

Sample Code

Dim ctTrackSizeManager As New TrackSizeObject

'limits the minimum size of the form to half of its dimensions
ctTrackSizeManager.MinWidth = 0.5 * Form1.Width
ctTrackSizeManager.MinHeight = 0.5 * Form1.Height

Set ctTrackSizeManager = Nothing



MaxWidth, MaxHeight

The MaxWidth and MaxHeight properties return/set the maximum width and height of the window to be captured, given in twips.

Syntax

MaxWidth As Single
MaxHeight As Single

Remarks

Set these properties to 0 whenever you want them to be ignored.

Sample Code

Dim ctTrackSizeManager As New TrackSizeObject

'limits the maximum width of the form to double of its width
ctTrackSizeManager.MaxWidth = 2 * Form1.Width

'suppose you don't care of the maximum height of the form
ctTrackSizeManager.MaxHeight = 0

Set ctTrackSizeManager = Nothing



Methods

Capture

The Capture method establishes a hook to capture messages to the specified window.

Syntax

Capture(ByVal hWnd As Long)

Parameters

hWnd

The handle to the window.

Return Values

None

Remarks

The Microsoft Windows operating environment identifies each form and control in an application by assigning it a handle (hWnd). The hWnd value is used with Windows API calls. Many Windows operating environment functions require the hWnd of a specific window as an argument. Because the value of this argument can change while a program is running, never store the hWnd value in a variable.

Sample Code

Dim ctTrackSizeManager As New TrackSizeObject

'limits the minimum size of the form to half of its dimensions
ctTrackSizeManager.MinWidth = 0.5 * Form1.Width
ctTrackSizeManager.MinHeight = 0.5 * Form1.Height

'limits the maximum size of the form to double of its dimensions
ctTrackSizeManager.MaxWidth = 2 * Form1.Width
ctTrackSizeManager.MaxHeight = 2 * Form1.Height

ctTrackSizeManager.Capture Form1.hWnd

Set ctTrackSizeManager = Nothing








ResizableControls Class

Properties

Methods

Events

Reference

Add


RefWidth

RefHeight

Resize






ResizableControls Class

This class automatically resizes and moves selected controls as specified when the reference object is resized. Properties and methods of this class can be invoked after creating or referencing an object. You are free to create as many objects as you wish by declaring them As New.



Properties

Reference

The Reference property returns/sets the object whose size is used as reference.

Syntax

Reference As Object

Remarks

When the Reference property is initialized, the library records its size and uses that size as reference for resizing until you change the reference object. The reference object may be any object expression that evaluates to an object (for instance, a Form, a PictureBox or a TextBox control).

Sample Code

Dim ctResizableControls As New ResizableControls

Set ctResizableControls.Reference = Form1

Set ctResizableControls = Nothing



RefWidth, RefHeight

The RefWidth and RefHeight properties return/set the width and height, given in twips, of the object whose size is used as reference.

Syntax

RefWidth As Single
RefHeight As Single

Remarks

Use these properties only when referencing the object (through the Reference property) conducts to undesirable results.

Sample Code

Dim ctResizableControls As New ResizableControls

ctResizableControls.RefWidth = Form1.Width
ctResizableControls.RefHeight = Form1.Height

Set ctResizableControls = Nothing



Methods

Add

The Add method adds controls to the resizable collection.

Syntax

Add(Control As Object, Optional ByVal lRatio As Single = 0, Optional ByVal tRatio As Single = 0, Optional ByVal wRatio As Single = 0, Optional ByVal hRatio As Single = 0)

Parameters

Control

The control to be resized.

lRatio

Horizontal movement of the Control.

tRatio

Vertical movement of the Control.

wRatio

Horizontal sizing of the Control.

hRatio

Vertical sizing of the Control.

Return Values

None

Remarks

When adding the control, its position and size are automatically recorded as a base for resizing. The lRatio, tRatio, wRatio and hRatio parameters should be assigned a value between 0 and 1.

Follow the expressions below to determine the correct values:

lRatio, tRatio
    newctlLeft = (lRatio * (oldrefWidth - newrefWidth)) + oldctlLeft
    newctlTop = (tRatio * (oldrefHeight - newrefHeight)) + oldctlTop
        0 = no movement; 0.5 = 50% movement; 1 = 100% movement.

wRatio, hRatio
    newctlWidth = (wRatio * (oldrefWidth - newrefWidth)) + oldctlWidth
    newctlHeight = (hRatio * (oldrefHeight - newrefHeight)) + oldctlHeight
        0 = no sizing; 0.5 = 50% sizing; 1 = 100% sizing.

Sample Code

Dim ctResizableControls As New ResizableControls

Set ctResizableControls.Reference = Form1

ctResizableControls.Add Label1, 1, 1, 0, 0
ctResizableControls.Add Text1, 1, 1, 1, 0

Set ctResizableControls = Nothing



Resize

The Resize method moves and resizes controls as specified when the reference object is resized.

Syntax

Resize(Optional ByVal ResizeNow As Boolean = True, Optional ByVal wSizeNow As Single = -1, Optional ByVal hSizeNow As Single = -1)

Parameters

ResizeNow

When False, no control will be moved or resized.

wSizeNow

The width used as reference, given in twips.

hSizeNow

The height used as reference, given in twips.

Return Values

None

Remarks

Set the reference object or dimensions, then add controls to the resizable collection before calling this method. The last two parameters of this method are usually used in conjunction with the RefWidth and RefHeight properties.

Sample Code

Private ctResizableControls As ResizableControls

Private Sub Form_Load()
  Set ctResizableControls = New ResizableControls

  Set ctResizableControls.Reference = Me

  ctResizableControls.Add Label1, 1, 1, 0, 0
  ctResizableControls.Add Text1, 1, 1, 1, 0
End Sub

Private Sub Form_Resize()
  ctResizableControls.Resize
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Set ctResizableControls = Nothing
End Sub






Requirements

• Windows 95/98, NT, 2000
• Visual Basic 6.0 RunTime files

You can get Visual Basic 6.0 RunTime files from Simtel.Net
http://www.simtel.net/pub/simtelnet/win95/dll.html






Contact

Reference for further information
http://softrunner.homestead.com

Comments, suggestions or bugs reports
cbotez@homestead.com






CT SizeManager ActiveX Library
Copyright © 2000, Cezar Botez
All rights reserved