home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / sbardemo.zip / README.TXT < prev    next >
Text File  |  1995-08-18  |  18KB  |  383 lines

  1. Status Bar DEMO - Version 3.00
  2.  
  3. By:  M. J.  Rodriguez     CIS ID: 100321,620
  4.                         Internet: 100321.620@compuserve.com
  5.                                   jrodrigu@cpd.hqusareur.army.mil
  6.  
  7.  
  8. This compressed file contains the following files:
  9.  
  10. CONSTANT.GLB    - A supporting file for the demo
  11. FORM1.FRM     - Demo Form for the project
  12. FORM1.FRX    - VB Support Graphic file for FORM1.FRM
  13. README.TXT    - This File
  14. SBARDEMO.EXE    - Executable of the Demo
  15. SBARDEMO.MAK    - Project MAK file
  16. STATBAR.BAS     - Status Bar Module you need for any status bar
  17. STATBAR.BMP    - BMP file used for the SBAR_MINICON Panels
  18.  
  19. Contents:
  20. -------------------------------------------------
  21. About the Code
  22. Status Bar Implementation
  23. How the Status Bar is Drawn
  24. Adding the StatusBar to your project
  25. How the Code Works
  26. Use of the Status Bar with Menu's and Mouse Movements.
  27. VB 4.0
  28. Disclaimer
  29. -------------------------------------------------
  30.  
  31.  
  32. About the Code:
  33. -------------------------------------------------
  34.  
  35. In early May I put out a project in CompuServe for a status bar that could be 
  36. displayed using just a label, a timer, and a picture box.  Then a week later, 
  37. I modified it by removing the label and just went with the timer and 
  38. PictureBox.  Suffice it to say, I have had over 1000 downloads of it and have 
  39. received many compliments.  Then as always, it doesn't quite meet just what 
  40. the user wants and so the questions came in.  This third iteration is the 
  41. result of some of those requests and includes some tips, although modified 
  42. here, from other users.  Unfortunately, I cannot find the name of the few who 
  43. did send in suggestions and additions, but if you see it again, I apologize 
  44. for not including your name... however, VC..(you know who you are because I 
  45. remember your initials), you get credit for the SBAR_FIXEDTEXT which was a 
  46. great idea and your code is included.   The person who sent me the SBAR_BUTTON 
  47. idea (without the code, so what you see is what I did) you get at least 
  48. partial credit for it.  And a special thanks to the Los Angeles Visual Basic 
  49. User's Group for their many kind comments.  I hope this will get added to your 
  50. Top Ten list again.
  51.  
  52. I have modularized this code to the point where you should be able to just 
  53. drop it into your projects and go.  If you have any problems let me know.
  54.  
  55.  
  56. Status Bar Implementation:
  57. -------------------------------------------------
  58.  
  59. In this concept, the Status bar is divided into panels.  Each panel is drawn 
  60. individually.  Each panel has properties which you can change.  How you change 
  61. the panel is determined by your needs.  The properties are kept in an array of 
  62. a user-defined type called PanelType.
  63.  
  64. Here is the structure of PanelType..
  65.  
  66. Type PanelType
  67.     sCaption As String          'Caption contained in the panel
  68.     PanelStyle As PanelStyleType 'Panel Information
  69.     iFontBold As Integer        'Whether or not font is bold
  70.     iFont3D As Integer          'Whether or not font is 3D
  71.     sFontName As String         'Font Name - Defaults to statusbar setting
  72.     sFontSize As String         'Font Size - Defaults to statusbar setting
  73.     lFontColor As Long          'Font Color - Defaults to statusbar setting
  74.     bVisible As Integer         'Let's you hide or show any panel you wish
  75. End Type
  76.  
  77.  
  78. The PanelStyle element is a user-defined type called PanelStyleType.  There is 
  79. no particular reason why I did it this way other than to isolate some 
  80. properties.  In the original implementation, the Status Bar passed the 
  81. PanelStyle element for drawing purposes.  Now, it isn't done that way, so 
  82. instead of changing it to be one complete element, I left it the way it was 
  83. and expanded it.  Probably not good coding, but it works.  Here is the 
  84. PanelStyleType.
  85.  
  86.  
  87. Type PanelStyleType
  88.     iLeft As Integer            'Left Position of the panel
  89.     iTop As Integer             'Top position of the panel
  90.     iWidth As Integer           'Width of the panel
  91.     iHeight As Integer          'Height of the Panel
  92.     iBorderStyle As Integer     'Type of panel 0-Recessed, 1-Raised, 2-Flat: User Defined
  93.     iFormat As Integer          'Format of the panel - Text, Date, Time, etc...: User Defined
  94.     iTextFormat As Integer      'Format of Text in the panel VCENTER, CENTER, etc.: User Defined
  95.     iOther As Integer           'Used for Icon Information or Percentage in the Meter Bar
  96.     lOther As Long              'User for color of the meter bar or whatever else needs to be used
  97. End Type
  98.  
  99.  
  100. These properties change as you need them to.  Once they are changed, they will 
  101. be reflected the next time the panel is drawn.
  102.  
  103. The following are the types of panels as defined by global constants.  These 
  104. are not the only types you are limited to as you certainly can add any type 
  105. you want.  It's entirely up to you.
  106.  
  107.  
  108. 'Format of the panels
  109. Global Const SBAR_TEXT = 0            'Panel just contains text
  110. Global Const SBAR_DATE = 1            'Panel contains the date
  111. Global Const SBAR_TIME = 2            'Panel contains the time
  112. Global Const SBAR_WEEKDAY = 3         'Panel contains the weekday
  113. Global Const SBAR_FULLDATE = 4        'Panel Shows date as Tuesday Jan 1, 1995
  114. Global Const SBAR_CAPSLOCK = 5        'Panel is a CAPLOCK toggle display
  115. Global Const SBAR_NUMLOCK = 6         'Panel is a NUMLOCK toggle display
  116. Global Const SBAR_SCROLL = 7          'Panel is a SCROLL LOCK toggle display
  117. Global Const SBAR_COUNTER = 8         'Panel is a counter display
  118. Global Const SBAR_FIXEDTEXT = 9       'Panel contains a fixed text
  119. Global Const SBAR_MINICON = 10        'Panel is a miniature icon display
  120. Global Const SBAR_ICONMIX = 11        'Panel is a miniature icon/text display
  121. Global Const SBAR_BUTTON = 12         'Panel will emulate a button and fire and event when clicked
  122. Global Const SBAR_METER = 13          'Panel is a meter control that displays progress
  123.  
  124. The SBAR_MINICON and SBAR_ICONMIX are unique in that they reference small 
  125. icons.  In reality, I use another PictureBox names sbar_pics and include a 
  126. single bitmap of all the small "icons" I want to use.  The individual pieces 
  127. of the bitmap are 16 x 16 pixels and drawn using PaintBrush.  The program 
  128. makes the assumption that you will do the same otherwise, the pictures may not 
  129. come out correctly.  In the project, you will need to add at least one picture 
  130. box named sbar_pics.  It doesn't have to big and can be invisible.  If you 
  131. don't want to add the sbar_pics PictureBox, then remark out or delete all the 
  132. references in the code that work with these types.  Most of them are in 
  133. Select..Case statements and a few If..Then..Else.. blocks which are easily 
  134. remarked out.
  135.  
  136. The panels are displayed in one of three ways: Flat, Raised, or Recessed.  
  137. Here are the constants used in the implementation.
  138.  
  139. Global Const SBAR_PANEL_RECESSED = 0
  140. Global Const SBAR_PANEL_RAISED = 1
  141. Global Const SBAR_PANEL_FLAT = 2
  142.  
  143. By setting the iBorderStyle element in the PanelStyle UDT, you determine what 
  144. the appearance of the panel will be.
  145.  
  146.  
  147. How the Status Bar is Drawn.
  148. -------------------------------------------------
  149.  
  150. The Status Bar is drawn using the DrawText API call and the Line Method.  Each 
  151. panel size is determined by a number of conditions.  Every panel except 
  152. SBAR_TEXT, SBAR_ICONMIX, and SBAR_METER is determined by the size of the 
  153. element being displayed using a predefined format.  For example, the 
  154. SBAR_FULLDATE size is determined by the width of the text of a formatted 
  155. string containing capital X's and usually is represented the largest character 
  156. count of the possible text.  This allows for constant size.  The SBAR_TEXT and 
  157. SBAR_ICONMIX are displayed if any space is left over after all the fixed sized 
  158. panels are subtracted from the available width minus the size of the border of 
  159. the status bar around the panels and the gaps between each panel.  SBAR_METER 
  160. is a globally defined constant which can be changed by you.  It is currently 
  161. set to 100 pixels in width.  Here are the constants used in determining sizes 
  162. of borders and gaps.
  163.  
  164. Global Const SBAR_BORDERSIZE = 2      'Space between StatusBar borders and panels in pixels
  165. Global Const SBAR_PANELGAP = 4        'Gap between panels in Pixels
  166. Global Const SBAR_TEXTGAP = 1         'Gap in between the text and the border in pixels
  167. Global Const SBAR_METERWIDTH = 100    'Width in pixels of the Meter panel
  168.  
  169. These measurements are determined by you and will affect the size of the 
  170. status bar's height.  Width is automatically decided as the status bar is 
  171. anchored to the bottom of the form.  This can be changed by adjusting the 
  172. Align property of the StatusBar control.
  173.  
  174.  
  175. Adding the StatusBar to your project
  176. -------------------------------------------------
  177.  
  178. First thing, decide which form or forms your Status bar is going on.  You 
  179. aren't limited to just one form.  You can have a status bar on any form you 
  180. want or as many.  There may be a performance sacrifice if you have like GOBS 
  181. of forms with Status Bars, but whatever makes you happy, I always say...
  182.  
  183. If this is not a MDI form, and you have panels for CapLock, NumLock, or 
  184. ScrollLock, or add anyother toggle function, then you want to change the forms 
  185. KeyPreview property to True and then add in the Form_KeyDown procedure the 
  186. follwing snippet:
  187.  
  188.     UpdateKeyPanels StatusBar, sb_panels()
  189.  
  190. This procedure takes care of just toggle keys.  If you have an MDI form, 
  191. obviously, you can't use this because there is no KeyPreview property.  
  192. The Timer procedure does take care of this.
  193.  
  194.  
  195. In the Forms Declaration section of the form, add the following:
  196.  
  197.     Dim sb_panels() As PanelType
  198.     Dim sb_initialized As Integer
  199.  
  200. The sb_panels() is for the status bar for that form.  For any other form, just 
  201. add the same thing.  It doesn't matter.
  202.  
  203. You will need to add a procedure in the General Declarations section called 
  204. CreatePanels.  A remarked out copy of the procedure is available in the 
  205. General Declaration Section of the STATBAR.BAS file. You can use it as a 
  206. template for your setting properties and the number of panels you want to 
  207. create.  You can also use the copy that is available in the sample project.  Just 
  208. look in the general section and look for the CreatePanels procedure.  A simple 
  209. cut and paste will make it real easy to add.
  210.  
  211. In the Form_Load event, you will need to add the following code snippet.
  212.  
  213.     Dim bSuc%
  214.  
  215.     CreatePanels
  216.     bSuc% = InitializeStatusBar(Me, sb_panels())
  217.     sb_initialized = True
  218.  
  219. Now you are ready to add the status bar to your project. In the form,  you 
  220. need to add a picture box to your form.  If this is a MDI form, it will be 
  221. auto-aligned to the top.  It can be changed programatically later so don't 
  222. worry.  Set the Name property of the Picture box to 'StatusBar'.  That's all 
  223. you need to do with it.
  224.  
  225. In the StatusBar_Resize Event, add the following snippet:
  226.  
  227.     If Me.WindowState <> 1 Then
  228.         If sb_initialized Then DisplayStatusBar Me.StatusBar, sb_panels()
  229.     End If
  230.  
  231. If you are using the SBAR_BUTTON panel, then add the following code to the 
  232. StatusBar_MouseDown  and StatusBar_MouseMove procedures:
  233.  
  234.     SBarMouseDown StatusBar, Button, Shift, X, Y, sb_panels()
  235.  
  236. then add the following snippet to the StatusBar_MouseUp procedure:
  237.  
  238.     SBarMouseUp StatusBar, Button, Shift, X, Y, sb_panels()
  239.  
  240. These procedures have been setup to deal with the SBAR_BUTTON type panels.
  241.  
  242. Once you have done this, now add a timer and set the properties to the 
  243. following:
  244.  
  245.     Enabled   True
  246.     Interval  200
  247.     Name      StatTimer
  248.  
  249. In the StatTimer_Timer procedure, add the following snippet:
  250.  
  251.     UpdateTimePanels StatusBar, sb_panels()
  252.  
  253. unless you are using an MDI form, then you want to use this procedure:
  254.  
  255.     UpdateStatusPanels StatusBar, sb_panels()
  256.  
  257. which takes care of the toggle keys you want to use.
  258.  
  259.  
  260. The last control you need to add is another picture box for the SBAR_MINICONS 
  261. if you want them in your project.  Add the PictureBox and set the following 
  262. properties:
  263.  
  264.     AutoRedraw  True
  265.     AutoSize    True
  266.     Name        sbar_pics
  267.     ScaleMode   3 - Pixel
  268.     Visible     False
  269.  
  270. The Picture property does not have to be set at design time, but it's up to 
  271. you.  Again, if you don't want to use SBAR_MINICONS or SBAR_ICONMIX, then 
  272. don't add the controls and remark out the lines that perform operations on the 
  273. sbar_pics control.
  274.  
  275.  
  276. How the Code Works
  277. -------------------------------------------------
  278.  
  279. The process involves, first, initializing the status bar by creating the 
  280. panels and then actually drawing the initial status bar.  Then as changes to 
  281. the status bar panels occur, they are redrawn.  They are redrawn on an 
  282. as-needed-basis, meaning that if the information changes in the panel, it is 
  283. redrawn and only redrawn for that panel.  The whole status bar does not have 
  284. to be redrawn unless the user resizes the form.  In this case, the resizing is 
  285. necessary because some parts of the status bar will go away and in order for 
  286. the user to see it, it has to be redrawn.  The dynamic panels of SBAR_TEXT and 
  287. SBAR_ICONMIX will adjust sizes if the status bar changes width.  What this 
  288. does is make it easier for the system to not make a change unless needed and 
  289. significantly speed up the updating of the status bar.  This is especially 
  290. useful for the Timer procedure because in many cases, it will be a quick in 
  291. and out process.  As such, if you make a change, just update the panel you 
  292. want.  In most cases, you will want to update only the text panel as you will 
  293. probably use that to display feedback to your user.
  294.  
  295.  
  296. There are no VBX's or DLL's used except for the DrawText, GetKeyState and 
  297. BitBlt API functions.  That's all that's needed.  The rest is done all through 
  298. VB code. 
  299.  
  300.  
  301. Use of the Status Bar with Menu's and Mouse Movements.
  302. -------------------------------------------------
  303.  
  304. I purposely did not include examples of how to use menu events to update the 
  305. Status Bar.  You are probably going to need a VBX that intercepts Window's 
  306. messages.  As far as mouse movements are concerned, you add those to wherever 
  307. you wish by simple calling the UpdateTextPanel procedure and pass the 
  308. StatusBar control, the Panel element from the array, and the new caption.  
  309. In this case, there is enough flexibility to abstract some of that by calling 
  310. one procedure that makes the decision of which panel gets updated and when 
  311. and then you call one procedure for any changes.  In my usage of this code, I 
  312. usually have the main form have a StatusBar only (such as an MDI form) and then 
  313. modularly declare the status panels in my application's main module.  In that 
  314. module, I have an initialization procedure and a procedure which handles the 
  315. display of the status bar.  Also, I have added pop-up menu support for turning 
  316. on and turning off specific panels by the user.  That info is saved in an INI 
  317. file so if the user wants to add GDI meter and FSR meter and a CapsLock panel, 
  318. they can do it by right clicking the mouse on the StatusBar and having a 
  319. Pop-up menu which turns off or turns on different configurations and even 
  320. changes what the panels actually show.  Some may want to have three SBAR_METER 
  321. panels, a SBAR_FULLDATE panel, the SBAR_CAPSLOCK panel, and two SBAR_MINICON 
  322. panels which monitor printing and incoming mail.   Again, it is easy to add 
  323. procedures which can increase the functionality of your StatusBar and make it 
  324. effective for your application.  While I could have added all that 
  325. functionality, time is something I don't have a lot of.  Suffice it to say, 
  326. this code is not a solution as it is more of a template.
  327.  
  328. One small not if you allow users to dynamically change or you dynamically 
  329. change the status bar panels configuration - call the DisplayStatusBar 
  330. procedure to redraw the status bar after you change the configuration so you 
  331. don't get a funny looking status bar.  An example would be like you changed 
  332. panel 2 from an SBAR_METER to an SBAR_ICONMIXED format.  Obviously, you are 
  333. going to have to redraw the whole thing again to make it look correct.  Again, 
  334. the DisplayStatusBar procedure will take care of this for you.  A better 
  335. method would be to call the Form_Resize event which automatically redraws the 
  336. status bar.
  337.  
  338. There is also those who like to use what I call a Flash Message method. What 
  339. this does is redraw the entire status bar and displays just a message.  To use 
  340. the FlashMessage, pass the StatusBar and the message you want to display and 
  341. voila.  At some point, you will need to restore the status bar.  Just call the 
  342. DisplayStatusBar procedure.  Real quick.
  343.  
  344. I would encourage you to look at the sample project to see how easy it is to 
  345. add functionality.  You can experiment with it to better understand how it 
  346. works and really get a sense of how well this can work in your application.
  347.  
  348. VB 4.0
  349. -------------------------------------------------
  350.  
  351. VB 4.0 may make this obsolete so I don't think I will do anymore with this 
  352. code.  However, if they do something and it turns out that it can't do what 
  353. this code can do.. guess what.. I will make it VB 4.0 compatible..<g>
  354.  
  355.  
  356. Disclaimer
  357. -------------------------------------------------
  358.  
  359. I hate to do this but the reason is very simple.  This code is for you to use 
  360. for FREE.  You may modify it in whatever manner you choose.  I am more 
  361. interested in helping those who are looking for something with some good 
  362. functionality, but can be tailored to fit a specific need.  Because of this:
  363.  
  364. I MAKE NO WARRANTY EITHER EXPRESSED OR IMPLIED ON THE RELIABILITY OR 
  365. USEFULNESS OF THIS PRODUCT.  I ASSUME NO LIABILITY OR RESPONSIBILITY FOR ANY 
  366. DAMAGES CAUSED BY USE OF THIS PRODUCT.  THE USER ASSUMES ALL RISK FOR USE OF 
  367. THIS PRODUCT.
  368.  
  369. If you have any questions or comments, and especially if you have suggestions 
  370. or things to add to it, you are encouraged to make contact with me.  I am very 
  371. interested to see what types of changes you make or improvements you add.  I 
  372. would very much like a copy of what you did.  I never claim nor do I ever try 
  373. to imply that I know everything, but I like to share information and if you 
  374. have some stuff for me, I would certainly love the opportunity to share code 
  375. or say hello.
  376.  
  377. Good Luck and Enjoy!
  378.  
  379. M. John Rodriguez
  380.  
  381.  
  382.  
  383.