2012-10-11 47 views
11

Đây có thể là một câu hỏi dễ nhưng tôi thậm chí không chắc chắn về thuật ngữ để tìm kiếm, vì vậy tôi phải hỏi. Tôi muốn chương trình của tôi để có một trình đơn khi nó được di chuột qua nếu nó được ghim vào trình đơn bắt đầu. Tôi đính kèm một ảnh chụp màn hình nơi cửa sổ powershell minh họa chức năng này, và trình bày một danh sách các nhiệm vụ.Làm cách nào để tạo menu trong menu bắt đầu cho chương trình của tôi?

enter image description here

Các chương trình khác đôi khi sử dụng để liệt kê các file vừa mở, vv Tôi chắc chắn điều này là đủ tiêu chuẩn mà có một hướng dẫn về nó ở đâu đó, có người tâm sẽ chỉ cho tôi với nó, hoặc giải thích làm thế nào để làm cái này? Tôi hy vọng rằng nó không quan trọng quá nhiều những gì ngôn ngữ được sử dụng, nhưng tôi thành thạo trong Delphi, C++, và C#.

Trả lời

12

Bạn phải sử dụng phương pháp ICustomDestinationList.AddUserTasks, mà là một phần của Taskbar Extensions giới thiệu trong Windows 7.

CẬP NHẬT

Hãy thử giao diện điều khiển ứng dụng mẫu này, chạy các mã và di chuyển một shortcut của ứng dụng để bắt đầu thực đơn. (Điều này chỉ là một đoạn mẫu, vì vậy hãy nhớ thêm kiểm tra cho kết quả của tất cả các phương pháp mà trả về một giá trị 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. 

enter image description here

+0

Có một ví dụ tốt về làm thế nào để làm điều này trong C# [ở đây ] (http://www.canofcode.co.uk/software/how-to-add-jumplists-to-ac-application/). – nateirvin

Các vấn đề liên quan