CListCtrl shows ellipsis despite a lot of space (only Win2008 and Win7)

I use CListCtrl to display some items with icons in ListView mode. In most cases, there is only one element in the list with a lot of space to the right, but in my Win2008 (or Win7) system it cuts off the text using ellipsis (for example, "Tank" is truncated to "Ta ..."), This does not happen with all the data (even some longer lines work), but repeatedly with the example "Tank". It also works great on WinXP — always.

A list view is created via the rc file with

CONTROL "List2",IDC_LIST,"SysListView32",LVS_LIST | WS_BORDER | WS_TABSTOP,320,27,195,38 

then it is created

 myListCtrl.SubclassDlgItem( IDC_LIST, this ); myListCtrl.ModifyStyle(LVS_OWNERDRAWFIXED, LVS_SHAREIMAGELISTS | LVS_SINGLESEL | LVS_SHOWSELALWAYS); ListView_SetBkColor(myListCtrl.m_hWnd,PMAINFRM->GetColor(IDCOLOR_LI_BKG)); ListView_SetTextBkColor(myListCtrl.m_hWnd,PMAINFRM->GetColor(IDCOLOR_LI_BKG)); myListCtrl.SetImageList(PMAINFRM->GetImageList(IDICO_16),LVSIL_NORMAL); myListCtrl.SetImageList(PMAINFRM->GetImageList(IDICO_16),LVSIL_SMALL); 

I insert only 1 column with the following format:

 LV_COLUMN lvc; lvc.mask = LVCF_FMT | LVCF_SUBITEM; lvc.fmt = LVCFMT_LEFT; lvc.iSubItem = 0; myListCtrl.InsertColumn(0,&lvc); 

And the data is inserted

 int index = 0; int nItem = m_lstClass.InsertItem(index,(LPTSTR) strLabel, iIconID)); myListCtrl.SetItemData( nItem, (DWORD)index); myListCtrl.SetItemState( nItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); 

I tried

 myListCtrl.SetColumnWidth(column, LVSCW_AUTOSIZE_USEHEADER); 

as well as

 myListCtrl.SetColumnWidth(column, LVSCW_AUTOSIZE); 

AND

 myListCtrl.SetExtendedStyle(LVS_EX_AUTOSIZECOLUMNS); 

didn't do the trick either.

Any ideas?

Micah

+4
source share
4 answers

This can help you. Call this function after you have inserted all your columns and rows.

 void SizeAllColumns(CListCtrl& list) { CHeaderCtrl* pHeader = list.GetHeaderCtrl(); ASSERT(pHeader); if (pHeader) { // Turn off redraw until the columns have all been resized list.SetRedraw(FALSE); for (int iCurrCol = 0; iCurrCol < pHeader->GetItemCount(); iCurrCol++) { list.SetColumnWidth(iCurrCol, LVSCW_AUTOSIZE); int nCurrWidth = list.GetColumnWidth(iCurrCol); list.SetColumnWidth(iCurrCol, LVSCW_AUTOSIZE_USEHEADER); int nColHdrWidth = list.GetColumnWidth(iCurrCol); list.SetColumnWidth(iCurrCol, max(nCurrWidth, nColHdrWidth)); } // Now that sizing is finished, turn redraw back on and // invalidate so that the control is repainted list.SetRedraw(TRUE); list.Invalidate(); } } 
+1
source

I had this problem and I think I finally found the answer. In my case, the problem was that there was a font in the dialog box specified in this style:

 IDD_DIALOG_TurnOnOffRecords DIALOG 0, 0, 376, 263 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Turn on off records" FONT 8, "@Arial Unicode MS" . . . 

If I deleted the FONT line and the DS_SETFONT flag, CListCtrl started showing the text again without truncation.

My assumption is that it uses different fonts to measure the width of the text and actually makes a drawing, this causes truncation.

0
source

I pulled my hair out on this since I had two identical CListCtrl in the same dialog box, and one showed the ellipsis and the other did not.

The problem in my case was that the elements that I inserted had an added newline character (10) as a result of reading the elements from the file using _fgetts (). Carriage return displays the same problem.

The length of the element does not matter if it had a newline character, then the last 2 characters will be divided and replaced by ellipsis (although at least 1 character will be displayed). This problem only appeared in Vista / Windows 7 and server equivalents 2008, 2008 R2. I believe that Windows 8 and Server 2012 also show this, but have not tested it yet.

Stripping a newline character displays an item in its full glory!

0
source

In my case, an ellipsis appeared at the end of each line after resizing the list. The solution "SetRedraw (false)" before filling out the list and the "SetRedraw (true)" for finalizing the checklist (Tom Archer solution) was a solution.

0
source

Source: https://habr.com/ru/post/1393952/


All Articles