jespadas
asked on
Error on listbox with more lines in each item
Hi.
I picked the answer of ListBox with more lines in each item. I tried it and it worked when I use addString with a text directly, but when I put text in a varible like CString or others, I only see unknown or no characters in the items. I am sending some code...
In the CtrlTest example of VC++ 1.52 (custlist.cpp)I did the following:
1). for the class CColorListBox, I wrote a function
void AddTextItem (LPCSTR text)
{ AddString(text);
}
2). I change the item height to 80
#define TEXT_ITEM_HEIGHT 80
void CColorListBox::MeasureItem (LPMEASURE ITEMSTRUCT lpMIS)
{ // all items are of fixed size
// must use LBS_OWNERDRAWVARIABLE for this to work
lpMIS->itemHeight = TEXT_ITEM_HEIGHT;
}
3).I change the first "if" statement of this function using a Drawtext()
void CColorListBox::DrawItem(LP DRAWITEMST RUCT lpDIS)
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC );
COLORREF cr = (COLORREF)pDC->GetBkColor( );
LPCSTR szText=(LPCSTR)lpDIS->item Data;
if (lpDIS->itemAction & ODA_DRAWENTIRE)
{
pDC->DrawText(szText,-1,&l pDIS->rcIt em,DT_LEFT |
DT_EXTERNALLEADING | DT_NOCLIP | DT_NOPREFIX |
DT_WORDBREAK);
}
....
.the same code.
....
}
4).On the Dialog part(OnInitDialog) I insert my strings
//this works
AddTextItem("Name:jespadas \nJob:Engi neer\nAge: 28")
//this does´t work
char mistr[300]="Name:jespadas\ nJob:Engin eer\nAge:2 8"
m_colors.AddTextItem(mistr );
Acording to this code what it is going on?
Why I am loosing the string value?
Thanks, I will appreciate any help.
I picked the answer of ListBox with more lines in each item. I tried it and it worked when I use addString with a text directly, but when I put text in a varible like CString or others, I only see unknown or no characters in the items. I am sending some code...
In the CtrlTest example of VC++ 1.52 (custlist.cpp)I did the following:
1). for the class CColorListBox, I wrote a function
void AddTextItem (LPCSTR text)
{ AddString(text);
}
2). I change the item height to 80
#define TEXT_ITEM_HEIGHT 80
void CColorListBox::MeasureItem
{ // all items are of fixed size
// must use LBS_OWNERDRAWVARIABLE for this to work
lpMIS->itemHeight = TEXT_ITEM_HEIGHT;
}
3).I change the first "if" statement of this function using a Drawtext()
void CColorListBox::DrawItem(LP
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC
COLORREF cr = (COLORREF)pDC->GetBkColor(
LPCSTR szText=(LPCSTR)lpDIS->item
if (lpDIS->itemAction & ODA_DRAWENTIRE)
{
pDC->DrawText(szText,-1,&l
DT_EXTERNALLEADING | DT_NOCLIP | DT_NOPREFIX |
DT_WORDBREAK);
}
....
.the same code.
....
}
4).On the Dialog part(OnInitDialog) I insert my strings
//this works
AddTextItem("Name:jespadas
//this does´t work
char mistr[300]="Name:jespadas\
m_colors.AddTextItem(mistr
Acording to this code what it is going on?
Why I am loosing the string value?
Thanks, I will appreciate any help.
ASKER
What I have is a OwnerDraw ListBox that I did with different behaivor. this is a copy of the question I picked from "jeeg" user.
Hi experts!
I would like to do a ListBox with several lines in each item, like this:
--------------------------
id:nnnn |
name: xxxxxxxxxxx > item 1
hobie: yyyyyyyyy |
--------------------------
id:nnnn |
name: xxxxxxxxxxx > item 2
hobie: yyyyyyyyy |
--------------------------
I tried using an AddString with "\n" and "\r" between strings, but it does not work. I have reviewed some multicolumn samples
but I need a diferent kind of viewing my data.
In addtion I new in MFC and need to do it on VC++ 1.52.
Somebody answer to him that the CtrlTest sample on VC 1.5x had something like that, but he needed use DrawText rather then paint a color...
Hi experts!
I would like to do a ListBox with several lines in each item, like this:
--------------------------
id:nnnn |
name: xxxxxxxxxxx > item 1
hobie: yyyyyyyyy |
--------------------------
id:nnnn |
name: xxxxxxxxxxx > item 2
hobie: yyyyyyyyy |
--------------------------
I tried using an AddString with "\n" and "\r" between strings, but it does not work. I have reviewed some multicolumn samples
but I need a diferent kind of viewing my data.
In addtion I new in MFC and need to do it on VC++ 1.52.
Somebody answer to him that the CtrlTest sample on VC 1.5x had something like that, but he needed use DrawText rather then paint a color...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am sorry if I did not accept before.
I just was evaluating and doing some code.
very good answer!
Thank you,
I just was evaluating and doing some code.
very good answer!
Thank you,
1) For List Boxes in VC 5.0, I send the box a message, like this:
SendDlgItemMessage(IDC_HOS
Where IDC_HOSTNAME is the name of the ListBox,
CB_ADDSTRING tells it to add a string,
host is the parameter (char, not CString, but CString might work, not sure), but this does add a dtring to the next line in the box. Do a search for "CB_" to find all the things you can send to a box though SendDlg...
2) The other thing, if your \n's. I had trouble with this come to think of it, in an edit box. Try \r\n or \n\r instead of just \n. Worth a try.
You could also do some error checking (assuming you haven't already), output the value of mistr to the screen in a AfxMessageBox (or the debugger could help, I'm not familiar with it...) and make sure it has in it the value you think it does.
Hope something here helps.
-Dex Man