home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / sbardemo.zip / STATBAR.BAS < prev    next >
BASIC Source File  |  1995-08-18  |  33KB  |  854 lines

  1. Option Explicit
  2. '***************************************************************
  3. '*   Name of File:      STATBAR.BAS                            *
  4. '*   Author:            M. John Rodriguez                      *
  5. '*   Date Created:      May 07, 1995                           *
  6. '*   Last Modified:     Aug 18, 1995                           *
  7. '*   Current Version:   3.00.00                                *
  8. '***************************************************************
  9. '   Questions or Comments are welcome!
  10. '   M. John Rodriguez
  11. '     CIS ID: 100321,620
  12. '   Internet: jrodrigu@cpd.hqusareur.army.mil
  13. '           : 100321.620@compuserve.com
  14. '
  15. '   See the README.TXT file for more information or just look through the code!
  16. '
  17. Type RECT
  18.     Left As Integer
  19.     Top As Integer
  20.     Right As Integer
  21.     Bottom As Integer
  22. End Type
  23.  
  24. Type PanelStyleType
  25.     iLeft As Integer            'Left Position of the panel
  26.     iTop As Integer             'Top position of the panel
  27.     iWidth As Integer           'Width of the panel
  28.     iHeight As Integer          'Height of the Panel
  29.     iBorderStyle As Integer            'Type of panel 0-Recessed, 1-Raised, 2-Flat: User Defined
  30.     iFormat As Integer          'Format of the panel - Text, Date, Time, etc...: User Defined
  31.     iTextFormat As Integer      'Format of Text in the panel VCENTER, CENTER, etc.: User Defined
  32.     iOther As Integer           'Used for Icon Information or Percentage in the Meter Bar
  33.     lOther As Long              'User for color of the meter bar or whatever else needs to be used
  34. End Type
  35.  
  36. Type PanelType
  37.     sCaption As String          'Caption contained in the panel
  38.     PanelStyle As PanelStyleType 'Panel Information
  39.     iFontBold As Integer        'Whether or not font is bold
  40.     iFont3D As Integer          'Whether or not font is 3D
  41.     sFontName As String         'Font Name - Defaults to statusbar setting
  42.     sFontSize As String         'Font Size - Defaults to statusbar setting
  43.     lFontColor As Long          'Font Color - Defaults to statusbar setting
  44.     bVisible As Integer         'Let's you hide or show any panel you wish
  45. End Type
  46.  
  47. Type DrawProperties
  48.     lBackColor As Long
  49.     iDrawMode As Integer
  50.     iDrawStyle As Integer
  51.     iDrawWidth As Integer
  52.     lFillColor As Long
  53.     iFillStyle As Integer
  54.     bFontBold As Integer
  55.     bFontItalic As Integer
  56.     sFontName As String * 30
  57.     sFontSize As String * 10
  58.     bFontStrikeThru As Integer
  59.     bFontTransparent As Integer
  60.     bFontUnderline As Integer
  61.     lForeColor As Long
  62.     iScaleMode As Integer
  63. End Type
  64.  
  65.  
  66. 'Constants for the DrawText API call
  67. Global Const DT_TOP = &H0
  68. Global Const DT_LEFT = &H0
  69. Global Const DT_CENTER = &H1
  70. Global Const DT_RIGHT = &H2
  71. Global Const DT_VCENTER = &H4
  72. Global Const DT_BOTTOM = &H8
  73. Global Const DT_WORDBREAK = &H10
  74. Global Const DT_SINGLELINE = &H20
  75. Global Const DT_EXPANDTABS = &H40
  76. Global Const DT_TABSTOP = &H80
  77. Global Const DT_NOCLIP = &H100
  78. Global Const DT_EXTERNALLEADING = &H200
  79. Global Const DT_CALCRECT = &H400
  80. Global Const DT_NOPREFIX = &H800
  81. Global Const DT_INTERNAL = &H1000
  82.  
  83. 'Types of panels
  84. Global Const SBAR_PANEL_RECESSED = 0
  85. Global Const SBAR_PANEL_RAISED = 1
  86. Global Const SBAR_PANEL_FLAT = 2
  87.  
  88. 'Format of the panels
  89. Global Const SBAR_TEXT = 0            'Panel just contains text
  90. Global Const SBAR_DATE = 1            'Panel contains the date
  91. Global Const SBAR_TIME = 2            'Panel contains the time
  92. Global Const SBAR_WEEKDAY = 3         'Panel contains the weekday
  93. Global Const SBAR_FULLDATE = 4        'Panel Shows date as Tuesday Jan 1, 1995
  94. Global Const SBAR_CAPSLOCK = 5        'Panel is a CAPLOCK toggle display
  95. Global Const SBAR_NUMLOCK = 6         'Panel is a NUMLOCK toggle display
  96. Global Const SBAR_SCROLL = 7          'Panel is a SCROLL LOCK toggle display
  97. Global Const SBAR_COUNTER = 8         'Panel is a counter display
  98. Global Const SBAR_FIXEDTEXT = 9       'Panel contains a fixed text
  99. Global Const SBAR_MINICON = 10        'Panel is a miniature icon display
  100. Global Const SBAR_ICONMIX = 11        'Panel is a miniature icon/text display
  101. Global Const SBAR_BUTTON = 12         'Panel will emulate a button and fire and event when clicked
  102. Global Const SBAR_METER = 13          'Panel is a meter control that displays progress
  103.  
  104.  
  105. 'Specific information for drawing the panels
  106. Global Const SBAR_BORDERSIZE = 3      'Space between StatusBar borders and panels in pixels
  107. Global Const SBAR_PANELGAP = 4        'Gap between panels
  108. Global Const SBAR_TEXTGAP = 1         'Gap in between the text and the border in pixels
  109. Global Const SBAR_METERWIDTH = 100    'Width in pixels of the Meter panel
  110.  
  111. 'Some colors
  112. Global Const SBAR_WHITEBORDER = &HFFFFFF    'For 3D Effect - White Bar
  113. Global Const SBAR_DGREYBORDER = &H808080    'For 3D Effect - Drk Grey Bar
  114. Global Const SBAR_BACKGROUND = &HC0C0C0     'Color to paint the picture box
  115. Global Const SBAR_FONTCOLOR = &H0           'Black forecolor to draw text
  116.  
  117. 'Virtual Keys definitions for the GetKeyState API
  118. Global Const KEY_NUMLOCK = &H90
  119. Global Const KEY_SCROLL = &H91
  120. Global Const KEY_CAPITAL = &H14     'Caplocks Key
  121.  
  122. Declare Function GetKeyState Lib "User" (ByVal nVirtKey As Integer) As Integer
  123. Declare Function DrawText Lib "User" (ByVal hDC As Integer, ByVal lpStr As String, ByVal nCount As Integer, lpRect As RECT, ByVal wFormat As Integer) As Integer
  124. Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Long) As Integer
  125.  
  126. Global Const SRCCOPY = &HCC0020     ' (DWORD) dest = source
  127. Global Const SRCPAINT = &HEE0086    ' (DWORD) dest = source OR dest
  128. Global Const SRCAND = &H8800C6      ' (DWORD) dest = source AND dest
  129. Global Const SRCINVERT = &H660046   ' (DWORD) dest = source XOR dest
  130. Global Const SRCERASE = &H440328    ' (DWORD) dest = source AND (NOT dest )
  131. Global Const NOTSRCCOPY = &H330008  ' (DWORD) dest = (NOT source)
  132. Global Const NOTSRCERASE = &H1100A6 ' (DWORD) dest = (NOT src) AND (NOT dest)
  133. Global Const MERGECOPY = &HC000CA   ' (DWORD) dest = (source AND pattern)
  134. Global Const MERGEPAINT = &HBB0226  ' (DWORD) dest = (NOT source) OR dest
  135. Global Const PATCOPY = &HF00021     ' (DWORD) dest = pattern
  136. Global Const PATPAINT = &HFB0A09    ' (DWORD) dest = DPSnoo
  137. Global Const PATINVERT = &H5A0049   ' (DWORD) dest = pattern XOR dest
  138. Global Const DSTINVERT = &H550009   ' (DWORD) dest = (NOT dest)
  139. Global Const BLACKNESS = &H42&      ' (DWORD) dest = BLACK
  140. Global Const WHITENESS = &HFF0062   ' (DWORD) dest = WHITE
  141.  
  142. 'Sub CreatePanels ()
  143.  
  144. 'Use this procedure to create the panels you want...
  145. 'Call it from the Form_Load() Event...
  146. 'For use in multiple forms, cut and paste this into the general declarations section of
  147. 'each form.  See the README.TXT file for more information.
  148.  
  149. 'Dim iMaxPanels%
  150.  
  151. 'iMaxPanels% = 3
  152.  
  153. 'ReDim sb_panels(iMaxPanels%)
  154.  
  155. 'sb_panels(1).PanelStyle.iBorderStyle = SBAR_PANEL_RAISED
  156. 'sb_panels(1).PanelStyle.iFormat = SBAR_TEXT
  157. 'sb_panels(1).sFontName =
  158. 'sb_panels(1).sFontSize =
  159. 'sb_panels(1).lFontColor =
  160. 'sb_panels(1).iFont3D = True
  161. 'sb_panels(1).iFontBold = True
  162.  
  163. 'sb_panels(2).PanelStyle.iBorderStyle = SBAR_PANEL_RAISED
  164. 'sb_panels(2).PanelStyle.iFormat = SBAR_DATE
  165. 'sb_panels(2).sFontName = "Courier New"
  166. 'sb_panels(2).sFontSize = "6.0"
  167. 'sb_panels(2).lFontColor = &HFF
  168. 'sb_panels(2).iFont3D = True
  169. 'sb_panels(2).iFontBold = True
  170.  
  171. 'sb_panels(3).PanelStyle.iBorderStyle = SBAR_PANEL_RAISED
  172. 'sb_panels(3).PanelStyle.iFormat = SBAR_TIME
  173. 'sb_panels(3).sFontName = "Courier New"
  174. 'sb_panels(3).sFontSize = "6.0"
  175. 'sb_panels(3).lFontColor = &HFF
  176. 'sb_panels(3).iFont3D = True
  177. 'sb_panels(3).iFontBold = True
  178.  
  179. 'End Sub
  180.  
  181. Sub ButtonClick (uPanel As PanelType)
  182.  
  183. 'Here is where you process the code for the button clicks...
  184.  
  185. MsgBox "User clicked " + uPanel.sCaption, 0, "Status Bar Demo"
  186.  
  187.  
  188. End Sub
  189.  
  190. Sub DisplayStatusBar (ctrlStatusBar As Control, puPanels() As PanelType)
  191.  
  192. 'You call this from the PictureBox's Resize Event to redisplay the status bar after adjustments
  193.  
  194. Dim iCnt%, sTest$, iNumTextPanels%
  195. Dim iMaxPanels%, iPTextWidth%
  196. Dim iLeftPos%
  197. Dim iNewWidth%, iLeftOverSpace%
  198. Dim sbarRECT As RECT
  199. Dim uProps As DrawProperties
  200.  
  201. 'Turn of the status timer for now...
  202. ctrlStatusBar.Parent.StatTimer.Enabled = False
  203.  
  204. SaveControlProperties ctrlStatusBar, uProps
  205.  
  206. 'Clear the status bar
  207. ctrlStatusBar.AutoRedraw = True
  208. ctrlStatusBar.Cls
  209.  
  210. Make3DStatusBar ctrlStatusBar
  211.  
  212. 'Find out how many panels we got..
  213. iMaxPanels% = UBound(puPanels)
  214.  
  215. 'Calculate how much space we have to work with
  216. iLeftOverSpace% = ctrlStatusBar.ScaleWidth - ((SBAR_BORDERSIZE * 2) + ((iMaxPanels% - 1) * SBAR_PANELGAP))
  217.  
  218. 'Let's got through each panel
  219. For iCnt% = 1 To iMaxPanels%
  220.     If puPanels(iCnt%).bVisible Then
  221.     'Clear the test variable
  222.     sTest$ = ""
  223.     'Now let's set up a test strings to format the panel widths
  224.     Select Case puPanels(iCnt%).PanelStyle.iFormat
  225.         Case SBAR_DATE        'Format for the Date Panel
  226.         sTest$ = " XX/XX/XXXX "
  227.         Case SBAR_TIME        'Format for the Time Panel
  228.         sTest$ = " XX:XX xx "
  229.         Case SBAR_FULLDATE
  230.         sTest$ = " XXXXXXXXX, XXX XX, XXXX "
  231.         Case SBAR_WEEKDAY     'Format for the WeekDay Panel
  232.         sTest$ = " XXXXXXXXX "
  233.         Case SBAR_CAPSLOCK    'Format for the Capslock Panel
  234.         sTest$ = " CAP "
  235.         Case SBAR_NUMLOCK     'Format for the NumLock Panel
  236.         sTest$ = " NUM "
  237.         Case SBAR_SCROLL      'Format for the ScrollLock Panel
  238.         sTest$ = " SCR "
  239.         Case SBAR_COUNTER     'Format for the Counter type panel
  240.         sTest$ = " " + String$(puPanels(iCnt%).PanelStyle.iOther, "X") + " "
  241.         Case SBAR_TEXT, SBAR_ICONMIX   'Increment the number of text panels we have
  242.         iNumTextPanels% = iNumTextPanels% + 1
  243.         Case SBAR_FIXEDTEXT, SBAR_BUTTON
  244.         sTest$ = " " + puPanels(iCnt%).sCaption + " "
  245.         Case SBAR_MINICON
  246.         puPanels(iCnt%).PanelStyle.iWidth = 24
  247.         iLeftOverSpace% = iLeftOverSpace% - 24
  248.         Case SBAR_METER
  249.         puPanels(iCnt%).PanelStyle.iWidth = SBAR_METERWIDTH + 2
  250.         iLeftOverSpace% = iLeftOverSpace% - puPanels(iCnt%).PanelStyle.iWidth
  251.     End Select
  252.     'Do we have a test string?
  253.     If sTest$ <> "" Then
  254.         'Alright, now copy the font information to the StatusBar
  255.         ctrlStatusBar.FontName = puPanels(iCnt%).sFontName
  256.         ctrlStatusBar.FontSize = puPanels(iCnt%).sFontSize
  257.         ctrlStatusBar.FontBold = puPanels(iCnt%).iFontBold
  258.         'Let's get a width for the Label control plus the Text Gap
  259.         iNewWidth% = ctrlStatusBar.TextWidth(sTest$) + (SBAR_TEXTGAP * 2)
  260.         'Set the width of the panel
  261.         puPanels(iCnt%).PanelStyle.iWidth = iNewWidth%
  262.         'Deduct the width from the left over spaces
  263.         iLeftOverSpace% = iLeftOverSpace% - iNewWidth%
  264.     End If
  265.     End If
  266. Next
  267.  
  268. ctrlStatusBar.AutoRedraw = False
  269. RestoreControlProperties ctrlStatusBar, uProps
  270.  
  271. 'Calculate the space left over for all SBAR_TEXT types
  272. iPTextWidth% = 0
  273. If iNumTextPanels% > 0 Then
  274.     If iLeftOverSpace% > 0 Then iPTextWidth% = iLeftOverSpace% \ iNumTextPanels%
  275. End If
  276.  
  277. 'OK, now set our starting position to place our panels.
  278. iLeftPos% = SBAR_BORDERSIZE
  279.  
  280. For iCnt% = 1 To iMaxPanels%
  281.     If puPanels(iCnt%).bVisible Then
  282.     'If this panel is SBAR_TEXT then set the width from our calculations
  283.     If puPanels(iCnt%).PanelStyle.iFormat = SBAR_TEXT Or puPanels(iCnt%).PanelStyle.iFormat = SBAR_ICONMIX Then puPanels(iCnt%).PanelStyle.iWidth = iPTextWidth%
  284.     'If the control has any width...
  285.     If puPanels(iCnt%).PanelStyle.iWidth > 0 Then
  286.         'Set the panels left position to be drawn...
  287.         puPanels(iCnt%).PanelStyle.iLeft = iLeftPos%
  288.         'Now draw the panel
  289.         DrawStatusPanel ctrlStatusBar, puPanels(iCnt%)
  290.         'Increment to our next position
  291.         iLeftPos% = iLeftPos% + puPanels(iCnt%).PanelStyle.iWidth + SBAR_PANELGAP
  292.     End If
  293.     End If
  294. Next
  295.  
  296. 'Reactivate the timer...
  297. ctrlStatusBar.Parent.StatTimer.Enabled = True
  298.  
  299. End Sub
  300.  
  301. Sub DrawBorder (ctrlStatusBar As Control, puRect As RECT, ByVal piStyle%)
  302.  
  303. Dim lColorLTBorder&, lColorRBBorder&
  304.  
  305. 'Ok, depending on the type of panel, set the border colors
  306. If piStyle% = SBAR_PANEL_FLAT Then
  307.     lColorLTBorder& = ctrlStatusBar.BackColor
  308.     lColorRBBorder& = ctrlStatusBar.BackColor
  309. ElseIf piStyle% = SBAR_PANEL_RAISED Then
  310.     lColorLTBorder& = SBAR_WHITEBORDER
  311.     lColorRBBorder& = SBAR_DGREYBORDER
  312. Else
  313.     lColorLTBorder& = SBAR_DGREYBORDER
  314.     lColorRBBorder& = SBAR_WHITEBORDER
  315. End If
  316.  
  317. 'Now Draw the lines around the box area...
  318. 'Top
  319. ctrlStatusBar.Line (puRect.Left, puRect.Top)-(puRect.Right, puRect.Top), lColorLTBorder&
  320. 'Left
  321. ctrlStatusBar.Line (puRect.Left, puRect.Top)-(puRect.Left, puRect.Bottom), lColorLTBorder&
  322. 'Bottom
  323. ctrlStatusBar.Line (puRect.Left, puRect.Bottom)-(puRect.Right, puRect.Bottom), lColorRBBorder&
  324. 'Right
  325. ctrlStatusBar.Line (puRect.Right, puRect.Top)-(puRect.Right, puRect.Bottom), lColorRBBorder&
  326.  
  327. End Sub
  328.  
  329. Sub DrawStatusPanel (ctrlStatusBar As Control, puPanel As PanelType)
  330.  
  331. 'This draws the panel with the caption.
  332.  
  333. Dim pRect As RECT, tRect As RECT, offsetRect As RECT, iconRect As RECT
  334. Dim bSuc%, uProps As DrawProperties
  335. Dim ctrlIcons As Control, iXPos%
  336.  
  337. If Not puPanel.bVisible Then Exit Sub
  338.  
  339. SaveControlProperties ctrlStatusBar, uProps
  340.  
  341. Set ctrlIcons = ctrlStatusBar.Parent.sbar_pics
  342.  
  343. 'Set some of the properties now...
  344. ctrlStatusBar.AutoRedraw = True
  345. ctrlStatusBar.DrawWidth = 1
  346. ctrlStatusBar.ForeColor = SBAR_FONTCOLOR
  347.  
  348. 'Calculate the drawing box rectangle
  349. pRect.Left = puPanel.PanelStyle.iLeft
  350. pRect.Top = puPanel.PanelStyle.iTop
  351. pRect.Right = pRect.Left + puPanel.PanelStyle.iWidth
  352. pRect.Bottom = pRect.Top + puPanel.PanelStyle.iHeight
  353.  
  354. 'Clear the drawing region of where the panel will be placed
  355. ctrlStatusBar.Line (pRect.Left, pRect.Top)-(pRect.Right, pRect.Bottom), ctrlStatusBar.BackColor, BF
  356.  
  357. DrawBorder ctrlStatusBar, pRect, puPanel.PanelStyle.iBorderStyle
  358. 'Now we need to determine what kind of panel this is and draw it on the screen..
  359. Select Case puPanel.PanelStyle.iFormat
  360.     Case SBAR_MINICON
  361.     'This is just a 16 x 16 bitmap that we use to show in it's place...
  362.     'The iconRECT holds the position of the iCon
  363.     iconRect.Left = pRect.Left + 4
  364.     iconRect.Right = pRect.Left + 16
  365.     iconRect.Top = ((pRect.Bottom - pRect.Top - 16) / 2) + pRect.Top
  366.     iconRect.Bottom = pRect.Top + 16
  367.     'Ok. now its time to draw the icon in place..
  368.     If puPanel.PanelStyle.iOther > 0 Then
  369.         iXPos% = (puPanel.PanelStyle.iOther * 16) - 16
  370.         bSuc% = BitBlt(ctrlStatusBar.hDC, iconRect.Left, iconRect.Top, 16, 16, ctrlIcons.hDC, iXPos%, 0, SRCCOPY)
  371.     End If
  372.     'Thats it.. we are finished..
  373.     GoTo DrawStatusPanel_Exit
  374.     Case SBAR_ICONMIX
  375.     If puPanel.PanelStyle.iWidth > 26 Then
  376.         iconRect.Left = pRect.Left + 4
  377.         iconRect.Right = pRect.Left + 16
  378.         iconRect.Top = ((pRect.Bottom - pRect.Top - 16) / 2) + pRect.Top
  379.         iconRect.Bottom = pRect.Top + 16
  380.         If puPanel.PanelStyle.iOther > 0 Then
  381.         iXPos% = (puPanel.PanelStyle.iOther * 16) - 16
  382.         bSuc% = BitBlt(ctrlStatusBar.hDC, iconRect.Left, iconRect.Top, 16, 16, ctrlIcons.hDC, iXPos%, 0, SRCCOPY)
  383.         End If
  384.         tRect.Left = iconRect.Right + 6
  385.         tRect.Top = pRect.Top + 1
  386.         tRect.Right = pRect.Right - 1
  387.         tRect.Bottom = pRect.Bottom - 1
  388.     End If
  389.     Case Else
  390.     'Calculate the textbox rectangle - 1 pixel less than the rectangle..
  391.     tRect.Left = pRect.Left + 2
  392.     tRect.Top = pRect.Top + 1
  393.     tRect.Right = pRect.Right - 2
  394.     tRect.Bottom = pRect.Bottom - 1
  395.     If puPanel.PanelStyle.iFormat = SBAR_BUTTON And puPanel.PanelStyle.iBorderStyle = SBAR_PANEL_RECESSED Then
  396.         'If this is a button and it is recessed, move the text over and down a pixel
  397.         'to give the illusion of a button depressing.
  398.         tRect.Left = tRect.Left + 1
  399.         tRect.Top = tRect.Top + 1
  400.         tRect.Right = tRect.Right + 1
  401.         tRect.Bottom = tRect.Bottom + 1
  402.     End If
  403. End Select
  404.  
  405. If puPanel.PanelStyle.iFormat = SBAR_METER Then
  406.     'This just draws the meter for the panel..
  407.     If puPanel.PanelStyle.iOther > 0 Then ctrlStatusBar.Line (pRect.Left + 1, pRect.Top + 1)-(pRect.Left + 1 + (SBAR_METERWIDTH * (puPanel.PanelStyle.iOther / 100)), pRect.Bottom - 1), puPanel.PanelStyle.lOther, BF
  408. End If
  409.  
  410. 'Change the scale mode one last time..
  411. ctrlStatusBar.FontBold = puPanel.iFontBold
  412. ctrlStatusBar.FontName = puPanel.sFontName
  413. ctrlStatusBar.FontSize = puPanel.sFontSize
  414.  
  415. 'Now if this is 3D
  416. If puPanel.iFont3D Then
  417.     'Set the offset by 1 pixel
  418.     offsetRect.Left = tRect.Left + 1
  419.     offsetRect.Top = tRect.Top + 1
  420.     offsetRect.Right = tRect.Right + 1
  421.     offsetRect.Bottom = tRect.Bottom + 1
  422.     'Set the forecolor to white
  423.     ctrlStatusBar.ForeColor = SBAR_WHITEBORDER
  424.     'Draw the text
  425.     bSuc% = DrawText(ctrlStatusBar.hDC, puPanel.sCaption, Len(puPanel.sCaption), offsetRect, puPanel.PanelStyle.iTextFormat)
  426. End If
  427.  
  428. 'Now draw the Caption...setting the ForeColor of the Status Bar
  429. ctrlStatusBar.ForeColor = puPanel.lFontColor
  430. 'Draw the text
  431. bSuc% = DrawText(ctrlStatusBar.hDC, puPanel.sCaption, Len(puPanel.sCaption), tRect, puPanel.PanelStyle.iTextFormat)
  432.  
  433. DrawStatusPanel_Exit:
  434. ctrlStatusBar.AutoRedraw = False
  435. 'And now reset the Status Bar Settings..
  436. RestoreControlProperties ctrlStatusBar, uProps
  437.  
  438. End Sub
  439.  
  440. Sub FlashMessage (ctrlStatusBar As Control, psCaption$)
  441.  
  442. 'Function flashes a message in the Status bar by erasing the status bar and showing the information
  443. Dim tRect As RECT, bSuc%
  444.  
  445. ctrlStatusBar.Parent.StatTimer.Enabled = False
  446.  
  447. tRect.Left = SBAR_BORDERSIZE
  448. tRect.Top = SBAR_BORDERSIZE
  449. tRect.Right = ctrlStatusBar.ScaleWidth - SBAR_BORDERSIZE
  450. tRect.Bottom = ctrlStatusBar.ScaleHeight - SBAR_BORDERSIZE
  451.  
  452. ctrlStatusBar.AutoRedraw = True
  453. ctrlStatusBar.Cls
  454.  
  455. Make3DStatusBar ctrlStatusBar
  456.  
  457. DrawBorder ctrlStatusBar, tRect, SBAR_PANEL_RECESSED
  458. 'Now draw the text..
  459. tRect.Left = tRect.Left + 2
  460. tRect.Top = tRect.Top + 1
  461. tRect.Right = tRect.Right - 1
  462. tRect.Bottom = tRect.Bottom - 1
  463.  
  464. bSuc% = DrawText(ctrlStatusBar.hDC, psCaption$, Len(psCaption$), tRect, DT_LEFT Or DT_VCENTER Or DT_SINGLELINE)
  465.  
  466. ctrlStatusBar.AutoRedraw = True
  467.  
  468.  
  469. End Sub
  470.  
  471. Function InitializeStatusBar (frmWin As Form, puPanels() As PanelType) As Integer
  472.  
  473. 'Use this procedure to initialize the Status bar.. call it from the Form_Load() Event
  474. Dim iMaxHeight%, iCnt%
  475. Dim iMaxPanels%, iMaxPanelHeight%
  476. Dim iAlignCenter%, iAlignLeft%, iAlignRight%
  477. Dim iOldScaleMode%
  478.  
  479. On Local Error Resume Next
  480.  
  481. 'Find the number of panels to be passed
  482. iMaxPanels% = UBound(puPanels)
  483.  
  484. 'Do we have any panels?
  485. If iMaxPanels% > 0 Then
  486.     'Set up some basic settings for the format of panel text
  487.     iAlignCenter% = DT_VCENTER Or DT_CENTER Or DT_SINGLELINE
  488.     iAlignLeft% = DT_VCENTER Or DT_LEFT Or DT_SINGLELINE
  489.     iAlignRight% = DT_VCENTER Or DT_RIGHT Or DT_SINGLELINE
  490.     
  491.     iOldScaleMode% = frmWin.ScaleMode
  492.     frmWin.ScaleMode = 3
  493.  
  494.     'Set the color of the background for the picture box
  495.     frmWin.StatusBar.BackColor = SBAR_BACKGROUND
  496.     'Set the alignment of the picture box
  497.     frmWin.StatusBar.Align = 2
  498.     'Change the settings to Pixel
  499.     frmWin.StatusBar.ScaleMode = 3
  500.     'Set the border style to none... we will take cate of the border style ourselves..
  501.     'frmWin.StatusBar.BorderStyle = 0
  502.     'Set the max height to the tallest text +
  503.     'the border above and below the panel + gap between border
  504.     'and text and include the line around the picture control
  505.     iMaxPanelHeight% = SetMaxHeight(frmWin.StatusBar, puPanels())
  506.     iMaxHeight% = iMaxPanelHeight% + (SBAR_BORDERSIZE * 2) + (SBAR_TEXTGAP * 2)
  507.  
  508.     'Now set the height of the Status Bar
  509.     frmWin.StatusBar.Height = iMaxHeight%
  510.     'And reset the max panel height after adjusting to the new status bar height.
  511.     iMaxPanelHeight% = frmWin.StatusBar.ScaleHeight - (SBAR_BORDERSIZE * 2)
  512.     
  513.     frmWin.ScaleMode = iOldScaleMode%
  514.  
  515.     'Now go through each panel and set the height of each panel the same
  516.     'As well as a few other things...
  517.     For iCnt% = 1 To iMaxPanels%
  518.     puPanels(iCnt%).PanelStyle.iTop = SBAR_BORDERSIZE
  519.     puPanels(iCnt%).PanelStyle.iHeight = iMaxPanelHeight%
  520.     Select Case puPanels(iCnt%).PanelStyle.iFormat
  521.         Case SBAR_TEXT, SBAR_ICONMIX, SBAR_FIXEDTEXT
  522.         puPanels(iCnt%).PanelStyle.iTextFormat = iAlignLeft%
  523.         Case SBAR_COUNTER
  524.         puPanels(iCnt%).PanelStyle.iTextFormat = iAlignRight%
  525.         Case SBAR_METER
  526.         puPanels(iCnt%).lFontColor = 0&
  527.         puPanels(iCnt%).PanelStyle.iTextFormat = iAlignCenter%
  528.         Case SBAR_BUTTON
  529.         puPanels(iCnt%).PanelStyle.iBorderStyle = SBAR_PANEL_RAISED
  530.         puPanels(iCnt%).PanelStyle.iTextFormat = iAlignCenter%
  531.         Case Else
  532.         puPanels(iCnt%).PanelStyle.iTextFormat = iAlignCenter%
  533.     End Select
  534.     If puPanels(iCnt%).sFontName = "" Then puPanels(iCnt%).sFontName = frmWin.StatusBar.FontName
  535.     If puPanels(iCnt%).sFontSize = "" Then puPanels(iCnt%).sFontSize = frmWin.StatusBar.FontSize
  536.     Next
  537.     DisplayStatusBar frmWin.StatusBar, puPanels()
  538.  
  539. Else
  540.     frmWin.StatusBar.Visible = False
  541. End If
  542.  
  543. End Function
  544.  
  545. Sub Make3DStatusBar (ctrlStatusBar As Control)
  546.  
  547. Dim sbarRECT As RECT
  548.  
  549. 'Now we need to display the status bar as raised.
  550. sbarRECT.Left = 0
  551. sbarRECT.Top = 0
  552. sbarRECT.Right = ctrlStatusBar.ScaleWidth - 1
  553. sbarRECT.Bottom = ctrlStatusBar.ScaleHeight - 1
  554. 'Draw top line
  555. ctrlStatusBar.Line (sbarRECT.Left, sbarRECT.Top)-(sbarRECT.Right, sbarRECT.Top), SBAR_WHITEBORDER
  556. 'Draw Left Line
  557. ctrlStatusBar.Line (sbarRECT.Left, sbarRECT.Top)-(sbarRECT.Left, sbarRECT.Bottom), SBAR_WHITEBORDER
  558. 'Draw bottom line
  559. ctrlStatusBar.Line (sbarRECT.Left, sbarRECT.Bottom)-(sbarRECT.Right, sbarRECT.Bottom), SBAR_DGREYBORDER
  560. 'Draw Right Line
  561. ctrlStatusBar.Line (sbarRECT.Right, sbarRECT.Top)-(sbarRECT.Right, sbarRECT.Bottom), SBAR_DGREYBORDER
  562.  
  563.  
  564. End Sub
  565.  
  566. Sub RestoreControlProperties (ctrlControl As Control, puProperties As DrawProperties)
  567.  
  568. 'ctrlControl.BackColor = puProperties.lBackColor
  569. 'ctrlControl.DrawMode = puProperties.iDrawMode
  570. 'ctrlControl.DrawStyle = puProperties.iDrawStyle
  571. 'ctrlControl.DrawWidth = puProperties.iDrawWidth
  572. 'ctrlControl.FillColor = puProperties.lFillColor
  573. 'ctrlControl.FillStyle = puProperties.iFillStyle
  574. ctrlControl.FontBold = puProperties.bFontBold
  575. ctrlControl.FontItalic = puProperties.bFontItalic
  576. ctrlControl.FontName = Trim$(puProperties.sFontName)
  577. ctrlControl.FontSize = Trim$(puProperties.sFontSize)
  578. ctrlControl.FontStrikethru = puProperties.bFontStrikeThru
  579. ctrlControl.FontUnderline = puProperties.bFontUnderline
  580. ctrlControl.ForeColor = puProperties.lForeColor
  581. 'ctrlControl.ScaleMode = puProperties.iScaleMode
  582.  
  583. End Sub
  584.  
  585. Sub RestoreFormProperties (frmForm As Form, puProperties As DrawProperties)
  586.  
  587. 'frmForm.BackColor = puProperties.lBackColor
  588. 'frmForm.DrawMode = puProperties.iDrawMode
  589. 'frmForm.DrawStyle = puProperties.iDrawStyle
  590. 'frmForm.DrawWidth = puProperties.iDrawWidth
  591. 'frmForm.FillColor = puProperties.lFillColor
  592. 'frmForm.FillStyle = puProperties.iFillStyle
  593. frmForm.FontBold = puProperties.bFontBold
  594. frmForm.FontItalic = puProperties.bFontItalic
  595. frmForm.FontName = Trim$(puProperties.sFontName)
  596. frmForm.FontSize = Trim$(puProperties.sFontSize)
  597. frmForm.FontStrikethru = puProperties.bFontStrikeThru
  598. frmForm.FontUnderline = puProperties.bFontUnderline
  599. frmForm.ForeColor = puProperties.lForeColor
  600. 'frmForm.ScaleMode = puProperties.iScaleMode
  601.  
  602. End Sub
  603.  
  604. Sub SaveControlProperties (ctrlControl As Control, puProperties As DrawProperties)
  605.  
  606. 'puProperties.lBackColor = ctrlControl.BackColor
  607. 'puProperties.iDrawMode = ctrlControl.DrawMode
  608. 'puProperties.iDrawStyle = ctrlControl.DrawStyle
  609. 'puProperties.iDrawWidth = ctrlControl.DrawWidth
  610. 'puProperties.lFillColor = ctrlControl.FillColor
  611. 'puProperties.iFillStyle = ctrlControl.FillStyle
  612. puProperties.bFontBold = ctrlControl.FontBold
  613. puProperties.bFontItalic = ctrlControl.FontItalic
  614. puProperties.sFontName = ctrlControl.FontName
  615. puProperties.sFontSize = ctrlControl.FontSize
  616. puProperties.bFontStrikeThru = ctrlControl.FontStrikethru
  617. puProperties.bFontUnderline = ctrlControl.FontUnderline
  618. puProperties.lForeColor = ctrlControl.ForeColor
  619. 'puProperties.iScaleMode = ctrlControl.ScaleMode
  620.  
  621.  
  622. End Sub
  623.  
  624. Sub SaveFormProperties (frmForm As Form, puProperties As DrawProperties)
  625.  
  626. puProperties.lBackColor = frmForm.BackColor
  627. puProperties.iDrawMode = frmForm.DrawMode
  628. puProperties.iDrawStyle = frmForm.DrawStyle
  629. puProperties.iDrawWidth = frmForm.DrawWidth
  630. puProperties.lFillColor = frmForm.FillColor
  631. puProperties.iFillStyle = frmForm.FillStyle
  632. puProperties.bFontBold = frmForm.FontBold
  633. puProperties.bFontItalic = frmForm.FontItalic
  634. puProperties.sFontName = frmForm.FontName
  635. puProperties.sFontSize = frmForm.FontSize
  636. puProperties.bFontStrikeThru = frmForm.FontStrikethru
  637. puProperties.bFontUnderline = frmForm.FontUnderline
  638. puProperties.lForeColor = frmForm.ForeColor
  639. puProperties.iScaleMode = frmForm.ScaleMode
  640.  
  641. End Sub
  642.  
  643. Sub SBarMouseDown (ctrlStatusBar As Control, piButton%, piShift%, pnXPos!, pnYPos!, puPanels() As PanelType)
  644.  
  645. Dim iXPos%, iYPos%, iCnt%, iGotit%
  646. Dim drawRect As RECT
  647.  
  648. If piButton% = 1 Then
  649.     iXPos% = pnXPos!
  650.     iYPos% = pnYPos!
  651.     For iCnt% = 1 To UBound(puPanels)
  652.     If puPanels(iCnt%).PanelStyle.iFormat = SBAR_BUTTON Then
  653.         drawRect.Left = puPanels(iCnt%).PanelStyle.iLeft
  654.         drawRect.Right = drawRect.Left + puPanels(iCnt%).PanelStyle.iWidth
  655.         drawRect.Top = puPanels(iCnt%).PanelStyle.iTop
  656.         drawRect.Bottom = drawRect.Top + puPanels(iCnt%).PanelStyle.iHeight
  657.  
  658.         If (iXPos% > drawRect.Left) And (iXPos% < drawRect.Right) Then
  659.         If (iYPos% > drawRect.Top) And (iYPos% < drawRect.Bottom) Then
  660.             iGotit% = iCnt%
  661.             puPanels(iCnt%).PanelStyle.iBorderStyle = SBAR_PANEL_RECESSED
  662.         End If
  663.         End If
  664.         If (iGotit% = 0) And (puPanels(iCnt%).PanelStyle.iBorderStyle = SBAR_PANEL_RECESSED) Then
  665.         puPanels(iCnt%).PanelStyle.iBorderStyle = SBAR_PANEL_RAISED
  666.         DrawStatusPanel ctrlStatusBar, puPanels(iCnt%)
  667.         End If
  668.     End If
  669.     Next
  670.     If iGotit% Then DrawStatusPanel ctrlStatusBar, puPanels(iGotit%)
  671. End If
  672.  
  673. End Sub
  674.  
  675. Sub SBarMouseUp (ctrlStatusBar As Control, piButton%, piShift%, pnXPos!, pnYPos!, puPanels() As PanelType)
  676.  
  677. Dim iXPos%, iYPos%, iCnt%, iGotit%
  678. Dim drawRect As RECT
  679.  
  680. If piButton% = 1 Then
  681.     iXPos% = pnXPos!
  682.     iYPos% = pnYPos!
  683.     For iCnt% = 1 To UBound(puPanels)
  684.     If puPanels(iCnt%).PanelStyle.iFormat = SBAR_BUTTON Then
  685.         puPanels(iCnt%).PanelStyle.iBorderStyle = SBAR_PANEL_RAISED
  686.         DrawStatusPanel ctrlStatusBar, puPanels(iCnt%)
  687.         drawRect.Left = puPanels(iCnt%).PanelStyle.iLeft
  688.         drawRect.Right = drawRect.Left + puPanels(iCnt%).PanelStyle.iWidth
  689.         drawRect.Top = puPanels(iCnt%).PanelStyle.iTop
  690.         drawRect.Bottom = drawRect.Top + puPanels(iCnt%).PanelStyle.iHeight
  691.         If (iXPos% > drawRect.Left) And (iXPos% < drawRect.Right) Then
  692.         If (iYPos% > drawRect.Top) And (iYPos% < drawRect.Bottom) Then iGotit% = iCnt%
  693.         End If
  694.     End If
  695.     Next
  696.     If iGotit% > 0 Then
  697.     If puPanels(iGotit%).PanelStyle.iFormat = SBAR_BUTTON Then ButtonClick puPanels(iGotit%)
  698.     End If
  699. End If
  700.  
  701. End Sub
  702.  
  703. Function SetMaxHeight (ctrlStatusBar As Control, puPanels() As PanelType) As Integer
  704.  
  705. 'Function Calculates the MaxHeight based on the font name and font size
  706.  
  707. Dim uProps As DrawProperties
  708. Dim iMaxPanels%, iMaxHeight%, iCnt%, sTemp$, iTestHeight%
  709.  
  710. 'Save the old settings
  711. SaveControlProperties ctrlStatusBar, uProps
  712.  
  713. 'Here we have a test sample
  714. sTemp$ = "TEST"
  715.  
  716. iMaxHeight% = 18
  717.  
  718. 'Get the number of panels
  719. iMaxPanels% = UBound(puPanels)
  720.  
  721. 'Go through each panel, checking for font information and then checking the
  722. 'height of the test string.  The font with the highest size will determine how
  723. 'large the status bar is in height.
  724. For iCnt% = 1 To iMaxPanels%
  725.     'Make sure we have font names to use
  726.     If puPanels(iCnt%).sFontName = "" Then ctrlStatusBar.FontName = Trim$(uProps.sFontName) Else ctrlStatusBar.FontName = puPanels(iCnt%).sFontName
  727.     If puPanels(iCnt%).sFontSize = "" Then ctrlStatusBar.FontSize = Trim$(uProps.sFontSize) Else ctrlStatusBar.FontSize = puPanels(iCnt%).sFontSize
  728.     'Set the remaining settings
  729.     ctrlStatusBar.FontBold = puPanels(iCnt%).iFontBold
  730.     'Get the height
  731.     iTestHeight% = ctrlStatusBar.TextHeight(sTemp$)
  732.     'If it is higher than what we got, make it the new height
  733.     If iTestHeight% > iMaxHeight% Then iMaxHeight% = iTestHeight%
  734. Next iCnt%
  735.  
  736. 'Return the old settings
  737. RestoreControlProperties ctrlStatusBar, uProps
  738. 'Return our maximum height
  739. SetMaxHeight = iMaxHeight%
  740.  
  741. End Function
  742.  
  743. Sub UpdateKeyPanels (cStatBar As Control, uPanels() As PanelType)
  744.  
  745.  
  746. 'This procedure can be called from the Form_KeyDown() event to better optimize
  747. 'the update of the toggle keys.   All you have to do is set the KeyPreview property
  748. 'of the form to True (except for MDI Forms.. you have to set it for each child)
  749. 'and then call this routine.
  750.  
  751.  
  752. Dim iCnt%, iKeyState%, iNumPanels%
  753.  
  754. 'Get the number of panels
  755. iNumPanels% = UBound(uPanels)
  756.  
  757. 'Go through each panel and place the appropriate information in it
  758. For iCnt% = 1 To iNumPanels%
  759.     Select Case uPanels(iCnt%).PanelStyle.iFormat
  760.     Case SBAR_CAPSLOCK    'Check the toggle of the Caps Lock Key
  761.         iKeyState% = GetKeyState(KEY_CAPITAL)
  762.         If (iKeyState% And 1) = 1 Then UpdateTextPanel cStatBar, uPanels(iCnt%), "CAP" Else UpdateTextPanel cStatBar, uPanels(iCnt%), ""
  763.     Case SBAR_NUMLOCK     'Check the toggle of the Num Lock Key
  764.         iKeyState% = GetKeyState(KEY_NUMLOCK)
  765.         If (iKeyState% And 1) = 1 Then UpdateTextPanel cStatBar, uPanels(iCnt%), "NUM" Else UpdateTextPanel cStatBar, uPanels(iCnt%), ""
  766.     Case SBAR_SCROLL      'Check the toggle of the Scroll Lock key
  767.         iKeyState% = GetKeyState(KEY_SCROLL)
  768.         If (iKeyState% And 1) = 1 Then UpdateTextPanel cStatBar, uPanels(iCnt%), "SCR" Else UpdateTextPanel cStatBar, uPanels(iCnt%), ""
  769.     End Select
  770. Next
  771.  
  772. End Sub
  773.  
  774. Sub UpdateStatusPanels (cStatBar As Control, uPanels() As PanelType)
  775.  
  776. 'You can call this one from the StatTimer_Timer() event to update all
  777. 'status panels (Date, Time, ToggleKeys).
  778. 'Toggle keys are a little slower but will work effectively if needed.
  779.  
  780.  
  781. Dim iCnt%, iKeyState%, iNumPanels%
  782.  
  783. 'Get the number of panels
  784. iNumPanels% = UBound(uPanels)
  785.  
  786. 'Go through each panel and place the appropriate information in it
  787. For iCnt% = 1 To iNumPanels%
  788.     Select Case uPanels(iCnt%).PanelStyle.iFormat
  789.     Case SBAR_DATE        'Show today's date
  790.         UpdateTextPanel cStatBar, uPanels(iCnt%), Format$(Now, "m/d/yyyy")
  791.     Case SBAR_TIME        'Show the Time
  792.         UpdateTextPanel cStatBar, uPanels(iCnt%), Format$(Now, "h:mm am/pm")
  793.     Case SBAR_FULLDATE
  794.         UpdateTextPanel cStatBar, uPanels(iCnt%), Format$(Now, "dddd, mmm dd, yyyy")
  795.     Case SBAR_WEEKDAY
  796.         UpdateTextPanel cStatBar, uPanels(iCnt%), Format$(Now, "dddd")
  797.     Case SBAR_CAPSLOCK    'Check the toggle of the Caps Lock Key
  798.         iKeyState% = GetKeyState(KEY_CAPITAL)
  799.         If (iKeyState% And 1) = 1 Then UpdateTextPanel cStatBar, uPanels(iCnt%), "CAP" Else UpdateTextPanel cStatBar, uPanels(iCnt%), ""
  800.     Case SBAR_NUMLOCK     'Check the toggle of the Num Lock Key
  801.         iKeyState% = GetKeyState(KEY_NUMLOCK)
  802.         If (iKeyState% And 1) = 1 Then UpdateTextPanel cStatBar, uPanels(iCnt%), "NUM" Else UpdateTextPanel cStatBar, uPanels(iCnt%), ""
  803.     Case SBAR_SCROLL      'Check the toggle of the Scroll Lock key
  804.         iKeyState% = GetKeyState(KEY_SCROLL)
  805.         If (iKeyState% And 1) = 1 Then UpdateTextPanel cStatBar, uPanels(iCnt%), "SCR" Else UpdateTextPanel cStatBar, uPanels(iCnt%), ""
  806.     End Select
  807. Next
  808.  
  809.  
  810. End Sub
  811.  
  812. Sub UpdateTextPanel (cStatBar As Control, uPanel As PanelType, ByVal sNewCaption As String)
  813.  
  814. 'All this panel does is check to see if you have a new caption.  If the caption is the
  815. 'same, then it does nothing since it isn't necessary.  If it does change, the caption
  816. 'panel is updates and then redrawn.
  817.  
  818. sNewCaption = " " + sNewCaption + " "
  819.  
  820. If sNewCaption <> uPanel.sCaption Then
  821.     uPanel.sCaption = sNewCaption
  822.     DrawStatusPanel cStatBar, uPanel
  823. End If
  824.  
  825. End Sub
  826.  
  827. Sub UpdateTimePanels (cStatBar As Control, uPanels() As PanelType)
  828.  
  829. 'All you have to do is call this procedure to update the time.  Call this from
  830. 'any Timer() event to update the panels.
  831.  
  832.  
  833. Dim iCnt%, iNumPanels%
  834.  
  835. 'Get the number of panels
  836. iNumPanels% = UBound(uPanels)
  837.  
  838. 'Go through each panel and place the appropriate information in it
  839. For iCnt% = 1 To iNumPanels%
  840.     Select Case uPanels(iCnt%).PanelStyle.iFormat
  841.     Case SBAR_DATE        'Show today's date
  842.         UpdateTextPanel cStatBar, uPanels(iCnt%), Format$(Now, "m/d/yyyy")
  843.     Case SBAR_TIME        'Show the Time
  844.         UpdateTextPanel cStatBar, uPanels(iCnt%), Format$(Now, "h:mm am/pm")
  845.     Case SBAR_WEEKDAY
  846.         UpdateTextPanel cStatBar, uPanels(iCnt%), Format$(Now, "dddd")
  847.     Case SBAR_FULLDATE
  848.         UpdateTextPanel cStatBar, uPanels(iCnt%), Format$(Now, "dddd, mmm dd, yyyy")
  849.     End Select
  850. Next
  851.  
  852. End Sub
  853.  
  854.