[SOLVED] Win32 Listview Problem

tekz

Active member
Joined
Aug 22, 2015
Posts
29
Hello,
I'm having problem with long strings in my win32 project. For some reason it just stops reading it after a string being x length long. Here is the code:
Code:
[COLOR=#000000][FONT=Inconsolata]HWND hListViewLog;[/FONT][/COLOR]LVCOLUMN lvLogList;
LV_ITEM lvLogItem = { [COLOR=#0000DD][B]0[/B][/COLOR] };
#[COLOR=#008800][B]define[/B][/COLOR] [COLOR=#880000]ListViewLog[/COLOR] [COLOR=#0000DD][B]400[/B][/COLOR]

[COLOR=#008800][B]void[/B][/COLOR] [COLOR=#880000]setListViewList[/COLOR](HWND hListView, LVCOLUMN lvList, [COLOR=#008800][B]int[/B][/COLOR] iSize, [COLOR=#008800][B]int[/B][/COLOR] iItem, wchar_t *wcName) {
    lvList[COLOR=#003377].mask[/COLOR] = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
    lvList[COLOR=#003377].fmt[/COLOR] = LVCFMT_LEFT;
    lvList[COLOR=#003377].iSubItem[/COLOR] = iItem;
    lvList[COLOR=#003377].cx[/COLOR] = iSize;
    lvList[COLOR=#003377].pszText[/COLOR] = wcName;
    [COLOR=#CC0000][B]ListView_InsertColumn[/B][/COLOR](hListView, iItem, &lvList);
}

hListViewLog = CreateWindowEx([COLOR=#003388][B]NULL[/B][/COLOR], WC_LISTVIEW, [COLOR=#003388][B]NULL[/B][/COLOR], WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_REPORT, [COLOR=#0000DD][B]25[/B][/COLOR], [COLOR=#0000DD][B]25[/B][/COLOR], [COLOR=#0000DD][B]745[/B][/COLOR], [COLOR=#0000DD][B]300[/B][/COLOR], hWnd, (HMENU)ListViewLog, ((LPCREATESTRUCT)lParam)->hInstance, [COLOR=#003388][B]NULL[/B][/COLOR]);
[COLOR=#880000]SendMessage[/COLOR](hListViewLog, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

[COLOR=#880000]setListViewList[/COLOR](hListViewLog, lvLogList, [COLOR=#0000DD][B]10000[/B][/COLOR], [COLOR=#0000DD][B]3[/B][/COLOR], L[COLOR=#DD2200]"Log"[/COLOR]);

lvLogItem.iItem;
[COLOR=#880000]ListView_InsertItem[/COLOR](hListViewLog, &lvLogItem); [COLOR=#880000][FONT=Inconsolata]ListView_SetItemText[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata](hListViewLog, lvLogItem.iItem, [COLOR=#0000DD][B]3[/B][/COLOR], L[COLOR=#DD2200]"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCDEFG"[/COLOR])[/FONT][/COLOR][COLOR=#000000][FONT=Inconsolata];[/FONT][/COLOR]

This is the current result:

34534.png

Any help appreciated.
 
Update:
After research I realized there is a 259 character limit for this. Now question is what would be a smart way to over come this problem.
 
As far as I know it is by design for the DISPLAY only. This means that what you see as rendered text is the limited part. The full text still exists in memory. If you need to display the full data just use a textbox and populate it based on the selected item in the listview. I haven't found a reason for any listview column to display more than 259 characters myself. Otherwise, you're going to be dealing with a bunch of complex drawing and UI handlers yourself and you'd end up with your own control drawn out on the form as a bitmap I'm sure, but it doesn't seem worth the hassle to me.
 
Last edited:
Forgot to post update, but you are right, in fact, that is what microsoft suggests as well, https://support.microsoft.com/en-us/kb/321104.

Here is code for it if anyone want to do this in the future.
Code:
if ((((LPNMHDR)lParam)->hwndFrom) == hListView)
{
   if ((((LPNMHDR)lParam)->code) == NM_DBLCLK)
   {
      int iItemIndex = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);

      wchar_t *wcData = new wchar_t[24576];
      ZeroMemory(wcData, sizeof(wchar_t) * 24576);

      LV_ITEM lvSelectedItem;
      lvSelectedItem.iItem = iItemIndex;
      lvSelectedItem.iSubItem = 3;
      lvSelectedItem.pszText = wcData;
      lvSelectedItem.cchTextMax = 24576;
      lvSelectedItem.mask = LVCF_FMT | LVCF_TEXT;

      ListView_GetItem(hListView, &lvSelectedItem);
      SetWindowText(hTextBox, wcData);

      delete[] wcData;
   }
}

Anyhow, I decided to custom draw the listview because I was going to separate different data types logged with different colors later on anyway.
 
Forgot to post update, but you are right, in fact, that is what microsoft suggests as well, https://support.microsoft.com/en-us/kb/321104.

Here is code for it if anyone want to do this in the future.
Code:
if ((((LPNMHDR)lParam)->hwndFrom) == hListView)
{
   if ((((LPNMHDR)lParam)->code) == NM_DBLCLK)
   {
      int iItemIndex = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);

      wchar_t *wcData = new wchar_t[24576];
      ZeroMemory(wcData, sizeof(wchar_t) * 24576);

      LV_ITEM lvSelectedItem;
      lvSelectedItem.iItem = iItemIndex;
      lvSelectedItem.iSubItem = 3;
      lvSelectedItem.pszText = wcData;
      lvSelectedItem.cchTextMax = 24576;
      lvSelectedItem.mask = LVCF_FMT | LVCF_TEXT;

      ListView_GetItem(hListView, &lvSelectedItem);
      SetWindowText(hTextBox, wcData);

      delete[] wcData;
   }
}

Anyhow, I decided to custom draw the listview because I was going to separate different data types logged with different colors later on anyway.

Great stuff! :) Custom drawing is a pain sometimes too I know.
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top