home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / system / bug_de / no_bugs.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-01-10  |  11.2 KB  |  266 lines

  1. VERSION 2.00
  2. Begin Form frmBuggy 
  3.    Caption         =   "Bug-Free Form"
  4.    ClientHeight    =   4392
  5.    ClientLeft      =   864
  6.    ClientTop       =   1536
  7.    ClientWidth     =   6060
  8.    Height          =   4812
  9.    Left            =   816
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4392
  12.    ScaleWidth      =   6060
  13.    Top             =   1164
  14.    Width           =   6156
  15.    Begin ListBox lstChanges 
  16.       Height          =   1368
  17.       Left            =   1800
  18.       TabIndex        =   6
  19.       Top             =   2820
  20.       Width           =   2892
  21.    End
  22.    Begin Frame Frame1 
  23.       Caption         =   "Memory and Resources"
  24.       Height          =   1272
  25.       Left            =   600
  26.       TabIndex        =   3
  27.       Top             =   1080
  28.       Width           =   5172
  29.       Begin Label lblResources 
  30.          Caption         =   "lblResources"
  31.          Height          =   372
  32.          Left            =   240
  33.          TabIndex        =   0
  34.          Top             =   780
  35.          Width           =   4812
  36.       End
  37.       Begin Label lblMemory 
  38.          Caption         =   "lblMemory"
  39.          Height          =   312
  40.          Left            =   240
  41.          TabIndex        =   1
  42.          Top             =   360
  43.          Width           =   4812
  44.       End
  45.    End
  46.    Begin Label Label2 
  47.       Caption         =   "Memory changes in Form_Resize:"
  48.       Height          =   252
  49.       Left            =   1800
  50.       TabIndex        =   5
  51.       Top             =   2520
  52.       Width           =   3012
  53.    End
  54.    Begin Label Label1 
  55.       Alignment       =   2  'Center
  56.       BorderStyle     =   1  'Fixed Single
  57.       Caption         =   "Resize me and watch the memory stay!"
  58.       Height          =   372
  59.       Left            =   840
  60.       TabIndex        =   4
  61.       Top             =   120
  62.       Width           =   4320
  63.    End
  64.    Begin Label lblMode 
  65.       Alignment       =   2  'Center
  66.       BorderStyle     =   1  'Fixed Single
  67.       Caption         =   "lblMode"
  68.       Height          =   252
  69.       Left            =   600
  70.       TabIndex        =   2
  71.       Top             =   600
  72.       Width           =   5052
  73.    End
  74. ' No_bugs.frm
  75. ' Purpose:
  76. ' Demonstrates a bug-free way to resize controls on a form.
  77. ' Date:         Author:
  78. ' 01/10/94      Elliott Whitticar (71221.1413@CompuServe.com)
  79. Option Explicit
  80. '=============================================
  81. ' Module Level Variable Declaration Section
  82. '=============================================
  83. Dim CtlDelta() As SizeStruct    ' Stores size and location of controls
  84. Dim mlFreeSpace As Long         ' Free memory at end of loop in Form_Resize
  85. Dim mlOldSpace As Long          ' Free memory at start of loop in Form_Resize
  86. Sub Form_Load ()
  87. ' Description:
  88. '   This code to get the relative position of all the controls
  89. '   on the form is based on the "Elastic Controls Resize Proportionally"
  90. '   article by Bill Wilkey in the August/September issue of
  91. '   "Visual Basic Programmer's Journal."
  92.     Dim i As Integer                ' For-variable
  93.     Dim lfFormHeight As Single      ' Form's ScaleHeight
  94.     Dim lfFormWidth As Single       ' Form's ScaleWidth
  95.     'NOTE: For Screen, Form, and Printer objects the Width
  96.     'And Height properties are always measured in TWIPS.
  97.     'For the (non-MDI) Form and Printer objects the internal
  98.     'client area coordinate system can be changed to other
  99.     'scalings. For simplicity you may want to leave the
  100.     'coordinate system set to the VB default of TWIPS.
  101.     'However, some API routines require Pixels so you'll need
  102.     'to do conversion.
  103.     ' Begin UI Initialization
  104.     ' Perform any desired startup sizing of the
  105.     ' form here, before processing coordinates.
  106.     WindowState = NORMAL
  107.     ' Set desired scale mode here. Use the SCALEMODE property
  108.     ' for pre-defined scalings, use the
  109.     ' SCALETop,Left,Width,Height properties directly or the
  110.     ' SCALE method to define a custom coordinate system.
  111.     ' ScaleMode = TWIPS
  112.     ' Size the control dimension proportion array
  113.     ReDim CtlDelta(0 To Controls.Count - 1)
  114.     ' Loop through each control on the form and capture its
  115.     ' dimensions as a percentage of the scalable dimensions of
  116.     ' the form. (won't work for the line control)
  117.     lfFormHeight = Me.ScaleHeight
  118.     lfFormWidth = Me.ScaleWidth
  119.     For i = 0 To Controls.Count - 1
  120.         If TypeOf Controls(i) Is Line Then
  121.             CtlDelta(i).Top = Controls(i).Y1 / lfFormHeight
  122.             CtlDelta(i).Left = Controls(i).X1 / lfFormWidth
  123.             CtlDelta(i).Width = Controls(i).X2 / lfFormWidth
  124.             CtlDelta(i).Height = Controls(i).Y2 / lfFormHeight
  125.         Else
  126.             CtlDelta(i).Top = Controls(i).Top / lfFormHeight
  127.             CtlDelta(i).Left = Controls(i).Left / lfFormWidth
  128.             CtlDelta(i).Width = Controls(i).Width / lfFormWidth
  129.             CtlDelta(i).Height = Controls(i).Height / lfFormHeight
  130.         End If
  131.     Next
  132. End Sub
  133. Sub Form_Resize ()
  134. 'Description:   Proportionally resize and move controls based on
  135. '               relative positions in CtlDelta() array.
  136. 'Arguments:     N/A
  137. 'Return:        N/A
  138. '-----------------------------------------------------------------
  139. 'Date        Developer           Comments
  140. '01/10/95    E. Whitticar        Initial creation
  141. '*****************************************************************
  142.     '=============================================
  143.     'Local Constant/Variable Declaration Section
  144.     '=============================================
  145.     Dim i As Integer                ' For-variable
  146.     Dim lfFormHeight As Single       ' ScaleHeight of parent control
  147.     Dim lfFormWidth As Single        ' ScaleWidth of parent control
  148.     Dim lfLeft As Single            ' Left coordinate
  149.     Dim lfTop As Single             ' Top coordinate
  150.     Dim lfWidth As Single           ' Width
  151.     Dim lfHeight As Single          ' Height
  152.     ' Don't bother if we're just an icon
  153.     If WindowState = MINIMIZED Then Exit Sub
  154.     ' This will go faster if the form is not visible
  155.     Me.Hide
  156.     ' Save the amount of free memory before the loop.
  157.     mlOldSpace = GetFreeSpace(0)       ' Original Free Memory
  158.     ' Loop through each control on the form and reset the dimensions
  159.     ' as a percentage of the scalable dimensions of the form.
  160.     lfFormHeight = Me.ScaleHeight
  161.     lfFormWidth = Me.ScaleWidth
  162.     For i = 0 To Controls.Count - 1
  163.         If TypeOf Controls(i) Is Line Then
  164.             Controls(i).Y1 = lfFormHeight * CtlDelta(i).Top
  165.             Controls(i).X1 = lfFormWidth * CtlDelta(i).Left
  166.             Controls(i).X2 = lfFormWidth * CtlDelta(i).Width
  167.             Controls(i).Y2 = lfFormHeight * CtlDelta(i).Height
  168.         
  169.         ElseIf TypeOf Controls(i) Is Menu Then
  170.             ' Skip it
  171.         ElseIf TypeOf Controls(i) Is Timer Then
  172.             ' Skip it
  173.         Else
  174.             ' Get all the size and postion properties
  175.             lfTop = lfFormHeight * CtlDelta(i).Top
  176.             lfLeft = lfFormWidth * CtlDelta(i).Left
  177.             lfWidth = lfFormWidth * CtlDelta(i).Width
  178.             lfHeight = lfFormHeight * CtlDelta(i).Height
  179.             
  180.             If TypeOf Controls(i) Is TextBox Then
  181.                 ' Set all but the height, unless it's multiline
  182.                 If Controls(i).MultiLine = True Then
  183.                     Controls(i).Move lfLeft, lfTop, lfWidth, lfHeight
  184.                 Else
  185.                     Controls(i).Move lfLeft, lfTop, lfWidth
  186.                 End If
  187.             
  188.             ElseIf TypeOf Controls(i) Is Label Then
  189.                 ' Set only the position, don't change dimensions
  190.                 Controls(i).Move lfLeft, lfTop
  191.             
  192.             ElseIf TypeOf Controls(i) Is CommandButton Then
  193.                 ' Set only the position, don't change dimensions
  194.                 Controls(i).Move lfLeft, lfTop
  195.             
  196.             ElseIf TypeOf Controls(i) Is ComboBox Then
  197.                 ' Set all but the height, unless it's style 1
  198.                 If Controls(i).Style = 1 Then
  199.                     Controls(i).Move lfLeft, lfTop, lfWidth, lfHeight
  200.                 Else
  201.                     Controls(i).Move lfLeft, lfTop, lfWidth
  202.                 End If
  203.             
  204.             ElseIf TypeOf Controls(i) Is HScrollBar Then
  205.                 ' Set all but the height
  206.                 Controls(i).Move lfLeft, lfTop, lfWidth
  207.             ElseIf TypeOf Controls(i) Is VScrollBar Then
  208.                 ' Set all but the width
  209.                 Controls(i).Move lfLeft, lfTop
  210.                 Controls(i).Height = lfHeight * CtlDelta(i).Height
  211. ' **********
  212. ' Put special code for any controls you're using here.
  213.             ' ElseIf TypeOf Controls(i) Is SSPanel Then
  214.             '     ' If it doesn't automatically align to the top or bottom, move it.
  215.             '     If Controls(i).Align = 0 Then
  216.             '         Controls(i).Move lfLeft, lfTop, lfWidth, lfHeight
  217.             '     Else
  218.             '         ' Skip it -- it aligns itself automatically
  219.             '     End If
  220.             ' ElseIf TypeOf Controls(i) Is MhDateInput Then
  221.             '     ' Set all but the height
  222.             '     Controls(i).Move lfLeft, lfTop, lfWidth
  223.             ' ElseIf TypeOf Controls(i) Is MaskEdBox Then
  224.             '     ' Set all but the height
  225.             '     Controls(i).Move lfLeft, lfTop, lfWidth
  226. ' **********
  227.             Else
  228.                 ' For any other control, move it.
  229.                 Controls(i).Move lfLeft, lfTop, lfWidth, lfHeight
  230.             End If
  231.         End If
  232.     Next
  233.     mlFreeSpace = GetFreeSpace(0)       ' Free Memory
  234.     ' Perform any desired custom sizing/updates
  235.     ' of the controls here.
  236.     ' Restore visibility to the form
  237.     Me.Show
  238.     ShowResources
  239. End Sub
  240. Sub ShowResources ()
  241. ' Description:  Displays mode, memory and resources
  242.     ' Local variables
  243.     Dim llWinFlags As Long      ' Returned from GetWinFlags()
  244.     Dim llVerNum As Long        ' Returned from GetVersion(): DOS and Windows Version Nos.
  245.     Dim lsVersion As String     ' Windows version string
  246.     Dim lsFreeSpace As String   ' KB of free memory (formatted)
  247.     Dim lwVerWord As Integer    ' Low word of version
  248.     ' Set the label captions to indicate the windows mode and free memory
  249.     llVerNum = GetVersion()
  250.     lwVerWord = CInt(llVerNum And &HFFFF&)
  251.     lsVersion = "Windows " & CStr(lwVerWord And &HFF) & "." & CStr(lwVerWord \ 256)
  252.     llWinFlags = GetWinFlags()
  253.     If llWinFlags And WF_ENHANCED Then
  254.         lblMode.Caption = lsVersion & ", 386-enhanced mode"
  255.     ElseIf llWinFlags And WF_PMODE Then
  256.         lblMode.Caption = lsVersion & ", protected mode"
  257.     Else
  258.         lblMode.Caption = lsVersion & ", standard mode"
  259.     End If
  260.     lsFreeSpace = Format$(mlFreeSpace, "###,###,###")
  261.     lblMemory.Caption = "Free Memory:       " & lsFreeSpace & " Bytes"
  262.     lblResources.Caption = "Free Resources:  " & GetFreeSystemResources(GFSR_SYSTEMRESOURCES) & "% (system); " & GetFreeSystemResources(GFSR_GDIRESOURCES) & "% (GDI); " & GetFreeSystemResources(GFSR_USERRESOURCES) & "% (user)"
  263.     lstChanges.AddItem CStr(mlFreeSpace - mlOldSpace)
  264.     lstChanges.ListIndex = lstChanges.ListCount - 1
  265. End Sub
  266.