home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
vb_code1
/
mcm_box
/
read.txt
< prev
Wrap
Text File
|
1994-05-31
|
23KB
|
632 lines
***************************************************************************
*
* McKean Consulting
* Robin W. McKean
* 1042 Braddock Circle
* Woodstock GA 30188
*
* MCMBOX.VBX V1.00.0000
*
* Multi-Purpose Combobox Control for Visual Basic 3.0
*
***************************************************************************
MComboBox is a custom control for managing the way your data appears in a
combobox. MComboBox is a property for property replacement of the standard
combobox control which comes with Visual Basic 3.0. In addition, there are
many more features which MComboBox can do that you can't do with the normal
combobox. Some of these features are:
* Set up owner draw columnar data in the combobox. Your data is
arranged in columns, with specific drawing flags setup for each
"Drawing Region". Think of each line as being broken up into
different areas, each with its own drawing flags and data.
* Make a drawing region a bitmap. You have control over the entire list's
bitmaps through the default bitmap property, or you can set individual
lines bitmap properties.
* Control individual line colors in the list box
* MComboBox has aligned bitmaps as well. You specifiy the bitmap,
the text, and the alignment (top, bottom, right, left), and MComboBox
will draw the text and the bitmap in the area you define.
* Properties to find closest match and find exact matches in the
combobox.
* Complete control over colors in the combobox. Colors can be
set for normal lines, individual lines, normal highlight colors,
and individual highlight colors.
* 3-D effects
* Handle entire drawing of items in your code
* Set individual fonts for individual lines
* Resort entire lists
* Improved string searching
* Variable height lines in the list box
MComboBox does not support simple combo boxes (the editable ones). The
main feature of MComboBox is text alignment and bitmaps. Editable
combo boxes do not lend themselves well to this style.
***************************************************************************
This ZIP file contains:
MCMBOX.VBX VB version of the MComboBox custom control
PROJECT1.MAK Sample project file for MLIST
FORM1.FRM Form used by the sample project
FORM1.FRX Binary file for Form1
READ.ME This file
PLUS.BMP Bitmap used in example
PAGE.BMP Ditto
***************************************************************************
REGISTRATION
Time for the sob story. This ComboBox is Shareware. It is NOT crippled
in anyway. When you download this custom control, you have the same custom
control that I am using in my everyday VB programming. As a Shareware
contributor, I am counting on the honor and moral fiber of every person who
downloads this custom control to do the right thing. I have contributed and
participated in the Shareware arena for years now. Your small contribution
can make a difference to me and my family...
Right now, the maximum string size in the ComboBox is 2048 characters. Let me
know if this causes a problem. I don't anticipate anyone needing to display
more than this number of characters to the screen.
If you like and appreciate this custom control...
1) Small time developers like me, send $10.00 to the address listed above
2) Corporate users send $15.00 to the address listed above
3) Register in the Compuserve SWREG forum ID 2737.
Registered users may purchase the source...
Send $40.00 to me at the above address.
Register in the SWREG Forum Id 2738.
If you register via CompuServe, the source will be e-mailed to you. Please
remember, you may not purchase source unless you are a registered user.
This control is written in C++ and has been compiled using both
Borland C++ 3.1 and Visual C++ 1.5.
You may now register this control in the SWREG on Compuserve. Type GO SWREG.
Corporate users should register via mail or register twice in the SWREG
Forum, as many of you have already done.
***************************************************************************
WARRANTY
The control, as is, works the way that I want it to. This does not mean
that it will work the way that you want it to. Along those lines, I
totally disclaim that the control will do anything whatsoever. This
includes any implied abilities and any WARRANTIES, including those for
SUITABILITY for a particular purpose, MERCHANTIBILITY, and all that other
bull crap.
***************************************************************************
PROGRAMMER'S NOTES (or, what I need to know to use this custom control)
The MCMBOX ComboBox is an enhanced Combo Box control. The following
is a desciption of each additional property, what it does, and how to
use it in your own VB programming. For additional control properties, see
those properties included in the standard combo box control. MComboBox now
contains all standard combo box properties. The ones listed below are additions.
LinesInList
When you select the down arrow, this property helps determine the overall size
of the drop down list box.
ItemDefHeight
This property is responsible for controlling the height of each individual
line item in the list box. It defaults to 195 Twips, the height of the
font used by the standard list box. You should adjust this height if you
change the font, font size, etc..
DrawRegions
This item determines the number of drawing regions on each line. This is
basically equivelent to the number of COLUMNS, but this combo box will still
scroll like a normal combo box. When setting this property, the control
clears the flags for the draw regions and sets them to left aligned, single
line, and centered vertically. Consult the Windows API for DrawText to
see what exactly these flags mean.
ItemLength
This is an indexed property which corresponds to the length of each drawing
region. If you want a drawing region to be a specific length, set that
drawing region's length to the desired setting in twips. For example...
MCombo1.DrawRegions = 2
MCombo1.ItemLength(1) = 500
MCombo1.ItemLength(2) = 500
' Generates an out of index error
MCombo1.ItemLength(0) = XXX
MCombo1.ItemLength(3) = XXX
It is probably a good idea to set the lengths of all drawing regions when you
are changing the defaults.
DrawFlags
This is an indexed property which corresponds to the flags of each drawing
region. If you want a drawing region to be drawn in a specific manner, set
that drawing region's flags to the desired settings. For specific flags,
look up the DrawText API function in the Windows API Reference. In the
following example, I setup two drawing regions and set the second drawing
region's flags to right justify the text. In this example, the second
drawing region displays currency values.
Const DT_RIGHT = 2
Const DT_VCENTER = 4
Const DT_SINGLELINE = 32
MCombo1.DrawRegions = 2
MCombo1.DrawFlags(2) = DT_RIGHT + DT_VCENTER + DT_SINGLELINE
MCombo.ItemLength(1) = 500
MCombo.ItemLength(2) = 500
If you are planning to include the '&' character in your strings, you
should include the DT_NOPREFIX flag to avoid the underline. I do NOT
automatically add this flag for you, as I want you to have total control
over the flags.
ActiveRegion
Setting this property affects the next two properties. It defines the
DrawingRegion (or index or column) that TextRegion and ListRegion will
return. Perhaps an example is in order.
My combo box is divided up into three columns, name, account number, dollar
amount. I want to get the account number for the currently selected line
as well as the first item...
MCombo1.ActiveRegion = 2
aString$ = MCombo1.TextRegion ' Gets 2nd column of current text
bString$ = MCombo1.ListRegion(0) ' 2nd column of item at index 0
TextRegion
This property will return the ActiveRegion in the currently selected text.
See the above "ActiveRegion". Corresponds to a DrawRegion of the Text property.
These values can also be written to at run time.
ListRegion
This property will return the ActiveRegion in the item at the specific index.
See the above "ActiveRegion". Corresponds to a DrawRegion of the List property.
These values can also be written to at run time.
DefPicture
This is the default bitmap to be displayed in the ImageRegion when a specific
bitmap has not been assigned to that items ItemPicture property. Please see
the demo on setting your own default picture and ItemPicture properties.
ImageType
This determines what type of image we are dealing with in our image region.
If this property is set to 0, then the ImageRegion property is ignored and
only text is displayed. If this image type is valid, then a bitmap/icon is
displayed in the ImageRegion.
Note that when the image type is set to AlignBitmap, the normal drawing
regions no longer apply. Anybody got a problem with that???
ImageRegion
This property specifies which region contains the image region. This value
should be any number between 1 and the number of DrawRegions. You may not
set this property to a value of less than zero or greater then DrawRegions.
When setting up your DrawRegions, the following is a good example:
MCombo1.DrawRegions = 3
MCombo1.ImageRegion = 1
MCombo1.ItemLength(1) = 100 ' Bitmap or Icon is in here
MCombo1.ItemLength(2) = 500
MCombo1.ItemLength(3) = 750
' Don't leave a space for the ImageRegion in your strings
MCombo1.AddItem "Region2" + Chr$(9) + "Region3"
MCombo1.AddItem "Region22" + Chr$(9) + "Region33"
The ImageRegion is ignored when calculating the "piece" of text that goes in
that region.
ItemPicture
This property is an array of pictures which correspond to the bitmaps for
each line item in the list box. If this item is not set by you, then
the MComboBox uses the DefPicture property.
' Change the first items picture in the list box
MCombo1.ItemPicture(0) = Image1.Picture
ItemForeColor
This property is an array of color which correspond to the foreground color
for each line item in the combo box. If this item is not set by you, then
the MComboBox uses the default foreground color property.
' Change the first items foreground color to white
MCombo1.ItemForeColor(0) = RGB(255,255,255)
ItemBkColor
This property is an array of color which correspond to the background color
for each line item in the combo box. If this item is not set by you, then
the MComboBox uses the default background color property.
' Change the first items background color to black
MCombo1.ItemBkColor(0) = RGB(0,0,0)
Alignment
This property controls the placement of the bitmap when the image type is
set to 4, AlignBitmap. See the demo for details, but basically the values
for this property are:
1 - Align the bitmap or icon to the left, centered, then the text, centered
vertically and left justified.
2 - Align the bitmap or on top, centered, then the text, centered
horizontally and vertically.
3 - Align the bitmap or icon to the right, centered, then the text, centered
vertically and left justified.
4 - Align the bitmap or icon on bottom, centered, then the text, centered
horizontally and vertically.
Note that when the image type is set to AlignBitmap, the normal drawing
regions no longer apply. Anybody got a problem with that???
FindString
Setting this property will cause the combo box to search for a string with
the closest match from the current ListIndex. If one is found, that string
is set to the current ListIndex if FindResult is set to 0, otherwise, FindIndex
is updated and ListIndex is left alone. This is useful for moving items
through a combo box while typing the string in an edit control, ie.
Search in Help.
FindStringExact
This property is the same as above, except that it will search for an exact
match.
HiliteForeColor,
This is the default foreground color to use when a line in the combo box is
hilited. If these colors are set, then the normal colors are ignored, and
the HiliteForeColor is used to draw the text, and HiliteBackColor is used
to draw the background.
You may force MComboBox to use the default colors by setting this color equal
HiliteBackColor.
HiliteBackColor,
This is the default background color to use when a line in the combo box is
hilited. If these colors are set, then the normal colors are ignored, and
the HiliteForeColor is used to draw the text, and HiliteBackColor is used
to draw the background.
You may force MComboBox to use the default colors by setting this color equal
HiliteForeColor.
ItemHiliteForeColor,
This is a property array, which corresponds to each line item in the combo box.
Using this property, you can set the foreground and background hilited color
of individual line items.
MCombo1.ItemHiliteForeColor(0) = RGB(0,0,0)
MCombo1.ItemHiliteBackColor(0) = RGB(255,255,255)
ItemHiliteBackColor,
This is a property array, which corresponds to each line item in the combo box.
Using this property, you can set the foreground and background hilited color
of individual line items.
MCombo1.ItemHiliteForeColor(0) = RGB(0,0,0)
MCombo1.ItemHiliteBackColor(0) = RGB(255,255,255)
MaskingColor
This color is used to mask out colors in your bitmaps when they are included
in your MComboBox. For example, lets say that you know you are not going
to use the color white in your bitmaps or combo boxes, so, you can set all the
pixels in your bitmap, which you want to be transparent to white, and the
natural color of the combo box will show through your bitmap wherever the color
white is. Think of this as the transparent color, like in Icons, except you
get to determine what it is.
BorderStyle
This property controls the border style of the combo box. Valid values are normal,
raised, and inset.
RiseColor
This is the color of the rising edge of a 3-D combo box. Default color is white.
FallColor
This is the color of the falling edge of the 3-D combo box. The default color
is a dark grey color.
Version
This property was included by me to insure backwards compatibility. You don't
need to be concerned with its use, as I use it for different things.
FindDirection
This property now determines which direction a FindString and
FindStringExact will search the combobox. If set to 0, the search will
begin at the currently active ListIndex and search to the bottom of
the list. If set to one, MComboBox will begin at the current ListIndex
and search to the top of the list.
SortColumn
When using the DrawRegions property, this property can be used to determine
which piece of your string determines the sort order. For example:
MCombo1.DrawRegions = 2
MCombo1.SortColumn = 2
MCombo1.AddItem "100" + Chr$(9) + "High"
Mlist1.AddItem "101" + Chr$(9) + "Critical"
This example would sort the combo box by priority. Only strings added after
this property is set will be affected. If this property is changed after
the strings are added, you will have to remove all the strings and then re-add
them or use the Resort property.
Setting this property to 0 sorts based on the entire string.
StringCompare
This property determines whether compares are case sensitive or case
insensitive. This only affects the compare when determining placement
in a Sorted combo box. This does not affect FindString and FindStringExact
properties.
Resort
Setting this property to 1 causes the list box to resort itself, provided
of course that it is a sorted combo box. Additionally, the sort may fail
if there is not enough disk space for resorting.
DisableDrawing
I added this property to enable the developer to suspend drawing until font
changes, position changes, etc. are completed. For example, you might want
to set this property to True while you are changing the font characteristics
of a line that is visible in the combo box. Before you set the last font
attribute, set this value to False, and the line will redisplay itself with
the correct font.
ItemFontBold
This property controls the bold attribute of an individual line item. Set this
property to true to cause that lines text to be displayed in bold. A word of
caution... Setting the individual font attributes of each line will cause a
font for that line to be created. Windows will only support so many fonts.
If you are going to be setting individual fonts, consider using the UNIMPLEMENTED
property which will accept an actual font handle. See UNIMPLEMENTED for details.
MCombo1.ItemFontBold = True
** You should set the font name before setting this property. **
ItemFontItalic
This property controls the italicized property of the font for a specific line.
If you want a lines text to appear italicized, set this property to true for
a specific line.
MCombo1.ItemFontItalic = True
** You should set the font name before setting this property. **
ItemFontName
This property controls the font name for a specific line of text. You should
set this property first and then set the others. See your VB Help for details
on this property "FontName".
MCombo1.FontName = "MS Sans Serif"
ItemFontSize
This property controls the individual size for a specific line of text.
MCombo1.ItemFontSize = 7.8
** You should set the font name before setting this property. **
ItemFontStrikeThru
Set this property to True if you want the font for a particular line of
text to have a line through it.
MCombo1.ItemFontStrikeThru = True
** You should set the font name before setting this property. **
ItemFontUnderline
Set this property to True if you want the font for a particular line of
text to have an underline beneath it.
MCombo1.ItemFontUnderline = True
** You should set the font name before setting this property. **
OwnerDraw
Set this property to True if you want to control all drawing of a line.
See the DrawItem event for handling drawing of a line.
ComboBoxStyle
This property determines whether the lines in a list box are a fixed
height or a variable height. Setting this property to 0 means all the
lines in the combo box are a fixed height, as determined by the
ItemDefHeight property. If this property is set to 1, then the lines in
the combo box are variable height. The property AddItemHeight should
be set before adding an item to the list. After that, you can use
ItemHeight to adjust the height of a line. The reason for this is
because I need the height of the line before the line is displayed,
otherwise, the entire list must be redrawn when you change the height
of that line with IndItemHeight.
AddItemHeight
This property determines the height of the next line to be added when
the combo box is a variable height combo box. See ComboBoxStyle above.
MCombo1.AddItemHeight = 195 ' Default line height
ItemHeight
This property can be used to adjust the height of a line item after
it has been added to the combo box. Be aware that this causes the
entire combo box to be redrawn. You might want to disable redrawing
while you adjust he height of a lot of lines.
MCombo1.ItemHeight(0) = 395
MCombo1.ItemHeight(2) = 595
InString
Like FindString, except this property looks for a string in a string.
FindColumn
Set this propery to the column you want to search when using the
FindColumnString property.
FindColumnString
The string you want to search for in FindColumn.
FindResult
This property controls the action of MCombo after it finds a string via
FindString, FindStringExact, FindColumnString, or InString. If set to
0, then ListIndex is updated, and the image of the combo box is updated
as well. If set to one, the list box is not updated. In either case,
FindIndex is updated with the ListIndex of the found item, when an item
is successfully found.
FindIndex
This property contains the ListIndex of the last successful find of an
item. This property is updated whether FindResult is set to Update List
Index or or Update FindIndex. Compare this to ListIndex or previously
set FindIndex to see if a find is successful.
FindCompare
This property was added so you can make the compare function when using
FindColumnString either case sensitive or case insensitive.
***************************************************************************
New Events
SelChange()
This event is called whenever a selection in the list box is changed
either through the keyboard or the mouse.
DrawItem(ListIndex As Integer, ItemAction As Integer, ItemState As Integer,
ItemDC As Integer, ItemLeft As Integer, ItemTop As Integer,
ItemRight As Integer, ItemBottom As Integer, ItemText As String)
This event is called when OwnerDraw is set to True. Owner draw basically
forces you be responsible for drawing each and every line item. The
following is a brief description of the parameters. Lookup Help for
DRAWITEMSTRUCT in your WinAPI help for more details.
ListIndex - Index of item being drawn. 0 based.
ItemAction - Action being performed (See DRAWITEMSTRUCT)
ItemState - State of line (See DRAWITEMSTRUCT)
ItemDC - DC to do the drawing with. DON'T use MCombo1.hDC
ItemLeft - Left coordinate of rectangle
ItemTop - Top coordinate of rectangle
ItemRight - Right coordinate of rectangle
ItemBottom - Bottom coordinate of rectange
ItemText - The text that needs to be drawn
***************************************************************************
FORMATTING STRINGS
You should place the Tab character between each column in your string. The
following example formats a string for the DrawFlags example:
MCombo1.AddItem "Robin W. McKean" + Chr$(9) + "$100.00"
The following string is for three columns:
MCombo1.AddItem "Robin W. McKean"+Chr$(9)+"$100.00"+Chr$(9)+"True"
Remember, you do NOT have to include a column for the ImageRegion. If
the ImageRegion property was 1 and the DrawRegions property was 3, then
the following line would work fine (3-1=2)
MCombo1.AddItem "Robin W. McKean"+Chr$(9)+"$100.00"
***************************************************************************
REACHING THE AUTHOR
I can be reached via U.S. Mail at the address listed above. You can reach
me via E-Mail at the following locations...
Internet: mckean@netcom.com
Compuserve: Robin W. McKean
72622,1403
Shareware South: Robin W. McKean
Atlanta, GA
I'm on CompuServe amd NetCom once or twice a day. I check Shareware South
about once a week.
***************************************************************************
REVISION HISTORY
1.00.0000 Initial Release
***************************************************************************
ACKNOWLEDGEMENTS
Thanks to everyone who supported MList, the other control which made this
control possible.
***************************************************************************