2009-11-04 4 views
1

빠른 질문 : Windows 7의 새로운 작업 표시 줄 API 중 일부를 다루고 있으며 내 Apps jumplist의 최근 항목을 표시하고 있지만 아래에 표시하려고합니다. 파일 이름과 다른 제목 (내 앱이 열리는 대부분의 파일은 매우 유사한 이름을 갖습니다). IShellItem 인터페이스를 사용하여이를 수행 할 수있는 방법이 없습니다. 이 작업을 위해 사용자 지정 범주 및 IShellLinks를 사용해야합니까? 참고로Windows 7 사용자 지정 제목 이동 목록 최근 항목

, 내 현재 코드는 다음과 같습니다

void AddRecentApp(const wchar_t* path, const wchar_t* title /* Can I even use this? */) { 
    HRESULT hres; 

    hres = CoInitialize(NULL); 

    IShellItem* recentItem; 
    hres = SHCreateItemFromParsingName(path, NULL, IID_PPV_ARGS(&recentItem)); 
    if(SUCCEEDED(hres)) { 
     SHARDAPPIDINFO recentItemInfo; 
     recentItemInfo.pszAppID = MY_APP_USER_MODEL_ID; 
     recentItemInfo.psi = recentItem; 

     SHAddToRecentDocs(SHARD_APPIDINFO, &recentItemInfo); 

     recentItem->Release(); 
    } 
} 

답변

2

이 그것을 알아 냈다. IShellItems는 파일을 나타내는 것으로 파일의 정보 만 제공합니다 (사용자 지정 제목 등은 없음). IShellLink는 본질적으로 바로 가기이며 실행시 표시 및 동작면에서 훨씬 유연합니다. 이 상황에 적절합니다. 새 코드는 다음과 같습니다.

void AddRecentApp(const wchar_t* path, const wchar_t* title) { 
    HRESULT hres; 
    hres = CoInitialize(NULL); 

    // Shell links give us more control over how the item is displayed and run 
    IShellLink* shell_link; 
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shell_link)); 
    if(SUCCEEDED(hres)) { 
     // Set up the basic link properties 
     shell_link->SetPath(path); 
     shell_link->SetArguments(L"--some-command-line-here"); // command line to execute when item is opened here! 
     shell_link->SetDescription(title); // This is what shows in the tooltip 
     shell_link->SetIconLocation(L"/path/to/desired/icon", 0); // can be an icon file or binary 

     // Open up the links property store and change the title 
     IPropertyStore* prop_store; 
     hres = shell_link->QueryInterface(IID_PPV_ARGS(&prop_store)); 
     if(SUCCEEDED(hres)) { 
      PROPVARIANT pv; 
      InitPropVariantFromString(title, &pv); 

      // Set the title property. 
      prop_store->SetValue(PKEY_Title, pv); // THIS is where the displayed title is actually set 
      PropVariantClear(&pv); 

      // Save the changes we made to the property store 
      prop_store->Commit(); 
      prop_store->Release(); 
     } 

     // The link must persist in the file system somewhere, save it here. 
     IPersistFile* persist_file; 
     hres = shell_link->QueryInterface(IID_PPV_ARGS(&persist_file)); 
     if(SUCCEEDED(hres)) { 
      hres = persist_file->Save(L"/link/save/directory", TRUE); 
      persist_file->Release(); 
     } 

     // Add the link to the recent documents list 
     SHARDAPPIDINFOLINK app_id_info_link; 
     app_id_info_link.pszAppID = MY_APP_USER_MODEL_ID; 
     app_id_info_link.psl = shell_link; 
     SHAddToRecentDocs(SHARD_APPIDINFOLINK, &app_id_info_link); 

     shell_link->Release(); 
    } 
} 
관련 문제