home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD71996272000.psc / ctlProgBar.ctl (.txt) < prev   
Encoding:
Visual Basic Form  |  2000-06-19  |  42.6 KB  |  983 lines

  1. VERSION 5.00
  2. Begin VB.UserControl ProgBar 
  3.    Alignable       =   -1  'True
  4.    BackColor       =   &H00FFFFFF&
  5.    CanGetFocus     =   0   'False
  6.    ClientHeight    =   1290
  7.    ClientLeft      =   0
  8.    ClientTop       =   0
  9.    ClientWidth     =   4425
  10.    ClipControls    =   0   'False
  11.    DrawWidth       =   50
  12.    FillColor       =   &H00FF0000&
  13.    BeginProperty Font 
  14.       Name            =   "Arial"
  15.       Size            =   8.25
  16.       Charset         =   0
  17.       Weight          =   400
  18.       Underline       =   0   'False
  19.       Italic          =   0   'False
  20.       Strikethrough   =   0   'False
  21.    EndProperty
  22.    ForeColor       =   &H00FF0000&
  23.    ScaleHeight     =   86
  24.    ScaleMode       =   3  'Pixel
  25.    ScaleWidth      =   295
  26.    ToolboxBitmap   =   "ctlProgBar.ctx":0000
  27. Attribute VB_Name = "ProgBar"
  28. Attribute VB_GlobalNameSpace = False
  29. Attribute VB_Creatable = True
  30. Attribute VB_PredeclaredId = False
  31. Attribute VB_Exposed = False
  32. '===========================================================
  33. '= ProgBar Control V2.1                                    =
  34. '= --------------------                                    =
  35. '= (C)2000 NJE                                             =
  36. '= NE94252@netscape.net                                    =
  37. '=                                                         =
  38. '= You may use this source code within your own            =
  39. '= applications, just give me a shout.                     =
  40. '= You may not distribute it on a website or ftp site      =
  41. '= without my express permission.                          =
  42. '===========================================================
  43. '= Updates:                                                =
  44. '= --------                                                =
  45. '= V1.1          - Addition of the VerticalText property.  =
  46. '=               - General code clean up.                  =
  47. '=               - Addition of the ability to play a wav   =
  48. '=                 file at 100%.                           =
  49. '= V1.2          - Addition of gradient fill (BarStyle).   =
  50. '=               - All bar and background drawing handled  =
  51. '=                 by APIs to speed things up.             =
  52. '=               - The ability to wait for the sound to    =
  53. '=                 finish or not before releasing to code. =
  54. '= V1.2.1        - Fixed a problem with the use of         =
  55. '=                 reserved words.                         =
  56. '= V2.0          - Used DCs to remove flicker.             =
  57. '=               - Added the font choice.                  =
  58. '= V2.0.1        - Removed the half developed shadow text  =
  59. '=                 property I had been working on, oops!   =
  60. '= V2.1          - Nightmare! Corrected a problem with the =
  61. '=                 control not drawing correctly when      =
  62. '=                 resized. This was due to the DC being   =
  63. '=                 created for the initial size of the     =
  64. '=                 user control and not changing for the   =
  65. '=                 life of the user control.               =
  66. '===========================================================
  67. '= RunTime Properties: (Aphabetical order)                 =
  68. '= -------------------                                     =
  69. '= BackColour    - The back ground colour of the bar.      =
  70. '=                 Standard colour range.                  =
  71. '= BarEndColour  - The colour the bar fades into when the  =
  72. '=                 'BarStyle' is Gradient.                 =
  73. '=                 Standard colour range.                  =
  74. '= BarStartColour- The colour the bar fades from or the    =
  75. '=                 colour of the bar if the 'BarStyle' is  =
  76. '=                 Solid. Standard colour range.           =
  77. '= BarStyle      - The style of bar fill (gradient or      =
  78. '=                 solid).                                 =
  79. '=                 0 = Gradiant, 1 = Solid.                =
  80. '= BorderStyle   - Standard border style.                  =
  81. '=                 0 = Flat, 1 = ThreeD                    =
  82. '= FillDirection - The direction the bar should fill.      =
  83. '=                 0 = Up, 1 = Down, 2 = Left, 3 = Right   =
  84. '= Font          - The font to use for the text.           =
  85. '=                 Standard font dialog.                   =
  86. '= FontColour    - The colour of the text displayed.       =
  87. '=                 Standard colour range.                  =
  88. '= Max           - The upper limit of the bar.             =
  89. '=                 Long value, -2147483648 to 2147483647   =
  90. '= Message       - The message to display in the bar.      =
  91. '=                 String.                                 =
  92. '= Min           - The lower limit of the progress bar.    =
  93. '=                 Long value, -2147483648 to 2147483647   =
  94. '= Percent       - The current bar percentage.             =
  95. '=                 Byte value, 0 to 100 (obviously :))     =
  96. '= PlaySound     - Flag to indicate the sound file         =
  97. '=                 specified in the SoundToPlay property   =
  98. '=                 sould be played when 100% is reached.   =
  99. '=                 (TRUE, FALSE)                           =
  100. '= ShowMessage   - Flag to indicate the message should be  =
  101. '=                 shown. (TRUE, FALSE)                    =
  102. '= ShowPercent   - Flag to incicate the current percentage =
  103. '=                 should be shown. (TRUE, FALSE)          =
  104. '= ShowValue     - Flag to indicate the current value      =
  105. '=                 should be shown. (TRUE, FALSE)          =
  106. '= SoundToPlay   - A string value holding the path and     =
  107. '=                 name of the wav file to play @ 100%.    =
  108. '= Value         - The current value of the progress bar.  =
  109. '=                 Long value, -2147483648 to 2147483647   =
  110. '= VerticalText  - Flag to indicate that the text should   =
  111. '=                 be written top to bottom, useful for up =
  112. '=                 or down progress bars. (TRUE, FALSE)    =
  113. '= WaitForSound  - This flag indicates that the code will  =
  114. '=                 susspend until the sound file played at =
  115. '=                 100% has finished playing.  If one's    =
  116. '=                 set to play that is. (TRUE, FALSE)      =
  117. '===========================================================
  118. '= Notes:                                                  =
  119. '= ------                                                  =
  120. '= 1. You can either show the percentage or value or       =
  121. '=    neither.  You can't show both.  Setting one will     =
  122. '=    disable the other.                                   =
  123. '= 2. Setting the value above the 'Max' or below the 'Min' =
  124. '=    will result in the value being set to the 'Max' or   =
  125. '=    'Min'.                                               =
  126. '= 3. Setting the percent above 100 or below 0 will result =
  127. '=    in the percentage being changed to 100 or 0.         =
  128. '= 4. Setting the 'Max' below the 'Min' will result in the =
  129. '=    'Max' being set to the 'Min' + 1.                    =
  130. '= 5. Setting the 'Min' below the 'Max' will result in the =
  131. '=    'Min' being set to the 'Max' - 1.                    =
  132. '= 6. Adjusting either the 'Max' or the 'Min' will cause   =
  133. '=    the 'Value' to be recalculated.                      =
  134. '= 7. If the 'BarStyle' is set to solid the colour of the  =
  135. '=    bar is defined by the 'BarStartColour' property.     =
  136. '= 8. If a sound is playing and the flag to play one at    =
  137. '=    100% is set the currently playing file will stop and =
  138. '=    the specified one will start.                        =
  139. '===========================================================
  140. '= Have fun! NJE                                           =
  141. '===========================================================
  142. Option Explicit
  143. 'API and constant to play wav file.
  144. Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  145. Private Const SND_SYNC = &H0
  146. Private Const SND_ASYNC = &H1
  147. 'API's, types and constants for the bar fills and text generation.
  148. Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
  149. Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
  150. Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal X As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
  151. Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
  152. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  153. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  154. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
  155. Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  156. Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As Size) As Long
  157. Private Declare Function GetTextMetrics Lib "gdi32" Alias "GetTextMetricsA" (ByVal hdc As Long, lpMetrics As TEXTMETRIC) As Long
  158. Private Type TEXTMETRIC
  159.     tmHeight As Long
  160.     tmAscent As Long
  161.     tmDescent As Long
  162.     tmInternalLeading As Long
  163.     tmExternalLeading As Long
  164.     tmAveCharWidth As Long
  165.     tmMaxCharWidth As Long
  166.     tmWeight As Long
  167.     tmOverhang As Long
  168.     tmDigitizedAspectX As Long
  169.     tmDigitizedAspectY As Long
  170.     tmFirstChar As Byte
  171.     tmLastChar As Byte
  172.     tmDefaultChar As Byte
  173.     tmBreakChar As Byte
  174.     tmItalic As Byte
  175.     tmUnderlined As Byte
  176.     tmStruckOut As Byte
  177.     tmPitchAndFamily As Byte
  178.     tmCharSet As Byte
  179. End Type
  180. Private Type Size
  181.     cx As Long
  182.     cy As Long
  183. End Type
  184. Private Type RECT
  185.     vLeft    As Long
  186.     vTop     As Long
  187.     vRight   As Long
  188.     vBottom  As Long
  189. End Type
  190. Private Type LOGFONT
  191.   lfHeight As Long
  192.   lfWidth As Long
  193.   lfEscapement As Long
  194.   lfOrientation As Long
  195.   lfWeight As Long
  196.   lfItalic As Byte
  197.   lfUnderline As Byte
  198.   lfStrikeOut As Byte
  199.   lfCharSet As Byte
  200.   lfOutPrecision As Byte
  201.   lfClipPrecision As Byte
  202.   lfQuality As Byte
  203.   lfPitchAndFamily As Byte
  204.   lfFacename As String * 33
  205. End Type
  206. Private Const PLANES = 14
  207. Private Const BITSPIXEL = 12
  208. Private Const TRANSPARENT = 1
  209. 'Memory DC declarations.
  210. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  211. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
  212. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  213. Private Declare Function OleTranslateColor Lib "OlePro32" (ByVal clrAny As Long, ByVal hPal As Long, ByRef clrConvertedOut As Long) As Long
  214. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  215. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC&, ByVal X&, ByVal y&, ByVal nWidth&, ByVal nHeight&, ByVal hSrcDC&, ByVal xSrc&, ByVal ySrc&, ByVal dwRop&) As Long
  216. Private Const SRCCOPY = &HCC0020
  217. Private Const SRCINVERT = &H660046
  218. Private Const SRCAND = &H8800C6
  219. Private Const SRCPAINT = &HEE0086
  220. 'Memory DC variables.
  221. Private hMemoryDC As Long
  222. Private hCompatibleBitmapTmp As Long
  223. Private hCompatibleBitmap As Long
  224. 'Fill direction list.
  225. Public Enum FillDirection
  226.     pbUp
  227.     pbDown
  228.     pbLeft
  229.     pbRight
  230. End Enum
  231. 'Border style list.
  232. Public Enum BorderStyles
  233.     pbNone
  234.     pbFixedSingle
  235. End Enum
  236. 'Appearance style list.
  237. Public Enum AppearanceStyles
  238.     pbFlat
  239.     pbThreeD
  240. End Enum
  241. 'Bar style list.
  242. Public Enum BarStyle
  243.     pbGradient
  244.     pbSolid
  245. End Enum
  246. 'Local variables to hold property values.
  247. Private mvarPercent As Byte
  248. Private mvarMin As Long
  249. Private mvarMax As Long
  250. Private mvarValue As Long
  251. Private mvarShowPercent As Boolean
  252. Private mvarMessage As String
  253. Private mvarShowMessage As Boolean
  254. Private mvarBarStartColour As OLE_COLOR
  255. Private mvarBarEndColour As OLE_COLOR
  256. Private mvarShowValue As Boolean
  257. Private mvarFillDirection As FillDirection
  258. Private mvarBackColour As OLE_COLOR
  259. Private mvarSoundToPlay As String
  260. Private mvarPlaySound As Boolean
  261. Private mvarVerticalText As Boolean
  262. Private mvarBarStyle As BarStyle
  263. Private mvarWaitForSound As Boolean
  264. Private WithEvents mvarFont As StdFont
  265. Attribute mvarFont.VB_VarHelpID = -1
  266. 'Default property values.
  267. Const mdefPercent = 0               'Start percent.
  268. Const mdefMin = 0                   'Lower limit.
  269. Const mdefMax = 100                 'Upper limit.
  270. Const mdefValue = 0                 'Start value.
  271. Const mdefShowPercent = False       'Don't show the percentage.
  272. Const mdefMessage = ""              'No start message.
  273. Const mdefShowMessage = False       'Don't show the message.
  274. Const mdefBarStartColour = &HFF     'Red bar colour start.
  275. Const mdefBarEndColour = &H0        'Black bar colour end.
  276. Const mdefShowValue = False         'Don't show the value.
  277. Const mdefFillDirection = 3         'Right fill.
  278. Const mdefBackColour = &HFFFFFF     'White background.
  279. Const mdefBorderStyle = 1           'ThreeD border style.
  280. Const mdefFontColour = &HFF0000     'Blue Text.
  281. Const mdefVerticalText = False      'Normal left to right text.
  282. Const mdefSoundToPlay = ""          'No initial sound.
  283. Const mdefPlaySound = False         'Don't play sound.
  284. Const mdefBarStyle = 1              'Solid.
  285. Const mdefWaitForSound = False      'Don't bother waiting.
  286. Public Property Let WaitForSound(ByVal vdata As Boolean)
  287.     'Set the wait for sound property.
  288.     mvarWaitForSound = vdata
  289.     'Indicate a property change.
  290.     PropertyChanged "WaitForSound"
  291. End Property
  292. Public Property Get WaitForSound() As Boolean
  293.     'Get the current state of the wait for sound flag.
  294.     WaitForSound = mvarWaitForSound
  295. End Property
  296. Public Property Let BarStyle(ByVal vdata As BarStyle)
  297.     'Check the bar style chosen, if it's outside the available
  298.     'settings set it to Solid.
  299.     If vdata < 0 Or vdata > 1 Then vdata = 1
  300.     'Set the bar style.
  301.     mvarBarStyle = vdata
  302.     'Update the control.
  303.     UserControl_Paint
  304.     'Indicate a property change.
  305.     PropertyChanged "BarStyle"
  306. End Property
  307. Public Property Get BarStyle() As BarStyle
  308.     'Get the current barstyle property value.
  309.     BarStyle = mvarBarStyle
  310. End Property
  311. Public Property Let VerticalText(ByVal vdata As Boolean)
  312.     'Set the vertical text flag.
  313.     mvarVerticalText = vdata
  314.     'Update the control.
  315.     UserControl_Paint
  316.     'Indicate a property change.
  317.     PropertyChanged "VerticalText"
  318. End Property
  319. Public Property Get VerticalText() As Boolean
  320.     'Get the state of the vertical text flag.
  321.     VerticalText = mvarVerticalText
  322. End Property
  323. Public Property Let SoundToPlay(ByVal vdata As String)
  324.     'Set the sound to play file string.
  325.     mvarSoundToPlay = vdata
  326.     'Indicate a property change.
  327.     PropertyChanged "SoundToPlay"
  328. End Property
  329. Public Property Get SoundToPlay() As String
  330.     'Get the surrent sound file string.
  331.     SoundToPlay = mvarSoundToPlay
  332. End Property
  333. Public Property Let PlaySound(ByVal vdata As Boolean)
  334.     'Set the play sound flag.
  335.     mvarPlaySound = vdata
  336.     'Indicate a property change.
  337.     PropertyChanged "PlaySound"
  338. End Property
  339. Public Property Get PlaySound() As Boolean
  340.     'Get the current play sound flag.
  341.     PlaySound = mvarPlaySound
  342. End Property
  343. Public Property Let FontColour(ByVal vdata As OLE_COLOR)
  344.     'Set the font colour by changing the forecolor.
  345.     UserControl.ForeColor = vdata
  346.     'Update the control.
  347.     UserControl_Paint
  348.     'Indicate a property change.
  349.     PropertyChanged "FontColour"
  350. End Property
  351. Public Property Get FontColour() As OLE_COLOR
  352.     'Get the current font colour.
  353.     FontColour = UserControl.ForeColor
  354. End Property
  355. Public Property Let BorderStyle(ByVal vdata As BorderStyles)
  356.     'Set the border style for the progress bar.
  357.     If vdata < 0 Then
  358.         vdata = 0
  359.     ElseIf vdata > 1 Then
  360.         vdata = 1
  361.     End If
  362.     UserControl.BorderStyle = vdata
  363.     'Update the control.
  364.     UserControl_Paint
  365.     'Indicate a property change.
  366.     PropertyChanged "BorderStyle"
  367. End Property
  368. Public Property Get BorderStyle() As BorderStyles
  369.     'Get the current border style.
  370.     BorderStyle = UserControl.BorderStyle
  371. End Property
  372. Public Property Let BarStartColour(ByVal vdata As OLE_COLOR)
  373.     'Set the bar start colour value.
  374.     mvarBarStartColour = vdata
  375.     'Update the control.
  376.     UserControl_Paint
  377.     'Indicate a property change.
  378.     PropertyChanged "BarStartColour"
  379. End Property
  380. Public Property Get BarStartColour() As OLE_COLOR
  381.     'Return the start colour value.
  382.     BarStartColour = mvarBarStartColour
  383. End Property
  384. Public Property Let BarEndColour(ByVal vdata As OLE_COLOR)
  385.     'Set the bar end colour.
  386.     mvarBarEndColour = vdata
  387.     'Update the control.
  388.     UserControl_Paint
  389.     'Indicate a property change.
  390.     PropertyChanged "BarEndColour"
  391. End Property
  392. Public Property Get BarEndColour() As OLE_COLOR
  393.     'Return the end bar colour.
  394.     BarEndColour = mvarBarEndColour
  395. End Property
  396. Public Property Let BackColour(ByVal vdata As OLE_COLOR)
  397.     'Set the back colour.
  398.     mvarBackColour = vdata
  399.     'Update the control.
  400.     UserControl_Paint
  401.     'Indicate a property change.
  402.     PropertyChanged "BackColour"
  403. End Property
  404. Public Property Get BackColour() As OLE_COLOR
  405.     'Get the current back colour.
  406.     BackColour = mvarBackColour
  407. End Property
  408. Public Property Let Value(ByVal vdata As Long)
  409. Attribute Value.VB_Description = "Returns/sets the value on the progress bar."
  410.     'Make sure the value chosen resides in the set range.
  411.     If vdata < mvarMin Then
  412.         vdata = mvarMin
  413.     ElseIf vdata > mvarMax Then
  414.         vdata = mvarMax
  415.     End If
  416.     'Set the current progress bar value.
  417.     mvarValue = vdata
  418.     'Calculate the percentage.
  419.     mvarPercent = Int(((mvarValue - mvarMin) / (mvarMax - mvarMin)) * 100)
  420.     'Update the control.
  421.     UserControl_Paint
  422.     'Indicate property changes.
  423.     PropertyChanged "Value"
  424.     PropertyChanged "Percent"
  425. End Property
  426. Public Property Get Value() As Long
  427.     'Return the current value.
  428.     Value = mvarValue
  429. End Property
  430. Public Property Let Min(ByVal vdata As Long)
  431. Attribute Min.VB_Description = "Returns/sets the progress bars lower limit."
  432.     'Check the min value is at least 1 less than
  433.     'the max value
  434.     If vdata >= mvarMax Then vdata = mvarMax - 1
  435.     'Set the start value of the progress bar.
  436.     mvarMin = vdata
  437.     'Recalculate the value.
  438.     mvarValue = Int(((mvarPercent / 100) * (mvarMax - mvarMin)) + mvarMin)
  439.     'Update the control.
  440.     UserControl_Paint
  441.     'Indicate property changes.
  442.     PropertyChanged "Min"
  443.     PropertyChanged "Value"
  444. End Property
  445. Public Property Get Min() As Long
  446.     'Return the value of the start.
  447.     Min = mvarMin
  448. End Property
  449. Public Property Let ShowValue(ByVal vdata As Boolean)
  450. Attribute ShowValue.VB_Description = "Returns/sets the flag to indicate the value should be shown."
  451.     'Set the flag to indicate the value should be shown
  452.     'in the progress bar.
  453.     mvarShowValue = vdata
  454.     'Check to see if the percentage is set to show in the
  455.     'progress bar and disable it.
  456.     If mvarShowValue = True Then
  457.         mvarShowPercent = False
  458.         'Indicate a property change.
  459.         PropertyChanged "ShowPercent"
  460.     End If
  461.     'Update the control.
  462.     UserControl_Paint
  463.     'Indicate a property change.
  464.     PropertyChanged "ShowValue"
  465. End Property
  466. Public Property Get ShowValue() As Boolean
  467.     'Return the current state of the value show flag.
  468.     ShowValue = mvarShowValue
  469. End Property
  470. Public Property Let ShowPercent(ByVal vdata As Boolean)
  471. Attribute ShowPercent.VB_Description = "Returns/sets the flag to indicate the percentage should be shown."
  472.     'Set the flag to indicate the percentage should be shown
  473.     'in the progress bar.
  474.     mvarShowPercent = vdata
  475.     'Check to see if the value is set to be shown and
  476.     'disable it.
  477.     If mvarShowPercent = True Then
  478.         mvarShowValue = False
  479.         'Indicate a property change.
  480.         PropertyChanged "ShowValue"
  481.     End If
  482.     'Update the control.
  483.     UserControl_Paint
  484.     'Indicate a property change.
  485.     PropertyChanged "ShowPercent"
  486. End Property
  487. Public Property Get ShowPercent() As Boolean
  488.     'Return the flag state for the percent showing.
  489.     ShowPercent = mvarShowPercent
  490. End Property
  491. Public Property Let ShowMessage(ByVal vdata As Boolean)
  492. Attribute ShowMessage.VB_Description = "Returns/sets the flag to indicate the message should be shown."
  493.     'Set the flag to indicate the message should be shown.
  494.     mvarShowMessage = vdata
  495.     'Update the control.
  496.     UserControl_Paint
  497.     'Indicate a property change.
  498.     PropertyChanged "ShowMessage"
  499. End Property
  500. Public Property Get ShowMessage() As Boolean
  501.     'Return the show message flag.
  502.     ShowMessage = mvarShowMessage
  503. End Property
  504. Public Property Let Percent(ByVal vdata As Byte)
  505. Attribute Percent.VB_Description = "Returns/sets the percentage on the progress bar."
  506.     'Ensure the percent chosen is between 0 and 100.
  507.     If vdata < 0 Then
  508.         vdata = 0
  509.     ElseIf vdata > 100 Then
  510.         vdata = 100
  511.     End If
  512.     'Set the percent property.
  513.     mvarPercent = vdata
  514.     'Calculate the value.
  515.     mvarValue = Int(((mvarPercent / 100) * (mvarMax - mvarMin)) + mvarMin)
  516.     'Update the control.
  517.     UserControl_Paint
  518.     'Indicate property changes.
  519.     PropertyChanged "Percent"
  520.     PropertyChanged "Value"
  521. End Property
  522. Public Property Get Percent() As Byte
  523.     'Return the current percentage of the progress bar.
  524.     Percent = mvarPercent
  525. End Property
  526. Public Property Let Message(ByVal vdata As String)
  527.     'Set message to show in the progress bar.
  528.     mvarMessage = vdata
  529.     'Update the control.
  530.     UserControl_Paint
  531.     'Indicate a property change.
  532.     PropertyChanged "Message"
  533. End Property
  534. Public Property Get Message() As String
  535.     'Return the message to show.
  536.     Message = mvarMessage
  537. End Property
  538. Public Property Let Max(ByVal vdata As Long)
  539.     'Check that the max value is at least 1 higher than
  540.     'the minimum value.
  541.     If vdata <= mvarMin Then vdata = mvarMin + 1
  542.     'Set the finish value for the progress bar.
  543.     mvarMax = vdata
  544.     'Recalculate the value.
  545.     mvarValue = Int(((mvarPercent / 100) * (mvarMax - mvarMin)) + mvarMin)
  546.     'Update the control.
  547.     UserControl_Paint
  548.     'Indicate property changes.
  549.     PropertyChanged "Max"
  550.     PropertyChanged "Value"
  551. End Property
  552. Public Property Get Max() As Long
  553.     'Return the finish value.
  554.     Max = mvarMax
  555. End Property
  556. Public Property Let FillDirection(ByVal vdata As FillDirection)
  557. Attribute FillDirection.VB_Description = "Returns/sets the the fill direction of the progress bar."
  558.     'Set the direction of the fill to right if it's invalid.
  559.     If vdata < 0 Or vdata > 3 Then
  560.         vdata = 3
  561.     End If
  562.     'Save the setting in the property variable.
  563.     mvarFillDirection = vdata
  564.     'Update the control.
  565.     UserControl_Paint
  566.     'Indicate a property change.
  567.     PropertyChanged "FillDirection"
  568. End Property
  569. Public Property Get FillDirection() As FillDirection
  570.     'Return the current fill direction.
  571.     FillDirection = mvarFillDirection
  572. End Property
  573. Public Property Get Font() As Font
  574.     'Return the current font.
  575.     Set Font = mvarFont
  576. End Property
  577. Public Property Set Font(mnewFont As StdFont)
  578.     'Set the current font.
  579.     With mvarFont
  580.         .Bold = mnewFont.Bold
  581.         .Italic = mnewFont.Italic
  582.         .Name = mnewFont.Name
  583.         .Size = mnewFont.Size
  584.         .Strikethrough = mnewFont.Strikethrough
  585.         .Underline = mnewFont.Underline
  586.     End With
  587.     'Indicate a property change.
  588.     PropertyChanged "Font"
  589. End Property
  590. Private Sub mvarFont_FontChanged(ByVal PropertyName As String)
  591.    Set UserControl.Font = mvarFont
  592.    Refresh
  593. End Sub
  594. Private Sub UserControl_Initialize()
  595.    Set mvarFont = New StdFont
  596.    Set UserControl.Font = mvarFont
  597. End Sub
  598. Private Sub UserControl_InitProperties()
  599.     'Set the defaults.
  600.     mvarFillDirection = mdefFillDirection
  601.     mvarMin = mdefMin
  602.     mvarMax = mdefMax
  603.     mvarValue = mdefValue
  604.     mvarPercent = mdefPercent
  605.     mvarMessage = mdefMessage
  606.     mvarShowMessage = mdefShowMessage
  607.     mvarShowPercent = mdefShowPercent
  608.     mvarShowValue = mdefShowValue
  609.     UserControl.BorderStyle = mdefBorderStyle
  610.     mvarBackColour = mdefBackColour
  611.     mvarBarStartColour = mdefBarStartColour
  612.     mvarBarEndColour = mdefBarEndColour
  613.     UserControl.ForeColor = mdefFontColour
  614.     mvarVerticalText = mdefVerticalText
  615.     mvarSoundToPlay = mdefSoundToPlay
  616.     mvarPlaySound = mdefPlaySound
  617.     mvarBarStyle = mdefBarStyle
  618.     mvarWaitForSound = mdefWaitForSound
  619. End Sub
  620. Private Sub UserControl_Paint()
  621.     'Draw the bar.
  622.     DrawBar
  623.     'Play the wav file.
  624.     PlayWav
  625. End Sub
  626. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  627.     'Restore the saved properties.
  628.     mvarBackColour = PropBag.ReadProperty("BackColour", mdefBackColour)
  629.     mvarBarStartColour = PropBag.ReadProperty("BarStartColour", mdefBarStartColour)
  630.     mvarBarEndColour = PropBag.ReadProperty("BarEndColour", mdefBarEndColour)
  631.     mvarFillDirection = PropBag.ReadProperty("FillDirection", mdefFillDirection)
  632.     mvarMax = PropBag.ReadProperty("Max", mdefMax)
  633.     mvarMessage = PropBag.ReadProperty("Message", mdefMessage)
  634.     mvarMin = PropBag.ReadProperty("Min", mdefMin)
  635.     mvarPercent = PropBag.ReadProperty("Percent", mdefPercent)
  636.     mvarShowMessage = PropBag.ReadProperty("ShowMessage", mdefShowMessage)
  637.     mvarShowPercent = PropBag.ReadProperty("ShowPercent", mdefShowPercent)
  638.     mvarShowValue = PropBag.ReadProperty("ShowValue", mdefShowValue)
  639.     mvarValue = PropBag.ReadProperty("Value", mdefValue)
  640.     mvarVerticalText = PropBag.ReadProperty("VerticalText", mdefVerticalText)
  641.     UserControl.BorderStyle = PropBag.ReadProperty("BorderStyle", mdefBorderStyle)
  642.     UserControl.ForeColor = PropBag.ReadProperty("FontColour", mdefFontColour)
  643.     mvarSoundToPlay = PropBag.ReadProperty("SoundToPlay", mdefSoundToPlay)
  644.     mvarPlaySound = PropBag.ReadProperty("PlaySound", mdefPlaySound)
  645.     mvarBarStyle = PropBag.ReadProperty("BarStyle", mdefBarStyle)
  646.     mvarWaitForSound = PropBag.ReadProperty("WaitForSound", mdefWaitForSound)
  647.     Set mvarFont = PropBag.ReadProperty("Font", Ambient.Font)
  648. End Sub
  649. Private Sub UserControl_Resize()
  650.     'Recreate the memory DC seeing as the old one is now an incorrect size.
  651.     'Delete the memory DC.
  652.     SelectObject hMemoryDC, hCompatibleBitmap
  653.     DeleteObject hCompatibleBitmapTmp
  654.     DeleteDC hMemoryDC
  655.     'Create a memory DC of the usercontrol.
  656.     hMemoryDC = CreateCompatibleDC(UserControl.hdc)
  657.     hCompatibleBitmapTmp = CreateCompatibleBitmap(UserControl.hdc, UserControl.ScaleWidth, UserControl.ScaleHeight)
  658.     hCompatibleBitmap = SelectObject(hMemoryDC, hCompatibleBitmapTmp)
  659.     'Repaint the control.
  660.     UserControl_Paint
  661. End Sub
  662. Private Sub UserControl_Terminate()
  663.     'Delete the memory DC.
  664.     SelectObject hMemoryDC, hCompatibleBitmap
  665.     DeleteObject hCompatibleBitmapTmp
  666.     DeleteDC hMemoryDC
  667. End Sub
  668. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  669.     'Save the instances current properties.
  670.     Call PropBag.WriteProperty("BackColour", mvarBackColour, mdefBackColour)
  671.     Call PropBag.WriteProperty("BarStartColour", mvarBarStartColour, mdefBarStartColour)
  672.     Call PropBag.WriteProperty("BarEndColour", mvarBarEndColour, mdefBarEndColour)
  673.     Call PropBag.WriteProperty("BorderStyle", UserControl.BorderStyle, mdefBorderStyle)
  674.     Call PropBag.WriteProperty("FillDirection", mvarFillDirection, mdefFillDirection)
  675.     Call PropBag.WriteProperty("FontColour", UserControl.ForeColor, mdefFontColour)
  676.     Call PropBag.WriteProperty("Max", mvarMax, mdefMax)
  677.     Call PropBag.WriteProperty("Message", mvarMessage, mdefMessage)
  678.     Call PropBag.WriteProperty("Min", mvarMin, mdefMin)
  679.     Call PropBag.WriteProperty("Percent", mvarPercent, mdefPercent)
  680.     Call PropBag.WriteProperty("ShowMessage", mvarShowMessage, mdefShowMessage)
  681.     Call PropBag.WriteProperty("ShowPercent", mvarShowPercent, mdefShowPercent)
  682.     Call PropBag.WriteProperty("ShowValue", mvarShowValue, mdefShowValue)
  683.     Call PropBag.WriteProperty("Value", mvarValue, mdefValue)
  684.     Call PropBag.WriteProperty("VerticalText", mvarVerticalText, mdefVerticalText)
  685.     Call PropBag.WriteProperty("SoundToPlay", mvarSoundToPlay, mdefSoundToPlay)
  686.     Call PropBag.WriteProperty("PlaySound", mvarPlaySound, mdefPlaySound)
  687.     Call PropBag.WriteProperty("BarStyle", mvarBarStyle, mdefBarStyle)
  688.     Call PropBag.WriteProperty("WaitForSound", mvarWaitForSound, mdefWaitForSound)
  689.     Call PropBag.WriteProperty("Font", mvarFont)
  690.     Call PropBag.WriteProperty("BarEndColour", mvarBarEndColour, mdefBarEndColour)
  691. End Sub
  692. Private Sub DrawBar()
  693. '================================================================================
  694. '= Draw Bar
  695. '================================================================================
  696.     'Local variables for determining colour depth.
  697.     Static intRgnCnt As Integer
  698.     Dim lngBitsPerPixel As Long
  699.     Dim lngNbrPlanes As Long
  700.     Dim lngColourBits As Long
  701.     'Local variables for drawing.
  702.     Dim lngAreaHeight As Long
  703.     Dim lngAreaWidth As Long
  704.     Dim sngRedLevel As Single
  705.     Dim sngGreenLevel As Single
  706.     Dim sngBlueLevel As Single
  707.     Dim sngRedColourVal As Single
  708.     Dim sngGreenColourVal As Single
  709.     Dim sngBlueColourVal As Single
  710.     Dim dblIntervalY As Double
  711.     Dim dblIntervalX As Double
  712.     Dim dblCurrentY As Double
  713.     Dim dblCurrentX As Double
  714.     Dim i As Integer
  715.     Dim FillArea As RECT
  716.     Dim hBrush As Long
  717.     If intRgnCnt = 0 Then
  718.         'Determine number of color bits supported.
  719.         lngBitsPerPixel = GetDeviceCaps(UserControl.hdc, BITSPIXEL)
  720.         lngNbrPlanes = GetDeviceCaps(UserControl.hdc, PLANES)
  721.         lngColourBits = (lngBitsPerPixel * lngNbrPlanes)
  722.         'Calculate the number of regions that the screen will be divided into.
  723.         'This is optimized for the current display's color depth.  Why waste
  724.         'time rendering 256 shades if you can only discern 32 or 64 of them?
  725.         Select Case lngColourBits
  726.             Case 32:   intRgnCnt = 256     '16M colors:  8 bits for blue
  727.             Case 24:   intRgnCnt = 256     '16M colors:  8 bits for blue
  728.             Case 16:   intRgnCnt = 256     '64K colors:  5 bits for blue
  729.             Case 15:   intRgnCnt = 32      '32K colors:  5 bits for blue
  730.             Case 8:    intRgnCnt = 64      '256 colors:  64 dithered blues
  731.             Case 4:    intRgnCnt = 64      '16 colors :  64 dithered blues
  732.             Case Else: lngColourBits = 4
  733.                 intRgnCnt = 64      '16 colors assumed: 64 dithered blues
  734.         End Select
  735.         
  736.         'Create a memory DC of the usercontrol.
  737.         hMemoryDC = CreateCompatibleDC(UserControl.hdc)
  738.         hCompatibleBitmapTmp = CreateCompatibleBitmap(UserControl.hdc, UserControl.ScaleWidth, UserControl.ScaleHeight)
  739.         hCompatibleBitmap = SelectObject(hMemoryDC, hCompatibleBitmapTmp)
  740.     End If
  741.     'Clear the memory DC with the specified background colour.
  742.     FillArea.vLeft = 0
  743.     FillArea.vTop = 0
  744.     FillArea.vRight = UserControl.ScaleWidth
  745.     FillArea.vBottom = UserControl.ScaleHeight
  746.     hBrush = CreateSolidBrush(RGB(mvarBackColour And &HFF&, (mvarBackColour And &HFF00&) \ &H100&, (mvarBackColour And &HFF0000) \ &H10000))
  747.     Call FillRect(hMemoryDC, FillArea, hBrush)
  748.     Call DeleteObject(hBrush)
  749.        
  750.     'Get the current pixel sizes.
  751.     lngAreaHeight = UserControl.ScaleHeight
  752.     lngAreaWidth = UserControl.ScaleWidth
  753.     'Determine start colour levels.
  754.     sngRedLevel = mvarBarStartColour And &HFF&
  755.     sngGreenLevel = (mvarBarStartColour And &HFF00&) \ &H100&
  756.     sngBlueLevel = (mvarBarStartColour And &HFF0000) \ &H10000
  757.        
  758.     'Set the fill area to the entire bar.
  759.     FillArea.vLeft = 0
  760.     FillArea.vTop = 0
  761.     FillArea.vRight = lngAreaWidth
  762.     FillArea.vBottom = lngAreaHeight
  763.     'If the bar is solid adjust the fill area to the current percentage.
  764.     If mvarBarStyle = 1 Then
  765.         Select Case mvarFillDirection
  766.             Case 0 'UP
  767.                 FillArea.vTop = lngAreaHeight - ((lngAreaHeight / 100) * mvarPercent)
  768.             Case 1 'DOWN
  769.                 FillArea.vBottom = (lngAreaHeight / 100) * mvarPercent
  770.             Case 2 'LEFT
  771.                 FillArea.vLeft = lngAreaWidth - ((lngAreaWidth / 100) * mvarPercent)
  772.             Case 3 'RIGHT
  773.                 FillArea.vRight = (lngAreaWidth / 100) * mvarPercent
  774.         End Select
  775.         'Fill the defined area with the bar start colour.
  776.         hBrush = CreateSolidBrush(RGB(sngRedLevel, sngGreenLevel, sngBlueLevel))
  777.         Call FillRect(hMemoryDC, FillArea, hBrush)
  778.         Call DeleteObject(hBrush)
  779.     'If it's a gradient fill run this code.
  780.     Else
  781.         'Number of pixels per region.
  782.         dblIntervalY = lngAreaHeight / intRgnCnt
  783.         dblIntervalX = lngAreaWidth / intRgnCnt
  784.         'Colour difference between regions.
  785.         sngRedColourVal = ((mvarBarEndColour And &HFF&) - sngRedLevel) / intRgnCnt
  786.         sngGreenColourVal = (((mvarBarEndColour And &HFF00&) \ &H100&) - sngGreenLevel) / intRgnCnt
  787.         sngBlueColourVal = (((mvarBarEndColour And &HFF0000) \ &H10000) - sngBlueLevel) / intRgnCnt
  788.         'Work through the number of regions the bar has been split into.
  789.         For i = 0 To intRgnCnt - 1
  790.             'Create a brush of the appropriate colour.
  791.             hBrush = CreateSolidBrush(RGB(Int(sngRedLevel), Int(sngGreenLevel), Int(sngBlueLevel)))
  792.             'Select the appropriate fill direction.
  793.             Select Case mvarFillDirection
  794.                 Case 0 'UP
  795.                     'Adjust the fill area to the current region.
  796.                     FillArea.vTop = lngAreaHeight - dblCurrentY - dblIntervalY
  797.                     FillArea.vBottom = lngAreaHeight - dblCurrentY
  798.                     'Fill this area if the area is shown, otherwise exit the loop.
  799.                     If FillArea.vTop > lngAreaHeight - ((lngAreaHeight / 100) * mvarPercent) Then
  800.                         Call FillRect(hMemoryDC, FillArea, hBrush)
  801.                     Else
  802.                         Exit For
  803.                     End If
  804.                 Case 1 'DOWN
  805.                     'Adjust the fill area to the current region.
  806.                     FillArea.vTop = dblCurrentY
  807.                     FillArea.vBottom = dblCurrentY + dblIntervalY
  808.                     'Fill this area if the area is shown, otherwise exit the loop.
  809.                     If FillArea.vBottom < (lngAreaHeight / 100) * mvarPercent Then
  810.                         Call FillRect(hMemoryDC, FillArea, hBrush)
  811.                     Else
  812.                         Exit For
  813.                     End If
  814.                 Case 2 'LEFT
  815.                     'Adjust the fill area to the current region.
  816.                     FillArea.vLeft = lngAreaWidth - dblCurrentX - dblIntervalX
  817.                     FillArea.vRight = lngAreaWidth - dblCurrentX
  818.                     'Fill this area if the area is shown, otherwise exit the loop.
  819.                     If FillArea.vLeft > lngAreaWidth - ((lngAreaWidth / 100) * mvarPercent) Then
  820.                         Call FillRect(hMemoryDC, FillArea, hBrush)
  821.                     Else
  822.                         Exit For
  823.                     End If
  824.                 Case 3 'RIGHT
  825.                     'Adjust the fill area to the current region.
  826.                     FillArea.vLeft = dblCurrentX
  827.                     FillArea.vRight = dblCurrentX + dblIntervalX
  828.                     'Fill this area if the area is shown, otherwise exit the loop.
  829.                     If FillArea.vRight < (lngAreaWidth / 100) * mvarPercent Then
  830.                         Call FillRect(hMemoryDC, FillArea, hBrush)
  831.                     Else
  832.                         Exit For
  833.                     End If
  834.             End Select
  835.             'Done with that brush, so delete it.
  836.             Call DeleteObject(hBrush)
  837.             'Increment the current X and Y locations.
  838.             dblCurrentY = dblCurrentY + dblIntervalY
  839.             dblCurrentX = dblCurrentX + dblIntervalX
  840.             'Increment display colour depth.
  841.             sngRedLevel = sngRedLevel + sngRedColourVal
  842.             sngGreenLevel = sngGreenLevel + sngGreenColourVal
  843.             sngBlueLevel = sngBlueLevel + sngBlueColourVal
  844.         Next
  845.         'Check to see if we bailed out of the for loop, if so
  846.         'delete the brush.
  847.         If i < intRgnCnt - 1 Then
  848.             Call DeleteObject(hBrush)
  849.         Else
  850.             'If we're at the end of the bar.
  851.             'Fill any of the remaining spaces with the bar end colour.
  852.             Select Case mvarFillDirection
  853.                 Case 0 'UP
  854.                     FillArea.vTop = 0
  855.                     FillArea.vBottom = FillArea.vTop + dblIntervalY
  856.                 Case 1 'DOWN
  857.                     FillArea.vBottom = lngAreaHeight
  858.                     FillArea.vTop = FillArea.vBottom - dblIntervalY
  859.                 Case 2 'LEFT
  860.                     FillArea.vLeft = 0
  861.                     FillArea.vRight = FillArea.vLeft + dblIntervalX
  862.                 Case 3 'RIGHT
  863.                     FillArea.vRight = lngAreaWidth
  864.                     FillArea.vLeft = FillArea.vRight - dblIntervalX
  865.             End Select
  866.             hBrush = CreateSolidBrush(RGB(mvarBarEndColour And &HFF&, (mvarBarEndColour And &HFF00&) \ &H100&, (mvarBarEndColour And &HFF0000) \ &H10000))
  867.             Call FillRect(hMemoryDC, FillArea, hBrush)
  868.             Call DeleteObject(hBrush)
  869.         End If
  870.     End If
  871. '================================================================================
  872. '= Draw Text
  873. '================================================================================
  874.     Call DrawText
  875. '================================================================================
  876. '= Copy memory DC to control.
  877. '================================================================================
  878.     Call BitBlt(UserControl.hdc, 0, 0, UserControl.ScaleWidth, _
  879.         UserControl.ScaleHeight, hMemoryDC, 0, 0, SRCCOPY)
  880. End Sub
  881. Private Sub DrawText()
  882.     'Local variables.
  883.     Dim strBarTxt As String
  884.     Dim i As Integer
  885.     Dim dblVertCurrentY As Double
  886.     Dim typFont As LOGFONT
  887.     Dim typTextMetric As TEXTMETRIC
  888.     Dim typSize As Size
  889.     Dim hPrevFont As Long, hFont As Long
  890. '================================================================================
  891. '= Generate text.
  892. '================================================================================
  893.     'If we want to show any text then draw it.
  894.     If mvarShowMessage Or mvarShowPercent Or mvarShowValue Then
  895.         'Set message if there's one flagged to show.
  896.         If mvarShowMessage Then strBarTxt = mvarMessage
  897.         'Add the percent or value if either are flagged to show.
  898.         If mvarShowPercent Or mvarShowValue Then
  899.             'Add a space if the percentage or value is to be shown and there is a message.
  900.             If Len(strBarTxt) > 0 Then strBarTxt = strBarTxt & " "
  901.             'Add the percentage if it's flagged to show.
  902.             If mvarShowPercent Then
  903.                 strBarTxt = strBarTxt & Format$(mvarPercent, "##0") + "%"
  904.             'Add the value if it's flagged to show.
  905.             ElseIf mvarShowValue Then
  906.                 strBarTxt = strBarTxt & Trim(Str(mvarValue)) & "/" & Trim(Str(mvarMax))
  907.             End If
  908.         End If
  909. '================================================================================
  910. '= Draw text to DC.
  911. '================================================================================
  912.         'Set the font up.
  913.         typFont.lfEscapement = 0
  914.         typFont.lfFacename = mvarFont.Name & Chr$(0)
  915.         typFont.lfHeight = (mvarFont.Size * -20) / Screen.TwipsPerPixelY
  916.         typFont.lfItalic = mvarFont.Italic
  917.         If mvarFont.Bold Then
  918.             typFont.lfWeight = 700
  919.         Else
  920.             typFont.lfWeight = 400
  921.         End If
  922.         typFont.lfUnderline = mvarFont.Underline
  923.         typFont.lfStrikeOut = mvarFont.Strikethrough
  924.         
  925.         'Create the font.
  926.         hFont = CreateFontIndirect(typFont)
  927.         hPrevFont = SelectObject(hMemoryDC, hFont)
  928.         Call SetBkMode(hMemoryDC, TRANSPARENT)
  929.         
  930.         'Set the backcolour to the text colour.
  931.         Call SetTextColor(hMemoryDC, UserControl.ForeColor)
  932.         'Get the font metrics.
  933.         Call GetTextMetrics(hMemoryDC, typTextMetric)
  934.         
  935.         'Draw the text vertically is so flagged.
  936.         If mvarVerticalText Then
  937.             'Calculate the total height of all the text.
  938.             For i = 1 To Len(strBarTxt)
  939.                 Call GetTextExtentPoint32(hMemoryDC, Mid(strBarTxt, i, 1), Len(Mid(strBarTxt, i, 1)), typSize)
  940.                 dblVertCurrentY = dblVertCurrentY + typSize.cy
  941.             Next i
  942.             'Set the Y coord to the begining letter of the text.
  943.             dblVertCurrentY = (UserControl.ScaleHeight - dblVertCurrentY) / 2
  944.             'Work through each letter of the text and place it on the progress bar.
  945.             For i = 1 To Len(strBarTxt)
  946.                 Call GetTextExtentPoint32(hMemoryDC, Mid(strBarTxt, i, 1), Len(Mid(strBarTxt, i, 1)), typSize)
  947.                 'Draw the letter to the memory DC.
  948.                 Call TextOut(hMemoryDC, _
  949.                     (UserControl.ScaleWidth - typSize.cx) / 2, _
  950.                     dblVertCurrentY, Mid(strBarTxt, i, 1), Len(Mid(strBarTxt, i, 1)))
  951.                 'Move the Y coord pointer for the next letter.
  952.                 dblVertCurrentY = dblVertCurrentY + typSize.cy
  953.             Next i
  954.         'Otherwise draw the text the normal left to right.
  955.         Else
  956.             Call GetTextExtentPoint32(hMemoryDC, strBarTxt, Len(strBarTxt), typSize)
  957.             'Draw the text to the memory DC.
  958.             Call TextOut(hMemoryDC, _
  959.                 (UserControl.ScaleWidth - typSize.cx) / 2, _
  960.                 (UserControl.ScaleHeight - typSize.cy) / 2, strBarTxt, Len(strBarTxt))
  961.         End If
  962.         'Reset the control's font settings.
  963.         Call SelectObject(hMemoryDC, hPrevFont)
  964.         Call DeleteObject(hFont)
  965.     End If
  966. End Sub
  967. Private Sub PlayWav()
  968.     'If the percentage has reached 100 and the flag to play
  969.     'a sound is on, then play the wav file.
  970.     If mvarPercent = 100 And mvarPlaySound Then
  971.         'If the file can be found then play it.
  972.         If Dir(mvarSoundToPlay) <> "" Then
  973.             'If we're supposed to wait for the sound to finish
  974.             'then play the sound sync'ed.
  975.             If mvarWaitForSound Then
  976.                 sndPlaySound mvarSoundToPlay, SND_SYNC
  977.             Else
  978.                 sndPlaySound mvarSoundToPlay, SND_ASYNC
  979.             End If
  980.         End If
  981.     End If
  982. End Sub
  983.