Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get en exe default icon

How to get en exe default icon

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
26 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Mark Salsbery

    Sorry about the double post. I got an error the first time. I should have checked to see if it posted first :) Mark

    K Offline
    K Offline
    Kharfax
    wrote on last edited by
    #21

    Thanks mate, and no problem about the double post. Yeap that works but I don't know why i have a lot of apps wich fail loading the icon :( I post my code, maybe someone sees what im doing wrong do { imageIndex = 0; keyNameLenght = 256; res = RegEnumKeyEx(phkResult, dwIndex, keyName, &keyNameLenght, NULL, NULL, NULL, NULL); if(res == ERROR_SUCCESS) { // Tomo icono // Busco Path en registro sprintf(lpSubKey2,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s\\", keyName); result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpSubKey2,NULL,KEY_ALL_ACCESS,&phkResult2); if (ERROR_SUCCESS == result) { //Levanto Path if (ERROR_SUCCESS == RegQueryValue(phkResult2, NULL, path, &largoBuffer)) { CString tup = path; HICON temp = NULL; HMODULE hMod = NULL; int res = 0; WORD pis = 0; tup.Remove('"'); SHFILEINFO shfi; memset(&shfi, 0, sizeof(shfi)); if (SHGetFileInfo(tup,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(shfi),SHGFI_ICON | SHGFI_SMALLICON)) { temp = shfi.hIcon; imageIndex = m_imageList.Add(temp); } else { LPTSTR pszExtension = PathFindExtension(tup); CString DummyFileName; DummyFileName = _T("dummyfile"); if (pszExtension[0] == _T('.')) DummyFileName += pszExtension; else DummyFileName += _T("."); SHFILEINFO shfi; memset(&shfi, 0, sizeof(shfi)); if (SHGetFileInfo(keyName,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(shfi),SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES)) { temp = shfi.hIcon; } if(temp != NULL) { imageIndex = m_imageList.Add(temp); } else { imageIndex = 0; } } } //Agregar Elemento lvi.mask = LVIF_TEXT | LVIF_IMAGE; lvi.iItem = 0; lvi.iSubItem = 0; lvi.pszText = keyName; lvi.iImage = imageIndex; m_listOrigin.InsertItem(&lvi); m_listOrigin.SetItem(&lvi); } } dwIndex++; }while(res != ERROR_NO_MORE_ITEMS);

    M 2 Replies Last reply
    0
    • K Kharfax

      Thanks mate, and no problem about the double post. Yeap that works but I don't know why i have a lot of apps wich fail loading the icon :( I post my code, maybe someone sees what im doing wrong do { imageIndex = 0; keyNameLenght = 256; res = RegEnumKeyEx(phkResult, dwIndex, keyName, &keyNameLenght, NULL, NULL, NULL, NULL); if(res == ERROR_SUCCESS) { // Tomo icono // Busco Path en registro sprintf(lpSubKey2,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s\\", keyName); result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpSubKey2,NULL,KEY_ALL_ACCESS,&phkResult2); if (ERROR_SUCCESS == result) { //Levanto Path if (ERROR_SUCCESS == RegQueryValue(phkResult2, NULL, path, &largoBuffer)) { CString tup = path; HICON temp = NULL; HMODULE hMod = NULL; int res = 0; WORD pis = 0; tup.Remove('"'); SHFILEINFO shfi; memset(&shfi, 0, sizeof(shfi)); if (SHGetFileInfo(tup,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(shfi),SHGFI_ICON | SHGFI_SMALLICON)) { temp = shfi.hIcon; imageIndex = m_imageList.Add(temp); } else { LPTSTR pszExtension = PathFindExtension(tup); CString DummyFileName; DummyFileName = _T("dummyfile"); if (pszExtension[0] == _T('.')) DummyFileName += pszExtension; else DummyFileName += _T("."); SHFILEINFO shfi; memset(&shfi, 0, sizeof(shfi)); if (SHGetFileInfo(keyName,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(shfi),SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES)) { temp = shfi.hIcon; } if(temp != NULL) { imageIndex = m_imageList.Add(temp); } else { imageIndex = 0; } } } //Agregar Elemento lvi.mask = LVIF_TEXT | LVIF_IMAGE; lvi.iItem = 0; lvi.iSubItem = 0; lvi.pszText = keyName; lvi.iImage = imageIndex; m_listOrigin.InsertItem(&lvi); m_listOrigin.SetItem(&lvi); } } dwIndex++; }while(res != ERROR_NO_MORE_ITEMS);

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #22

      >>...but I don't know why i have a lot of apps wich fail loading the icon What do you mean? EXEs without icons? Are you just getting the default EXE icon or none at all? Mark

      1 Reply Last reply
      0
      • K Kharfax

        Thanks mate, and no problem about the double post. Yeap that works but I don't know why i have a lot of apps wich fail loading the icon :( I post my code, maybe someone sees what im doing wrong do { imageIndex = 0; keyNameLenght = 256; res = RegEnumKeyEx(phkResult, dwIndex, keyName, &keyNameLenght, NULL, NULL, NULL, NULL); if(res == ERROR_SUCCESS) { // Tomo icono // Busco Path en registro sprintf(lpSubKey2,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s\\", keyName); result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpSubKey2,NULL,KEY_ALL_ACCESS,&phkResult2); if (ERROR_SUCCESS == result) { //Levanto Path if (ERROR_SUCCESS == RegQueryValue(phkResult2, NULL, path, &largoBuffer)) { CString tup = path; HICON temp = NULL; HMODULE hMod = NULL; int res = 0; WORD pis = 0; tup.Remove('"'); SHFILEINFO shfi; memset(&shfi, 0, sizeof(shfi)); if (SHGetFileInfo(tup,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(shfi),SHGFI_ICON | SHGFI_SMALLICON)) { temp = shfi.hIcon; imageIndex = m_imageList.Add(temp); } else { LPTSTR pszExtension = PathFindExtension(tup); CString DummyFileName; DummyFileName = _T("dummyfile"); if (pszExtension[0] == _T('.')) DummyFileName += pszExtension; else DummyFileName += _T("."); SHFILEINFO shfi; memset(&shfi, 0, sizeof(shfi)); if (SHGetFileInfo(keyName,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(shfi),SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES)) { temp = shfi.hIcon; } if(temp != NULL) { imageIndex = m_imageList.Add(temp); } else { imageIndex = 0; } } } //Agregar Elemento lvi.mask = LVIF_TEXT | LVIF_IMAGE; lvi.iItem = 0; lvi.iSubItem = 0; lvi.pszText = keyName; lvi.iImage = imageIndex; m_listOrigin.InsertItem(&lvi); m_listOrigin.SetItem(&lvi); } } dwIndex++; }while(res != ERROR_NO_MORE_ITEMS);

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #23

        >>...but I don't know why i have a lot of apps wich fail loading the icon What do you mean? EXEs without icons? Are you just getting the default EXE icon or none at all? By the way, don't forget to use DestroyIcon() on the returned HICON after you add it to your image list :) Mark

        K 1 Reply Last reply
        0
        • M Mark Salsbery

          >>...but I don't know why i have a lot of apps wich fail loading the icon What do you mean? EXEs without icons? Are you just getting the default EXE icon or none at all? By the way, don't forget to use DestroyIcon() on the returned HICON after you add it to your image list :) Mark

          K Offline
          K Offline
          Kharfax
          wrote on last edited by
          #24

          First thanks to all the people that helped me with that :D The problem wasn't the technique used to get the icon, the problem was that when I used RegQueryValue I didn't re initialized the variable with the buffer lenght :sigh: So a lot of entries were corrupt and that's why some exe didn't get an icon

          M 1 Reply Last reply
          0
          • K Kharfax

            First thanks to all the people that helped me with that :D The problem wasn't the technique used to get the icon, the problem was that when I used RegQueryValue I didn't re initialized the variable with the buffer lenght :sigh: So a lot of entries were corrupt and that's why some exe didn't get an icon

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #25

            Cool! And remember, don't forget to use DestroyIcon() on the returned HICON after you add it to your image list :) Mark

            K 1 Reply Last reply
            0
            • M Mark Salsbery

              Cool! And remember, don't forget to use DestroyIcon() on the returned HICON after you add it to your image list :) Mark

              K Offline
              K Offline
              Kharfax
              wrote on last edited by
              #26

              Done :D Thanks a lot Mark, you were really helpful

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups