11

これは簡単な質問かもしれませんが、検索する用語がわからないので、質問する必要があります。プログラムがスタートメニューに固定されている場合、プログラムにカーソルを合わせたときにメニューが表示されるようにしたいと思います。Windows PowerShellがこの機能を示し、タスクのリストを表示するスクリーンショットを添付しています。

ここに画像の説明を入力してください

他のプログラムは、最近開いたファイルなどを一覧表示するためにこれを使用することがあります。これは、どこかにチュートリアルがあるほど十分に標準的であると確信しています。誰かが私にそれを指摘したり、これを行う方法を説明したりしますか?どの言語を使用するかはそれほど重要ではないことを願っていますが、Delphi、C ++、およびC#に精通しています。

4

1 に答える 1

12

Windows 7 で導入されたICustomDestinationList.AddUserTasksの一部であるメソッドを使用する必要があります。Taskbar Extensions

アップデート

このサンプル コンソール アプリを試して、コードを実行し、アプリのショートカットをスタート メニューに移動します。(これは単なるサンプル スニペットなので、HResult値を返すすべてのメソッドの結果のチェックを追加することを忘れないでください)

program ProjectTasks;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SysUtils,
  ActiveX,
  windows,
  ComObj,
  ShlObj,
  PropSys,
  ObjectArray;

const
  PKEY_TITLE : TPropertyKey = ( fmtID : '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}'; pID : 2);

procedure CreateTaskList;
var
  LCustomDestinationList : ICustomDestinationList;
  pcMaxSlots : Cardinal;
  ppv : IObjectArray;
  poa : IObjectCollection;
  LTask : IShellLink;
  LPropertyStore : IPropertyStore;
  LTitle : TPropVariant;
  LTaskBarList : ITaskBarList;
  LTaskBarList3 : ITaskBarList3;
  hr : HRESULT;
begin
    LTaskBarList := CreateComObject(CLSID_TaskBarList) as ITaskBarList;
    hr := LTaskBarList.QueryInterface(IID_ITaskBarList3, LTaskBarList3);
    if hr <> S_OK then exit;


    LCustomDestinationList := CreateComObject(CLSID_DestinationList) as ICustomDestinationList;
    LCustomDestinationList.BeginList(pcMaxSlots, IID_IObjectArray, ppv);
    poa := CreateComObject(CLSID_EnumerableObjectCollection) as IObjectCollection;


    LTask := CreateComObject(CLSID_ShellLink) as IShellLink;
    LTask.SetPath(pChar(ParamStr(0))); //set the  path to the exe
    LTask.SetDescription('This is a description sample');
    LTask.SetArguments(PChar('Bar'));
    LTask.SetIconLocation(PChar('Shell32.dll'),1);
    LPropertyStore := LTask as IPropertyStore;
    LTitle.vt := VT_LPWSTR;
    LTitle.pwszVal := PChar('This is the Task 1');
    LPropertyStore.SetValue(PKEY_Title,LTitle);
    LPropertyStore.Commit;
    poa.AddObject(LTask);

    LTask := CreateComObject(CLSID_ShellLink) as IShellLink;
    LTask.SetPath(PChar(ParamStr(0))); //set the  path to the exe
    LTask.SetDescription('This is a description sample');
    LTask.SetArguments(PChar('Foo'));
    LTask.SetIconLocation(pChar('Shell32.dll'),1);
    LPropertyStore := LTask as IPropertyStore;
    LTitle.vt := VT_LPWSTR;
    LTitle.pwszVal := pChar('This is the Task 2');
    LPropertyStore.SetValue(PKEY_Title,LTitle);
    LPropertyStore.Commit;
    poa.AddObject(LTask);


    LCustomDestinationList.AddUserTasks(poa as IObjectArray);
    LCustomDestinationList.CommitList;
end;

begin
 try
    CoInitialize(nil);
    try
       CreateTaskList;
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;
end.

ここに画像の説明を入力

于 2012-10-11T22:16:57.213 に答える