Click here to Skip to main content
15,902,299 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Consume Webservice in VC++ Pin
User 21559711-Jul-07 23:43
User 21559711-Jul-07 23:43 
QuestionHow to create environment variables in run-time ? ? Pin
Yanshof11-Jul-07 20:02
Yanshof11-Jul-07 20:02 
AnswerRe: How to create environment variables in run-time ? ? Pin
Hamid_RT11-Jul-07 20:19
Hamid_RT11-Jul-07 20:19 
AnswerRe: How to create environment variables in run-time ? ? Pin
Cvaji11-Jul-07 21:06
Cvaji11-Jul-07 21:06 
QuestionCListCtrl could not show icon sometimes. Pin
CooperWu11-Jul-07 19:44
CooperWu11-Jul-07 19:44 
AnswerRe: CListCtrl could not show icon sometimes. Pin
Hamid_RT11-Jul-07 19:58
Hamid_RT11-Jul-07 19:58 
GeneralRe: CListCtrl could not show icon sometimes. Pin
CooperWu11-Jul-07 20:26
CooperWu11-Jul-07 20:26 
GeneralRe: CListCtrl could not show icon sometimes. Pin
Mark Salsbery12-Jul-07 6:09
Mark Salsbery12-Jul-07 6:09 
This isn't going to work well.

You're getting an index to an icon in the system imagelist. Every time you get a new icon the
previous index becomes invalid.

From the docs for SHGetFileInfo()/SHGFI_SYSICONINDEX:
"Only those images whose indices are successfully copied to iIcon are valid. Attempting to access
other images in the system image list will result in undefined behavior.
"

You need to copy the icon to your own image list which the listview control uses.

Something like this maybe:
HICON hIcon = 0;

// Try to extract an icon from the file itself

SHFILEINFO shfi;
memset(&shfi, 0, sizeof(shfi));
if (SHGetFileInfo(pszPathname,
   FILE_ATTRIBUTE_NORMAL,
   &shfi,
   sizeof(shfi),
   SHGFI_ICON | SHGFI_SMALLICON))
{
   hIcon = shfi.hIcon;
}

// If no icon yet, get icon associated with the file type from the shell

if (hIcon == 0)
{
   LPTSTR pszExtension = PathFindExtension(pszPathname);
   CString DummyFileName;
   DummyFileName = _T("dummyfile");
   if (pszExtension[0] == _T('.'))
      DummyFileName += pszExtension;
   else
      DummyFileName += _T(".");

   SHFILEINFO shfi;
   memset(&shfi, 0, sizeof(shfi));
   if (SHGetFileInfo(DummyFileName,
      FILE_ATTRIBUTE_NORMAL,
      &shfi,
      sizeof(shfi),
      SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES))
   {
      hIcon = shfi.hIcon;
   }
}

// Add the icon to the listview's image list

if (hIcon)
{
   rItem.iImage = m_imgList.Add(hIcon);
   rItem.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
   m_lstSubmitFileList.InsertItem( &rItem );

   DestroyIcon(hIcon);
}



Mark Salsbery
Microsoft MVP - Visual C++


This episode brought to you by the number 3

GeneralRe: CListCtrl could not show icon sometimes. Pin
CooperWu12-Jul-07 15:18
CooperWu12-Jul-07 15:18 
QuestionHelp file .hpj Error Pin
sridharsb200711-Jul-07 18:49
sridharsb200711-Jul-07 18:49 
QuestionCD - DVD Writing Pin
ragavan11-Jul-07 18:21
ragavan11-Jul-07 18:21 
AnswerRe: CD - DVD Writing Pin
David Crow12-Jul-07 2:42
David Crow12-Jul-07 2:42 
Questiondocument view and dialog Pin
saisp11-Jul-07 17:49
saisp11-Jul-07 17:49 
AnswerRe: document view and dialog Pin
DevMentor.org11-Jul-07 18:51
DevMentor.org11-Jul-07 18:51 
GeneralRe: document view and dialog Pin
saisp11-Jul-07 19:07
saisp11-Jul-07 19:07 
GeneralRe: document view and dialog Pin
DevMentor.org11-Jul-07 23:29
DevMentor.org11-Jul-07 23:29 
GeneralRe: document view and dialog Pin
saisp11-Jul-07 23:43
saisp11-Jul-07 23:43 
GeneralRe: document view and dialog Pin
DevMentor.org12-Jul-07 0:55
DevMentor.org12-Jul-07 0:55 
GeneralRe: document view and dialog Pin
DevMentor.org12-Jul-07 1:02
DevMentor.org12-Jul-07 1:02 
GeneralRe: document view and dialog Pin
saisp12-Jul-07 1:15
saisp12-Jul-07 1:15 
GeneralRe: document view and dialog Pin
DevMentor.org12-Jul-07 2:23
DevMentor.org12-Jul-07 2:23 
GeneralRe: document view and dialog Pin
saisp12-Jul-07 2:34
saisp12-Jul-07 2:34 
GeneralRe: document view and dialog Pin
DevMentor.org12-Jul-07 9:32
DevMentor.org12-Jul-07 9:32 
QuestionThe ActiveX Control embeded in Web Pin
eraccn11-Jul-07 16:08
eraccn11-Jul-07 16:08 
AnswerRe: The ActiveX Control embeded in Web Pin
LoveCPlusplus18-Jul-07 0:39
LoveCPlusplus18-Jul-07 0:39 

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.