hi. i need to get the item text length in order to prepare the buffer, how do i do this thanks.
http://msdn.microsoft.com/en-us/libr...55(VS.85).aspx
Printable View
hi. i need to get the item text length in order to prepare the buffer, how do i do this thanks.
http://msdn.microsoft.com/en-us/libr...55(VS.85).aspx
There is not any function/message which directly returns the text length of a listview item text.
You have two choices
- Allocate a buffer large enough to keep any item text of your listview or, much better...
- ...start with a reasonable buffer size and loop until it can keep the text as in the following example
Code:int nSize = 64;
int nRet = 0;
LVITEM lvi = {0};
lvi.iSubItem = nSubItem;
lvi.pszText = NULL;
do
{
nSize *= 2;
free(lvi.pszText);
lvi.pszText = (LPTSTR)calloc(nSize, sizeof(TCHAR));
lvi.cchTextMax = nSize;
nRet = (int)::SendMessage(hWndList, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
}while(nRet >= nSize - 1);
thanks alot. i was thinking about #2 but i was hoping there was a better solution...
LVS_OWNERDATA, seems to be another solution. but that seems like ALOT of work, and in this case its not reallythe best cause its to much work for nothing at all.
thanks alot for your reply
.
Making a virtual listview control (having LVS_OWNERDATA style) is a completely different approach and is good when we are dealing with very large number of items.
The list doesn't internally keep any information (text and so on) and ask for them anytime an item has to be displayed (by sending LVN_GETDISPINFO notification to its parent).
well i geuss that is really nice to have. not that i have alot of items. (on my windows i have around 270 items) they are just results from the QueryServicesStatus. and display around 6 sub items currently.
i was thinking keeping the service manager open all the time, and using the callback functions to keep all the info up to date. i made it so when i right click on an item i see the service options menu, to set the status and delete the service(i could seriously mess up my computer by deleting ntfs driver or something :O).
i am having the folowing issues tho. 1. the full row select style doesnt work :( it only selects the first item (report view ofcourse), the headers dont automaticly sort the items, i tried using the autosort style but than the windows creation failed.
here are my current styles:
i do know inline is irrelavant here cause its not going to inline it most likely.Code:inline CREATESTRUCTW m_CreateStruct(LPCWSTR name, int id , HWND parent)
{
CREATESTRUCTW cs = {0};
cs.lpszClass = WC_LISTVIEWW;
cs.lpszName = name;
cs.hInstance = CApp::Instance();
cs.hwndParent = parent;
cs.lpCreateParams = this; // doesnt really do anything.
cs.hMenu = reinterpret_cast<HMENU>(id);
cs.style = LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | WS_CHILD | WS_VISIBLE;
cs.dwExStyle = WS_EX_CLIENTEDGE | LVS_EX_FULLROWSELECT | LVS_EX_SINGLEROW;
return cs;
}
i create all controls classes, form classes, dialog classes, containers, allocators, string classes from scratch. i know there is STL, BOOST, MFC, wxWidgets, or whatever library, but i like to do evrything from scratch. I think my containers are awesome tho, lots of diffrent containers specialised for any job are good programming design imho.
okay enough babbling. Do you think in my case it will good to use the "Virtual Listview control?"
Oh and can you give me a decent tutorial or example =] thanks alot for your time!~
And i should teach myself to use capitals in evry new sentence.
No. A virtual listview control makes sense only for very large number of items (thousands, ten thousands, more...).
It doesn't internally keep any item data. It has the advantage of avoiding long time of populating many items, but can have a series of disavantages.
You have already noticed that (auto)sort doesn't work.
If no item info inside then... what to sort?... ;)
i thought it would automaticly sort on text.
can you give me an example how to make sort work? and why doesnt the fll row select work?
You can find information about dealing with listview controls in Codeguru Articles
Also you can see a virtual listview which I made in this little open project: LogExpert (note that you have to be logged-in to download sources).
Unfortunately, all these are using MFC (not raw-WinAPI), but you can pick some ideas from there.