2009-11-04 5 views
1

Quickie question: Je suis en train de jouer avec certaines des nouvelles API de la barre des tâches dans Windows 7 et j'ai trouvé des éléments récents sur mon appli jumplist, mais je voudrais les afficher sous un titre différent du nom de fichier (la plupart des fichiers que mon application va ouvrir auront des noms très similaires). Cependant, je ne vois aucun moyen de le faire avec l'interface IShellItem. Devrais-je utiliser des catégories personnalisées et IShellLinks pour accomplir cela?Titres personnalisés pour Windows 7 Jump List Articles récents

Pour référence, mon code actuel ressemble à ceci:

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(); 
    } 
} 

Répondre

2

figured it out. IShellItems sont juste une représentation d'un fichier, donc ils fourniront seulement les informations de ce fichier (aucun titre personnalisé, etc.) Un IShellLink est essentiellement un raccourci, et est beaucoup plus flexible en termes d'affichage et d'actions prises lors du lancement. approprié dans cette situation. Voici mon nouveau code:

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(); 
    } 
}