|
I am creating an ownerdraw listbox. In DrawItem function I want to draw text. There's a code snippet in MSDN that is a little bit strange:
It uses this code to retrieve the text of current item.
LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
I think it's wrong because a user might add custom data to items of the control and it's logical that itemData member refers to that data, anyway it doesn't work for me. I used this code which works just fine:
GetText(lpDrawItemStruct->itemID, str);
Is this ok?. If not, then is there any better way of finding text of current item in DrawItem ?
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
Reading the MSDN documention about the DRAWITEMSTRUCT will give you the information about itemData. Hope you will...
Anyway the second method you used is not wrong.
- NS -
|
|
|
|
|
NS17 wrote: Reading the MSDN documention about the DRAWITEMSTRUCT will give you the information about itemData.
I did, and that's the reason of this question. It says something that seems to be wrong to me:
from MSDN:
itemData
For a combo box or list box, this member contains the value that was passed to the list box by one of the following:
CComboBox::AddString
CComboBox::InsertString
CListBox::AddString
CListBox::InsertString
this description with the snippet try to prove the string added can be found in itemData variable. I'm wondering at the moment, whether it differs if a list box has HAS_STRING style or not. Mine has and the itemData has not the string.
I'm completely confused
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
Hamed Mosavi wrote: it differs if a list box has HAS_STRING
Yes.
- NS -
|
|
|
|
|
A different question why you dont use of ListCtrl instead ListBox?
|
|
|
|
|
I like listbox because of its simplicity. But could you please point out the advantage of listctrl that made you to ask so?
- NS -
|
|
|
|
|
Instead my choice is Listctrl and ListBox is simple to use but its limited.
|
|
|
|
|
Hamid. wrote: but its limited.
That's true...
- NS -
|
|
|
|
|
Hamid. wrote: why you dont use of ListCtrl
Because all I need is a list of names.
CListCtrl has been designed to do more, like icons, different views(like report), good in-place edit, etc. and more flexibility cause more complexity, so one should spend a lot more time and write more codes to do the same work that could be easily done by a ListBox.
Now that I don't need those features, why should I go the hard way?
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
Hamed Mosavi wrote: Now that I don't need those features, why should I go the hard way?
I agree. It was an odd suggestion.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Your method seems fine to me - but have a look at LBS_HASTRINGS to be sure.
My suspicion is that the example snippet is just storing a pointer to some text in itemData in order to have something simple to draw. There's nothing to stop you have your code numbers in it, or neglecting it completely.
Iain.
|
|
|
|
|
I try to subclass and use this code for change background color in list control
<br />
BOOL CSubListCtrl::OnEraseBkgnd(CDC* pDC) <br />
{<br />
CRect rect;<br />
GetClientRect(&rect);<br />
pDC->FillSolidRect(0,0,rect.Width(),rect.Height(),RGB(100,200,0));<br />
return TRUE;<br />
}
it work only when first time show.
but when I add item to it, that item will change to default color.
Please help me for solve this problem.
|
|
|
|
|
I think you should override DrawItem which will be called when each item of the control is to be drawn. Then use the input parameter for that function(lpDrawItemStruct ) like this:
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
dc.FillSolidRect(&lpDrawItemStruct->rcItem, RGB(100,200,0));
dc.Detach();
You should also manually draw text of each item, check to see if it is selected to highlight it and draw a border for active item.
By the way if your list control is inside a dialog, take a look at OnCtlColor of the dialog. It makes life times easier if you just need to change background or text color of a dialog control.
-- modified at 6:59 Wednesday 3rd October, 2007
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
I wonder why you do such a thing when SetBkColor and SetTextBkColor are available for CListCtrl.
- NS -
|
|
|
|
|
|
But he needs a single bk color. So my suggestion is good, right?
- NS -
|
|
|
|
|
I didnt see your answer but I see your answer yeah its good and perfect.;) but he must tells more detaily of his control.
|
|
|
|
|
scanf consider space bar as an end of input just like an enter key(carriage return), is it possible so that it shouldn't consider space bar as an end of input.
|
|
|
|
|
does this works for you
char vl_sData1[111],vl_sData[1233];
sprintf(sData,"Hello World\n")
sscanf(sData,"%[^\n]" , vl_sData1)
|
|
|
|
|
You are only partialy correct. When scanf() is processing a %s format specifier, it will continue until it encounters a whitespace character. If there are any more format specifiers, those will then get processed.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Use gets() function.
It will scan the string till you will press enter key.
|
|
|
|
|
Hi,
how does "sizeof" operator works internally?
Thanks
-Sachin
|
|
|
|
|
Did you try a simple Google search[^]?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
I tried that also, but didn't get any solution.
-Sachin
|
|
|
|
|
Sachinpatole wrote: I tried that also, but didn't get any solution.
You are lying...
- NS -
|
|
|
|