home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / mcm_box / read.txt < prev   
Text File  |  1994-05-31  |  23KB  |  632 lines

  1. ***************************************************************************
  2. *
  3. *  McKean Consulting
  4. *  Robin W. McKean
  5. *  1042 Braddock Circle
  6. *  Woodstock GA  30188
  7. *
  8. *  MCMBOX.VBX    V1.00.0000
  9. *
  10. *  Multi-Purpose Combobox Control for Visual Basic 3.0
  11. *
  12. ***************************************************************************
  13.  
  14. MComboBox is a custom control for managing the way your data appears in a 
  15. combobox.  MComboBox is a property for property replacement of the standard 
  16. combobox control which comes with Visual Basic 3.0.  In addition, there are 
  17. many more features which MComboBox can do that you can't do with the normal 
  18. combobox.  Some of these features are:
  19.  
  20.     * Set up owner draw columnar data in the combobox.  Your data is
  21.       arranged in columns, with specific drawing flags setup for each
  22.       "Drawing Region".  Think of each line as being broken up into
  23.       different areas, each with its own drawing flags and data.
  24.  
  25.     * Make a drawing region a bitmap.  You have control over the entire list's 
  26.       bitmaps through the default bitmap property, or you can set individual 
  27.       lines bitmap properties.
  28.  
  29.     * Control individual line colors in the list box
  30.  
  31.     * MComboBox has aligned bitmaps as well.  You specifiy the bitmap,
  32.       the text, and the alignment (top, bottom, right, left), and MComboBox
  33.       will draw the text and the bitmap in the area you define.
  34.  
  35.     * Properties to find closest match and find exact matches in the
  36.       combobox.
  37.  
  38.     * Complete control over colors in the combobox.  Colors can be
  39.       set for normal lines, individual lines, normal highlight colors,
  40.       and individual highlight colors.
  41.  
  42.     * 3-D effects
  43.  
  44.     * Handle entire drawing of items in your code
  45.  
  46.     * Set individual fonts for individual lines
  47.  
  48.     * Resort entire lists
  49.     
  50.     * Improved string searching
  51.  
  52.     * Variable height lines in the list box
  53.  
  54. MComboBox does not support simple combo boxes (the editable ones).  The
  55. main feature of MComboBox is text alignment and bitmaps.  Editable
  56. combo boxes do not lend themselves well to this style.
  57.  
  58. ***************************************************************************
  59.  
  60. This ZIP file contains:
  61.  
  62.     MCMBOX.VBX         VB version of the MComboBox custom control
  63.     PROJECT1.MAK    Sample project file for MLIST
  64.     FORM1.FRM        Form used by the sample project
  65.     FORM1.FRX        Binary file for Form1
  66.     READ.ME            This file
  67.     PLUS.BMP        Bitmap used in example
  68.     PAGE.BMP        Ditto
  69.  
  70. ***************************************************************************
  71.  
  72. REGISTRATION
  73.  
  74. Time for the sob story.  This ComboBox is Shareware.  It is NOT crippled 
  75. in anyway.  When you download this custom control, you have the same custom 
  76. control that I am using in my everyday VB programming.  As a Shareware 
  77. contributor, I am counting on the honor and moral fiber of every person who 
  78. downloads this custom control to do the right thing.  I have contributed and 
  79. participated in the Shareware arena for years now.  Your small contribution 
  80. can make a difference to me and my family...
  81.  
  82. Right now, the maximum string size in the ComboBox is 2048 characters.  Let me
  83. know if this causes a problem.  I don't anticipate anyone needing to display
  84. more than this number of characters to the screen.
  85.  
  86. If you like and appreciate this custom control...
  87.  
  88.   1)  Small time developers like me, send $10.00 to the address listed above
  89.   2)  Corporate users send $15.00 to the address listed above
  90.   3)  Register in the Compuserve SWREG forum ID 2737.
  91.  
  92. Registered users may purchase the source...
  93.  
  94.   Send $40.00 to me at the above address.
  95.   Register in the SWREG Forum Id 2738.
  96.  
  97.   If you register via CompuServe, the source will be e-mailed to you.  Please
  98.   remember, you may not purchase source unless you are a registered user.
  99.  
  100.   This control is written in C++ and has been compiled using both
  101.   Borland C++ 3.1 and Visual C++ 1.5.
  102.  
  103. You may now register this control in the SWREG on Compuserve.  Type GO SWREG.
  104.  
  105. Corporate users should register via mail or register twice in the SWREG
  106. Forum, as many of you have already done.
  107.  
  108. ***************************************************************************
  109.  
  110. WARRANTY
  111.  
  112. The control, as is, works the way that I want it to.  This does not mean
  113. that it will work the way that you want it to.   Along those lines, I
  114. totally disclaim that the control will do anything whatsoever.  This
  115. includes any implied abilities and any WARRANTIES, including those for
  116. SUITABILITY for a particular purpose, MERCHANTIBILITY, and all that other
  117. bull crap.
  118.  
  119. ***************************************************************************
  120.  
  121. PROGRAMMER'S NOTES (or, what I need to know to use this custom control)
  122.  
  123. The MCMBOX ComboBox is an enhanced Combo Box control.  The following
  124. is a desciption of each additional property,  what it does, and how to
  125. use it in your own VB programming.  For additional control properties, see
  126. those properties included in the standard combo box control.  MComboBox now
  127. contains all standard combo box properties.  The ones listed below are additions.
  128.  
  129. LinesInList
  130.  
  131. When you select the down arrow, this property helps determine the overall size
  132. of the drop down list box.
  133.  
  134. ItemDefHeight
  135.  
  136. This property is responsible for controlling the height of each individual
  137. line item in the list box.  It defaults to 195 Twips, the height of the
  138. font used by the standard list box.  You should adjust this height if you
  139. change the font, font size, etc..
  140.  
  141. DrawRegions
  142.  
  143. This item determines the number of drawing regions on each line.  This is
  144. basically equivelent to the number of COLUMNS, but this combo box will still
  145. scroll like a normal combo box.  When setting this property, the control
  146. clears the flags for the draw regions and sets them to left aligned, single
  147. line, and centered vertically.  Consult the Windows API for DrawText to
  148. see what exactly these flags mean.
  149.  
  150. ItemLength
  151.  
  152. This is an indexed property which corresponds to the length of each drawing
  153. region.  If you want a drawing region to be a specific length, set that
  154. drawing region's length to the desired setting in twips.  For example...
  155.  
  156.     MCombo1.DrawRegions = 2
  157.     MCombo1.ItemLength(1) = 500
  158.     MCombo1.ItemLength(2) = 500
  159.  
  160.     ' Generates an out of index error
  161.     MCombo1.ItemLength(0) = XXX
  162.     MCombo1.ItemLength(3) = XXX
  163.  
  164. It is probably a good idea to set the lengths of all drawing regions when you
  165. are changing the defaults.
  166.  
  167. DrawFlags
  168.  
  169. This is an indexed property which corresponds to the flags of each drawing
  170. region.  If you want a drawing region to be drawn in a specific manner, set
  171. that drawing region's flags to the desired settings.  For specific flags,
  172. look up the DrawText API function in the Windows API Reference.  In the
  173. following example, I setup two drawing regions and set the second drawing
  174. region's flags to right justify the text.  In this example, the second
  175. drawing region displays currency values.
  176.  
  177.     Const DT_RIGHT = 2
  178.     Const DT_VCENTER = 4
  179.     Const DT_SINGLELINE = 32
  180.  
  181.     MCombo1.DrawRegions = 2
  182.     MCombo1.DrawFlags(2) = DT_RIGHT + DT_VCENTER + DT_SINGLELINE
  183.     MCombo.ItemLength(1) = 500
  184.     MCombo.ItemLength(2) = 500
  185.  
  186. If you are planning to include the '&' character in your strings, you
  187. should include the DT_NOPREFIX flag to avoid the underline.  I do NOT
  188. automatically add this flag for you, as I want you to have total control
  189. over the flags.
  190.  
  191. ActiveRegion
  192.  
  193. Setting this property affects the next two properties.  It defines the
  194. DrawingRegion (or index or column) that TextRegion and ListRegion will
  195. return.  Perhaps an example is in order.
  196.  
  197. My combo box is divided up into three columns, name, account number, dollar
  198. amount.  I want to get the account number for the currently selected line
  199. as well as the first item...
  200.  
  201.     MCombo1.ActiveRegion = 2
  202.     aString$ = MCombo1.TextRegion    ' Gets 2nd column of current text
  203.     bString$ = MCombo1.ListRegion(0)    ' 2nd column of item at index 0
  204.  
  205. TextRegion
  206.  
  207. This property will return the ActiveRegion in the currently selected text.
  208. See the above "ActiveRegion".  Corresponds to a DrawRegion of the Text property.
  209. These values can also be written to at run time.
  210.  
  211. ListRegion
  212.  
  213. This property will return the ActiveRegion in the item at the specific index.
  214. See the above "ActiveRegion".  Corresponds to a DrawRegion of the List property.
  215. These values can also be written to at run time.
  216.  
  217. DefPicture
  218.  
  219. This is the default bitmap to be displayed in the ImageRegion when a specific
  220. bitmap has not been assigned to that items ItemPicture property.  Please see
  221. the demo on setting your own default picture and ItemPicture properties.
  222.  
  223. ImageType
  224.  
  225. This determines what type of image we are dealing with in our image region.
  226. If this property is set to 0, then the ImageRegion property is ignored and
  227. only text is displayed.  If this image type is valid, then a bitmap/icon is 
  228. displayed in the ImageRegion.
  229.  
  230. Note that when the image type is set to AlignBitmap, the normal drawing
  231. regions no longer apply.  Anybody got a problem with that???
  232.  
  233. ImageRegion
  234.  
  235. This property specifies which region contains the image region.  This value
  236. should be any number between 1 and the number of DrawRegions.  You may not
  237. set this property to a value of less than zero or greater then DrawRegions.
  238. When setting up your DrawRegions, the following is a good example:
  239.  
  240.     MCombo1.DrawRegions = 3
  241.     MCombo1.ImageRegion = 1
  242.  
  243.     MCombo1.ItemLength(1) = 100        ' Bitmap or Icon is in here
  244.     MCombo1.ItemLength(2) = 500
  245.     MCombo1.ItemLength(3) = 750
  246.  
  247.     ' Don't leave a space for the ImageRegion in your strings
  248.     MCombo1.AddItem "Region2" + Chr$(9) + "Region3"
  249.     MCombo1.AddItem "Region22" + Chr$(9) + "Region33"
  250.  
  251. The ImageRegion is ignored when calculating the "piece" of text that goes in
  252. that region.
  253.  
  254. ItemPicture
  255.  
  256. This property is an array of pictures which correspond to the bitmaps for
  257. each line item in the list box.  If this item is not set by you, then
  258. the MComboBox uses the DefPicture property.
  259.  
  260.     ' Change the first items picture in the list box
  261.     MCombo1.ItemPicture(0) = Image1.Picture
  262.  
  263. ItemForeColor
  264.  
  265. This property is an array of color which correspond to the foreground color
  266. for each line item in the combo box.  If this item is not set by you, then
  267. the MComboBox uses the default foreground color property.
  268.  
  269.     ' Change the first items foreground color to white
  270.     MCombo1.ItemForeColor(0) = RGB(255,255,255)
  271.  
  272. ItemBkColor
  273.  
  274. This property is an array of color which correspond to the background color
  275. for each line item in the combo box.  If this item is not set by you, then
  276. the MComboBox uses the default background color property.
  277.  
  278.     ' Change the first items background color to black
  279.     MCombo1.ItemBkColor(0) = RGB(0,0,0)
  280.  
  281. Alignment
  282.  
  283. This property controls the placement of the bitmap when the image type is
  284. set to 4, AlignBitmap.  See the demo for details, but basically the values
  285. for this property are:
  286.  
  287. 1 - Align the bitmap or icon to the left, centered, then the text, centered
  288.     vertically and left justified.
  289. 2 -    Align the bitmap or on top, centered, then the text, centered
  290.     horizontally and vertically.
  291. 3 - Align the bitmap or icon to the right, centered, then the text, centered
  292.     vertically and left justified.
  293. 4 -    Align the bitmap or icon on bottom, centered, then the text, centered
  294.     horizontally and vertically.
  295.  
  296. Note that when the image type is set to AlignBitmap, the normal drawing
  297. regions no longer apply.  Anybody got a problem with that???
  298.  
  299. FindString
  300.  
  301. Setting this property will cause the combo box to search for a string with
  302. the closest match from the current ListIndex.  If one is found, that string
  303. is set to the current ListIndex if FindResult is set to 0, otherwise, FindIndex
  304. is updated and ListIndex is left alone.  This is useful for moving items 
  305. through a combo box while typing the string in an edit control, ie.  
  306. Search in Help.
  307.  
  308. FindStringExact
  309.  
  310. This property is the same as above, except that it will search for an exact
  311. match.
  312.  
  313. HiliteForeColor,
  314.  
  315. This is the default foreground color to use when a line in the combo box is
  316. hilited.  If these colors are set, then the normal colors are ignored, and
  317. the HiliteForeColor is used to draw the text, and HiliteBackColor is used
  318. to draw the background.
  319.  
  320. You may force MComboBox to use the default colors by setting this color equal
  321. HiliteBackColor.
  322.  
  323. HiliteBackColor,
  324.  
  325. This is the default background color to use when a line in the combo box is
  326. hilited.  If these colors are set, then the normal colors are ignored, and
  327. the HiliteForeColor is used to draw the text, and HiliteBackColor is used
  328. to draw the background.
  329.  
  330. You may force MComboBox to use the default colors by setting this color equal
  331. HiliteForeColor.
  332.  
  333. ItemHiliteForeColor,
  334.  
  335. This is a property array, which corresponds to each line item in the combo box.
  336. Using this property, you can set the foreground and background hilited color
  337. of individual line items.
  338.  
  339.     MCombo1.ItemHiliteForeColor(0) = RGB(0,0,0)
  340.     MCombo1.ItemHiliteBackColor(0) = RGB(255,255,255)
  341.  
  342. ItemHiliteBackColor,
  343.  
  344. This is a property array, which corresponds to each line item in the combo box.
  345. Using this property, you can set the foreground and background hilited color
  346. of individual line items.
  347.  
  348.     MCombo1.ItemHiliteForeColor(0) = RGB(0,0,0)
  349.     MCombo1.ItemHiliteBackColor(0) = RGB(255,255,255)
  350.  
  351. MaskingColor
  352.  
  353. This color is used to mask out colors in your bitmaps when they are included
  354. in your MComboBox.  For example, lets say that you know you are not going
  355. to use the color white in your bitmaps or combo boxes, so, you can set all the
  356. pixels in your bitmap, which you want to be transparent to white, and the
  357. natural color of the combo box will show through your bitmap wherever the color
  358. white is.  Think of this as the transparent color, like in Icons, except you
  359. get to determine what it is.
  360.  
  361. BorderStyle
  362.  
  363. This property controls the border style of the combo box.  Valid values are normal,
  364. raised, and inset.
  365.  
  366. RiseColor
  367.  
  368. This is the color of the rising edge of a 3-D combo box.  Default color is white.
  369.  
  370. FallColor
  371.  
  372. This is the color of the falling edge of the 3-D combo box.  The default color
  373. is a dark grey color.
  374.  
  375. Version
  376.  
  377. This property was included by me to insure backwards compatibility.  You don't
  378. need to be concerned with its use, as I use it for different things.
  379.  
  380. FindDirection
  381.  
  382. This property now determines which direction a FindString and
  383. FindStringExact will search the combobox.  If set to 0, the search will
  384. begin at the currently active ListIndex and search to the bottom of
  385. the list.  If set to one, MComboBox will begin at the current ListIndex
  386. and search to the top of the list.
  387.  
  388. SortColumn
  389.  
  390. When using the DrawRegions property, this property can be used to determine
  391. which piece of your string determines the sort order.  For example:
  392.  
  393.     MCombo1.DrawRegions = 2
  394.     MCombo1.SortColumn = 2
  395.     MCombo1.AddItem "100" + Chr$(9) + "High"
  396.     Mlist1.AddItem "101" + Chr$(9) + "Critical"
  397.  
  398. This example would sort the combo box by priority.  Only strings added after
  399. this property is set will be affected.  If this property is changed after
  400. the strings are added, you will have to remove all the strings and then re-add
  401. them or use the Resort property.
  402.  
  403. Setting this property to 0 sorts based on the entire string.
  404.  
  405. StringCompare
  406.  
  407. This property determines whether compares are case sensitive or case
  408. insensitive.  This only affects the compare when determining placement
  409. in a Sorted combo box.  This does not affect FindString and FindStringExact
  410. properties.
  411.  
  412. Resort
  413.  
  414. Setting this property to 1 causes the list box to resort itself, provided 
  415. of course that it is a sorted combo box.  Additionally, the sort may fail 
  416. if there is not enough disk space for resorting.
  417.  
  418. DisableDrawing
  419.  
  420. I added this property to enable the developer to suspend drawing until font
  421. changes, position changes, etc. are completed.  For example, you might want
  422. to set this property to True while you are changing the font characteristics
  423. of a line that is visible in the combo box.  Before you set the last font
  424. attribute, set this value to False, and the line will redisplay itself with
  425. the correct font.
  426.  
  427. ItemFontBold
  428.  
  429. This property controls the bold attribute of an individual line item.  Set this
  430. property to true to cause that lines text to be displayed in bold.  A word of
  431. caution...  Setting the individual font attributes of each line will cause a
  432. font for that line to be created.  Windows will only support so many fonts.
  433. If you are going to be setting individual fonts, consider using the UNIMPLEMENTED
  434. property which will accept an actual font handle.  See UNIMPLEMENTED for details.
  435.  
  436.     MCombo1.ItemFontBold = True
  437.  
  438. ** You should set the font name before setting this property. **
  439.  
  440. ItemFontItalic
  441.  
  442. This property controls the italicized property of the font for a specific line.
  443. If you want a lines text to appear italicized, set this property to true for
  444. a specific line.
  445.  
  446.     MCombo1.ItemFontItalic = True
  447.  
  448. ** You should set the font name before setting this property. **
  449.  
  450. ItemFontName
  451.  
  452. This property controls the font name for a specific line of text.  You should
  453. set this property first and then set the others.  See your VB Help for details
  454. on this property "FontName".
  455.  
  456.     MCombo1.FontName = "MS Sans Serif"
  457.  
  458. ItemFontSize
  459.  
  460. This property controls the individual size for a specific line of text.
  461.  
  462.     MCombo1.ItemFontSize = 7.8
  463.  
  464. ** You should set the font name before setting this property. **
  465.  
  466. ItemFontStrikeThru
  467.  
  468. Set this property to True if you want the font for a particular line of
  469. text to have a line through it.
  470.  
  471.     MCombo1.ItemFontStrikeThru = True
  472.  
  473. ** You should set the font name before setting this property. **
  474.  
  475. ItemFontUnderline
  476.  
  477. Set this property to True if you want the font for a particular line of
  478. text to have an underline beneath it.
  479.  
  480.     MCombo1.ItemFontUnderline = True
  481.  
  482. ** You should set the font name before setting this property. **
  483.  
  484. OwnerDraw
  485.  
  486. Set this property to True if you want to control all drawing of a line.
  487. See the DrawItem event for handling drawing of a line.
  488.  
  489. ComboBoxStyle
  490.  
  491. This property determines whether the lines in a list box are a fixed
  492. height or a variable height.  Setting this property to 0 means all the
  493. lines in the combo box are a fixed height, as determined by the
  494. ItemDefHeight property.  If this property is set to 1, then the lines in
  495. the combo box are variable height.  The property AddItemHeight should
  496. be set before adding an item to the list.  After that, you can use
  497. ItemHeight to adjust the height of a line.  The reason for this is
  498. because I need the height of the line before the line is displayed,
  499. otherwise, the entire list must be redrawn when you change the height
  500. of that line with IndItemHeight.
  501.  
  502. AddItemHeight
  503.  
  504. This property determines the height of the next line to be added when
  505. the combo box is a variable height combo box.  See ComboBoxStyle above.
  506.  
  507.     MCombo1.AddItemHeight = 195        ' Default line height
  508.  
  509. ItemHeight
  510.  
  511. This property can be used to adjust the height of a line item after
  512. it has been added to the combo box.  Be aware that this causes the
  513. entire combo box to be redrawn.  You might want to disable redrawing
  514. while you adjust he height of a lot of lines.
  515.  
  516.     MCombo1.ItemHeight(0) = 395
  517.     MCombo1.ItemHeight(2) = 595
  518.  
  519. InString
  520.  
  521. Like FindString, except this property looks for a string in a string.
  522.  
  523. FindColumn
  524.  
  525. Set this propery to the column you want to search when using the 
  526. FindColumnString property.
  527.  
  528. FindColumnString
  529.  
  530. The string you want to search for in FindColumn.
  531.  
  532. FindResult
  533.  
  534. This property controls the action of MCombo after it finds a string via
  535. FindString, FindStringExact, FindColumnString, or InString.  If set to
  536. 0, then ListIndex is updated, and the image of the combo box is updated
  537. as well.  If set to one, the list box is not updated.  In either case,
  538. FindIndex is updated with the ListIndex of the found item, when an item
  539. is successfully found.
  540.  
  541. FindIndex
  542.  
  543. This property contains the ListIndex of the last successful find of an
  544. item.  This property is updated whether FindResult is set to Update List
  545. Index or or Update FindIndex.  Compare this to ListIndex or previously
  546. set FindIndex to see if a find is successful.
  547.  
  548. FindCompare
  549.  
  550. This property was added so you can make the compare function when using
  551. FindColumnString either case sensitive or case insensitive.
  552.  
  553. ***************************************************************************
  554.  
  555. New Events
  556.  
  557. SelChange()
  558.  
  559. This event is called whenever a selection in the list box is changed
  560. either through the keyboard or the mouse.  
  561.  
  562. DrawItem(ListIndex As Integer, ItemAction As Integer, ItemState As Integer, 
  563.             ItemDC As Integer, ItemLeft As Integer, ItemTop As Integer, 
  564.             ItemRight As Integer, ItemBottom As Integer, ItemText As String)
  565.  
  566. This event is called when OwnerDraw is set to True.  Owner draw basically
  567. forces you be responsible for drawing each and every line item.  The
  568. following is a brief description of the parameters.  Lookup Help for
  569. DRAWITEMSTRUCT in your WinAPI help for more details.
  570.  
  571.     ListIndex        - Index of item being drawn.  0 based.
  572.     ItemAction        - Action being performed (See DRAWITEMSTRUCT)
  573.     ItemState        - State of line (See DRAWITEMSTRUCT)
  574.     ItemDC            - DC to do the drawing with.  DON'T use MCombo1.hDC
  575.     ItemLeft        - Left coordinate of rectangle
  576.     ItemTop         - Top coordinate of rectangle
  577.     ItemRight        - Right coordinate of rectangle
  578.     ItemBottom        - Bottom coordinate of rectange
  579.     ItemText        - The text that needs to be drawn
  580.  
  581. ***************************************************************************
  582.  
  583. FORMATTING STRINGS
  584.  
  585. You should place the Tab character between each column in your string.  The
  586. following example formats a string for the DrawFlags example:
  587.  
  588.     MCombo1.AddItem "Robin W. McKean" + Chr$(9) + "$100.00"
  589.  
  590. The following string is for three columns:
  591.  
  592.     MCombo1.AddItem "Robin W. McKean"+Chr$(9)+"$100.00"+Chr$(9)+"True"
  593.  
  594. Remember, you do NOT have to include a column for the ImageRegion.  If
  595. the ImageRegion property was 1 and the DrawRegions property was 3, then
  596. the following line would work fine (3-1=2)
  597.  
  598.     MCombo1.AddItem "Robin W. McKean"+Chr$(9)+"$100.00"
  599.  
  600. ***************************************************************************
  601.  
  602. REACHING THE AUTHOR
  603.  
  604. I can be reached via U.S. Mail at the address listed above.  You can reach
  605. me via E-Mail at the following locations...
  606.  
  607. Internet:            mckean@netcom.com
  608.  
  609. Compuserve:            Robin W. McKean
  610.                     72622,1403
  611.  
  612. Shareware South:    Robin W. McKean
  613.                     Atlanta, GA
  614.  
  615. I'm on CompuServe amd NetCom once or twice a day.  I check Shareware South 
  616. about once a week.
  617.  
  618. ***************************************************************************
  619.  
  620. REVISION HISTORY
  621.  
  622. 1.00.0000    Initial Release
  623.  
  624. ***************************************************************************
  625.  
  626. ACKNOWLEDGEMENTS
  627.  
  628. Thanks to everyone who supported MList,  the other control which made this
  629. control possible.
  630.  
  631. ***************************************************************************
  632.