on the screen.
AliR.
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
Note that GetText applies only to owner draw buttons with the
LBS_HASSTRINGS style.
Otherwise, it is pretty meaningless. Usually, you work directly from the
ItemData value.
In a couple cases I had a little "interpretive language" I "executed" to
do the drawing.
for example, it would have a command to draw a string, then a bitmap, then
another string,
then another bitmap, etc. I would set a string that said
< |i|w|e>Text of message <iconname> more text <iconname>
where the first element was <> (no level) <i> (information) <w> (warning)
<e> (error) and
would therefore display no icon, a circle-i,
exclamation-point-in-yellow-triangle or
stop-sign, then some text, then suitable icons from the set of named icons
in the
indicated places. When I did the AddString, my AddString method would
parse this and
create a little piece of "interpretive code" that would cause the symbols
to be displayed
CArray<MessageObject> code;
class MessageObject { public: virtual void Show(CDC & dc) PURE; }
class Icon : public MessageObject {
protected:
HICON icon;
public:
Icon(HICON h) { icon = h; }
virtual void show(CDC & dc) {
CPoint pt = dc.GetCurrentPos();
dc.DrawIcon(pt.x, pt.y, icon);
dc.MoveTo(pt.x + ::GetSystemMetrics(SM_CXSMALLICON), pt.y);
}
};
class Text : public MessageObject {
protected:
CString text;
public:
Text(const CString & s) { text = s; }
virtual void show(CDC & dc) {
dc.SetAlign(TA_UPDATECP);
dc.TextOut(0, 0, text);
}
};
The "interpreter" was
for(int i = 0; i < code.GetSize(); i++)
code[i].show(dc);
In another case, I just parsed the string on the fly (the above code is
really a subset of
what was going on; there were also commands to "speak" the text, perform
parameter
subsitution in the style of %1, %2, etc. of FormatMessage (this was done
in Win16, before
FormatMessage), and so on)
joe
On Mon, 20 Jul 2009 15:05:41 -0500, "AliR" <AliR@online.nospam> wrote:
When the WM_DRAWITEM gets called you will need to call CListBox::GetText
to
get the text of the item that needs to be drawn and here you can do
whatever
you want to the text before you actually draw it in your draw item method.
For example the text of the item could be "This is a test" and you can
draw
"This is something else" along with some bitmaps next to it.
AliR.
"nexolite" <nexolite@discussions.microsoft.com> wrote in message
news:0ADBD8F9-1FE4-4707-B4A1-43354591A466@microsoft.com...
Thank you very much.
I will definitely look at the examples you pointed.
I also want to know, when I call CListBox::AddString() does WM_DRAWITEM
message gets sent?
because I need to get the string(that was added using AddString() ) in
WM_DRAWITEM handler and check the string for certain characters and then
replace those characters with bitmap
Is this way of doing this?
"Joseph M. Newcomer" wrote:
As indicated, owner-draw. Take a look at my Logging ListBox Control,
for
example, to see
textual displays, or my Gradient Fill Explorer for bitmaps (although it
is a combo box,
the code is nearly identical for a listbox); the code can be adapted
and
hybridized to
your heart's content. Once you do an owner-draw listbox, you will
realize this is a
really cool way to do list boxes.
joe
On Mon, 20 Jul 2009 04:48:01 -0700, nexolite
<nexolite@discussions.microsoft.com> wrote:
Hi,
How can I add colored text in the CListBox
and display a bitmap along with strings.
Thank you
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm