Click here to Skip to main content
15,878,231 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ofstream optimization problem Pin
doug2518-Jul-13 2:48
doug2518-Jul-13 2:48 
GeneralRe: ofstream optimization problem Pin
Richard MacCutchan18-Jul-13 2:56
mveRichard MacCutchan18-Jul-13 2:56 
GeneralRe: ofstream optimization problem Pin
doug2518-Jul-13 3:16
doug2518-Jul-13 3:16 
GeneralRe: ofstream optimization problem Pin
doug2518-Jul-13 3:31
doug2518-Jul-13 3:31 
GeneralRe: ofstream optimization problem Pin
Richard MacCutchan18-Jul-13 3:50
mveRichard MacCutchan18-Jul-13 3:50 
GeneralRe: ofstream optimization problem Pin
Jochen Arndt17-Jul-13 21:08
professionalJochen Arndt17-Jul-13 21:08 
GeneralRe: ofstream optimization problem Pin
doug2518-Jul-13 2:55
doug2518-Jul-13 2:55 
QuestionWin32 ListView control doesn't display any icons Pin
Jonathan Davies16-Jul-13 7:48
Jonathan Davies16-Jul-13 7:48 
Using VS2008 Prof. on Windows8, a Win32 ListView control in Report mode doesn't display any icons at the start of each row. It shows data which I can sort, but no icons.

I'm assuming its some bit or attribute not set somewhere so have to show all the relevant code for someone to see what I'm missing. The list (header)setup code is here (followed by the row insertion code taken out of its loop and then my test code). All error handling removed. I've compared this to an ATL/WTL program that shows the icons and I can't see any difference.

The image list is initialised by the CDeviceImageList constructor which uses the below code to initialize the list:
C++
class CDeviceImageList
{
private:
	SP_CLASSIMAGELIST_DATA m_spImageData;		//!< Structure containing class image list information.
public:
	/**
		Builds an image-list that contains bitmaps for every installed device-class.
	*/
	CDeviceImageList()
	{
		RtlZeroMemory(&m_spImageData, sizeof(SP_CLASSIMAGELIST_DATA));
		m_spImageData.cbSize = sizeof(SP_CLASSIMAGELIST_DATA);
		BOOL b = SetupDiGetClassImageList(&m_spImageData);
		if(FALSE == b)
		{
			assert(!"Failed to aquire class image list");
		}
	}
         
