C++/(Shell)바탕화면 아이콘 개체들 조회

  1. HRESULT hr;
  2. LPSHELLFOLDER lpsf = NULL;
  3. hr = ::SHGetDesktopFolder(&lpsf);
  4. if (FAILED(hr))
  5.     throw CString(_T("SHGetDestktopFolder error"));
  6. IEnumIDList* pEnumIDList = NULL;
  7. hr = lpsf->EnumObjects(::GetParent(m_hWnd), SHCONTF_FOLDERS | SHCONTF_NONFOLDERS,
  8.     &pEnumIDList);
  9. if (FAILED(hr))
  10.     throw CString(_T("lpsf->EnumObjects error"));
  11. LPITEMIDLIST pItemIDList;
  12. ULONG fetched;
  13. while (pEnumIDList->Next(1, &pItemIDList, &fetched) == S_OK)
  14. {
  15.     ULONG attrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER;    // 획득하려는 속성
  16.     hr = lpsf->GetAttributesOf(1, (const struct _ITEMIDLIST**)&pItemIDList, &attrs);
  17.     if (hr != S_OK)
  18.         throw CString(_T("lpsf->GettAttributesOf error"));
  19.     STRRET str; // 이름을 받을 구조체
  20.     hr = lpsf->GetDisplayNameOf(pItemIDList, SHGDN_NORMAL, &str);
  21.     if (hr != S_OK)
  22.         throw CString(_T("lpsp->GetDisplayNameOf error"));
  23.     TCHAR displayName[MAX_PATH];
  24.     switch (str.uType)
  25.     {
  26.     case STRRET_CSTR:   // 획득 문자열이 cStr 멤버에 있다.
  27.         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.cStr, strlen(str.cStr), displayName, MAX_PATH);         
  28.         break;
  29.     case STRRET_WSTR:   // 획득 문자열이 pOleStr 멤버에 있다. (유니코드)
  30.         lstrcpy(displayName, str.pOleStr);
  31.         break;
  32.     default:
  33.         throw CString(_T("lpsp->GetDisplayNameOf error"));
  34.     }       
  35.     AfxMessageBox(displayName);
  36. }

[컴퓨터]-[휴지통]-[제어판]-[USER_NAME]-[라이브러리]-[네트워크]-...

이 글에는 0 개의 댓글이 있습니다.