0

的Windows功能区框架标记支持最近的项目菜单中的应用程序菜单的EnablePinning属性:功能区框架的最近项目中的“EnablePinning”属性在哪里?

<ApplicationMenu.RecentItems> 
    <RecentItems CommandName="MRU" EnablePinning="true" /> 
</ApplicationMenu.RecentItems> 

我预计会有可以查询/在运行时更新匹配的属性,但我找不到属性键。有人知道是否有一个,如果有的话,它是什么?

另外,还有另一种方法来在运行时打开/关闭锁定/关闭?元素及其父级支持应用程序模式。

TIA

澄清:我想要做的就是启用/禁用寄托在运行时整个菜单。我不关心单个项目的销状态。

回答

0

我不知道,如果你可以修改现有条目中的固定状态,但它绝对有可能以编程方式查询状态,并使用UI_PKEY_Pinned属性与特定的状态添加新项目: https://msdn.microsoft.com/en-us/library/windows/desktop/dd940401(v=vs.85).aspx

化包装,如适用于Delphi的Windows功能区框架WinForms的Windows功能区(.NET)可轻松访问API模型。文章还介绍了如何使用C#查询/添加最近的项目。

如果您想要在运行时更改状态,例如可以查询所有项目的状态,将它们从列表中移除,根据需要进行调整并将其添加到列表中。没有那样做,但是值得一试。

+0

对不起,我想我的问题还不够清楚。我需要做的是启用/禁用整个菜单的固定。相当于在标记中,但在运行时从“EnablePinning = true”切换为“EnablePinning = false”(反之亦然)。我不关心单个项目的销状态。我试图启用或禁用用户的固定项目的能力。 – chrisd

0

嗯......这将是很难完成的,因为在XML中定义标志将被编译到链接到应用程序的资源文件中,然后在启动时加载。如果您想禁用/启用标记,您可以创建另一个资源定义并重新加载功能区,但是从用户的角度来看,这是相当多的开销,并且肯定会引起注意,因为它需要创建新的窗口句柄。

+0

我希望有一个运行时可访问的属性,就像其他许多命令属性一样。但似乎没有一个。谢谢。 – chrisd

0

我把最近的项目由内而外UpdateProperty

TRecentItem = class(TInterfacedObject, IUISimplePropertySet) 
    private 
     FRecentFile: TSSettings.TRecentFile; 
    protected 
     function GetValue(const key: TUIPropertyKey; out value: TPropVariant): HRESULT; stdcall; 
    public 
     procedure Initialize(const RecentFile: TSSettings.TRecentFile); safecall; 
    end; 

function TMyForm.UpdateProperty(commandId: UInt32; const key: TUIPropertyKey; 
    currentValue: PPropVariant; out newValue: TPropVariant): HRESULT; 
var 
    I: Integer; 
    psa: PSafeArray; 
    pv: Pointer; 
    RecentItem: TRecentItem; 
begin 
    if (key = UI_PKEY_RecentItems) then 
    begin 
    psa := SafeArrayCreateVector(VT_UNKNOWN, 0, Settings.RecentFiles.Count); 

    if (not Assigned(psa)) then 
     Result := E_FAIL 
    else 
    begin 
     for I := 0 to Settings.RecentFiles.Count - 1 do 
     begin 
     RecentItem := TRecentItem.NewInstance() as TRecentItem; 
     RecentItem.Initialize(Settings.RecentFiles[I]); 
     pv := Pointer(IUnknown(RecentItem)); 
     Check(SafeArrayPutElement(psa, I, pv^)); 
     end; 

     Result := UIInitPropertyFromIUnknownArray(UI_PKEY_RecentItems, psa, PropVar); 

     SafeArrayDestroy(psa); 
    end; 
    end; 

如果引脚被改变,我得到这个命令而关闭应用程序菜单:

function TMyForm.Execute(commandId: UInt32; verb: _UIExecutionVerb; 
    key: PUIPropertyKey; currentValue: PPropVariant; 
    commandExecutionProperties: IUISimplePropertySet): HRESULT; stdcall; 
var 
    Count: Integer; 
    I: Integer; 
    Pinned: Boolean; 
    psa: PSafeArray; 
    pv: IUnknown; 
    RecentFile: UInt32; 
    SimplePropertySet: IUISimplePropertySet; 
    Value: TPropVariant; 
begin 
    if ((commandId = cmdAppRecentItems) 
    and Assigned(key) and (key^ = UI_PKEY_RecentItems) 
    and Assigned(currentValue) and (currentValue^.vt = VT_ARRAY + VT_UNKNOWN)) then 
    begin 
    psa := nil; 
    Result := UIPropertyToIUnknownArrayAlloc(key^, currentValue^, psa); 
    if (Succeeded(Result)) then 
    begin 
     Result := SafeArrayGetUBound(psa, 1, Count); 
     for I := 0 to Count do 
     if (Succeeded(Result)) then 
     begin 
      Result := SafeArrayGetElement(psa, I, pv); 
      if (Succeeded(Result) and Assigned(pv)) then 
      begin 
      Result := pv.QueryInterface(IUISimplePropertySet, SimplePropertySet); 
      if (Succeeded(Result)) then 
       Result := SimplePropertySet.GetValue(UI_PKEY_Pinned, Value); 
      if (Succeeded(Result)) then 
       Result := UIPropertyToBoolean(UI_PKEY_Pinned, Value, Pinned); 
      if (Succeeded(Result)) then 
       Settings.RecentFiles.SetPinned(I, Pinned); 
      end; 
     end; 
     SafeArrayDestroy(psa); 
    end; 
    end 
end; 

...但我没有找到这个解决方案的文档。

相关问题