【问题标题】:How can I create a menu in the start menu for my program?如何在我的程序的开始菜单中创建一个菜单?
【发布时间】:2012-10-02 16:40:47
【问题描述】:

这可能是一个简单的问题,但我什至不确定要搜索的术语,所以我不得不问。如果我的程序被固定到开始菜单,我希望我的程序在悬停时有一个菜单。我附上了一个屏幕截图,其中 windows powershell 说明了这个功能,并显示了一个任务列表。

其他程序有时会使用它来列出最近打开的文件等。我相信这是足够标准的,在某个地方有一个教程,有人介意指点我,或者解释如何做到这一点吗?我希望用什么语言不要太在意,但我精通Delphi、C++和C#。

【问题讨论】:

    标签: c# c++ delphi winapi windows-7


    【解决方案1】:

    您必须使用ICustomDestinationList.AddUserTasks 方法,它是Windows 7 中引入的Taskbar Extensions 的一部分。

    更新

    试试这个示例控制台应用程序,运行代码并将应用程序的快捷方式移动到开始菜单。 (这只是一个示例 sn-p,所以记得添加对所有返回 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.
    

    【讨论】:

    • 在 C# here 中有一个很好的例子来说明如何做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 2018-03-10
    • 2019-09-14
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多