	operator HIMAGELIST() const throw()
	{ 
		return m_spImageData.ImageList; 
	}

...


ListView setup before the data ...
C++
LVITEM lvItem;
SecureZeroMemory(&lvItem, sizeof(LVITEM));

LVCOLUMN lvCol;
SecureZeroMemory(&lvCol, sizeof(LVCOLUMN));

HWND hList=GetDlgItem(hwnd,IDC_LIST1);

lvCol.pszText=L"Port";                                  // First Header Text
lvCol.mask=LVCF_TEXT;                                   // .pszText is valid


lvCol.cx=60;                                            // width of coloumn 1
lvCol.mask   |= LVCF_WIDTH;                             // .cx (width) is valid


lvCol.iSubItem = 0;                                     // Col 0
lvCol.mask  |= LVCF_SUBITEM;                            // .iSubItem is valid

lvCol.fmt   = HDF_SORTUP;                               // Set an up arrow
lvCol.fmt     |= LVCFMT_LEFT;                           // and left-align the column.
lvCol.mask  |= LVCF_FMT;                                // .format is valid

int nCol = 0;
nCol = ListView_InsertColumn(hList, lvCol.iSubItem, &lvCol);



lvCol.iSubItem = 1;                                     // Col 1
lvCol.pszText=L"Device";                                // Col 1 title
lvCol.cx=220;                                           // Col 1 width
nCol = ListView_InsertColumn(hList, lvCol.iSubItem, &lvCol);


lvCol.iSubItem = 2;                                     // Col 2
lvCol.pszText=L"Manufacturer";                          // Col 2 title
lvCol.cx=100;                                            // width of coloumn
nCol = ListView_InsertColumn(hList, lvCol.iSubItem, &lvCol);



CDeviceImageList cImageList;
HIMAGELIST hImageList = cImageList;

HIMAGELIST hRet = ListView_SetImageList(hList,  hImageList, LVSIL_SMALL,);

ListView_SetExtendedListViewStyle(hList, LVS_EX_INFOTIP | LVS_SHOWSELALWAYS);

At this point I can get the image list back from the ListView
The relevant row insertion code, after which I can get the icons, is below but the ListView doesn't display them...
C++
LVITEM lvItem;
SecureZeroMemory(&lvItem, sizeof(LVITEM));
lvItem.mask=LVIF_TEXT;             // Text Style
lvItem.cchTextMax = 0;           // Max size of text

lvItem.iItem=n;                    // choose item  - n is loop counter here
lvItem.iSubItem=0;                 // Put in first coloumn
lvItem.pszText=m_pData[n]->szName;  // Text to display

lvItem.iImage = ImageIndex;
lvItem.mask |= LVIF_IMAGE;


lvItem.lParam=(LPARAM)m_pData[n];
lvItem.mask |= LVIF_PARAM;

// Get the list view handle
HWND hList=GetDlgItem(hwnd,IDC_LIST1);


int nItemIndex = ListView_InsertItem(hList, &lvItem); // Send info to the Listview

//Presuming don't need lParam set any more...
lvItem.lParam=0;
lvItem.mask &= ~LVIF_PARAM;

//Nor image
lvItem.iImage = 0;
lvItem.mask &= ~LVIF_IMAGE;

lvItem.iSubItem=1;
lvItem.pszText=(LPTSTR)(LPCTSTR)szData[n][1];
ListView_SetItem(hList, &lvItem); // Enter text to SubItems


lvItem.iSubItem=2;
lvItem.pszText=(LPTSTR)(LPCTSTR)szData[n][2];
ListView_SetItem(hList, &lvItem); // Enter text to SubItems


After each loop above I can use the following three lines to get the icons (and a few more to display them as proof). But the ListView still refuses to show them...

HWND hList=GetDlgItem(hwnd,IDC_LIST1);
HIMAGELIST hGotList = ListView_GetImageList(hList, LVSIL_SMALL);
HICON hIcon = ImageList_GetIcon(hGotList, ImageIndex, ILD_NORMAL);


modified 17-Jul-13 5:07am.

QuestionRe: Win32 ListView control doesn't display any icons Pin
Randor 16-Jul-13 13:01
professional Randor 16-Jul-13 13:01 
AnswerRe: Win32 ListView control doesn't display any icons Pin
Jonathan Davies16-Jul-13 23:49
Jonathan Davies16-Jul-13 23:49 
AnswerRe: Win32 ListView control doesn't display any icons Pin
Richard MacCutchan16-Jul-13 20:59
mveRichard MacCutchan16-Jul-13 20:59 
GeneralRe: Win32 ListView control doesn't display any icons Pin
Jonathan Davies16-Jul-13 23:24
Jonathan Davies16-Jul-13 23:24 
GeneralRe: Win32 ListView control doesn't display any icons Pin
Richard MacCutchan17-Jul-13 1:33
mveRichard MacCutchan17-Jul-13 1:33 
GeneralRe: Win32 ListView control doesn't display any icons Pin
Jonathan Davies17-Jul-13 2:27
Jonathan Davies17-Jul-13 2:27 
GeneralRe: Win32 ListView control doesn't display any icons Pin
Richard MacCutchan17-Jul-13 4:49
mveRichard MacCutchan17-Jul-13 4:49 
GeneralRe: Win32 ListView control doesn't display any icons Pin
Jonathan Davies17-Jul-13 6:42
Jonathan Davies17-Jul-13 6:42 
GeneralRe: Win32 ListView control doesn't display any icons Pin
Richard MacCutchan17-Jul-13 7:33
mveRichard MacCutchan17-Jul-13 7:33 
AnswerRe: Win32 ListView control doesn't display any icons Pin
Jonathan Davies18-Jul-13 0:19
Jonathan Davies18-Jul-13 0:19 
GeneralRe: Win32 ListView control doesn't display any icons Pin
Richard MacCutchan18-Jul-13 0:39
mveRichard MacCutchan18-Jul-13 0:39 
GeneralRe: Win32 ListView control doesn't display any icons Pin
Richard MacCutchan17-Jul-13 7:50
mveRichard MacCutchan17-Jul-13 7:50 
QuestionHow can make smooth horizontal scroll on ListControl?? Pin
Sun-Mi Kang14-Jul-13 21:21
Sun-Mi Kang14-Jul-13 21:21 
AnswerRe: How can make smooth horizontal scroll on ListControl?? Pin
Richard MacCutchan14-Jul-13 22:24
mveRichard MacCutchan14-Jul-13 22:24 
QuestionHow to use listview_insertgroup with custom draw? Pin
JoneLe8614-Jul-13 18:39
JoneLe8614-Jul-13 18:39 
QuestionRe: How to use listview_insertgroup with custom draw? Pin
Richard MacCutchan14-Jul-13 21:19
mveRichard MacCutchan14-Jul-13 21:19 
AnswerRe: How to use listview_insertgroup with custom draw? Pin
JoneLe8619-Jul-13 8:42
JoneLe8619-Jul-13 8:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.