You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows Ribbon UI框架RecentItems固定状态获取异常问题

Windows Ribbon RecentItems 固定状态读取异常问题

问题背景

我通过以下XML配置了RecentItems列表:

<ApplicationMenu.RecentItems>
  <RecentItems CommandName="cmdRecentItems" EnablePinning="true" MaxCount="7"/>
</ApplicationMenu.RecentItems>

目前的问题是:我可以设置项的初始固定状态,也能在点击项时通过commandExecutionProperties读取到最新的固定状态,但当菜单关闭后尝试获取所有项的固定状态时,所有项(包括初始设置为固定的项)的状态都返回false。

尝试的实现代码

基于相关技术帖子、示例项目以及SDK的HTMLEdit示例(无固定功能但提供了RecentItems的通用实现思路),我编写了以下twinBASIC代码(兼容VB6/VBA,未使用WinForms/.NET):

Private Sub OnRibbonCmdExecute(ByVal commandId As Long, ByVal verb As UI_EXECUTIONVERB, ByVal key As LongPtr, currentValue As Variant, ByVal bCurValWasNull As Boolean, ByVal commandExecutionProperties As IUISimplePropertySet, returnValue As Long) Handles pUIApp.OnRibbonCmdExecute
(...)
        Case IDC_RECENTITEMS
                Dim nItem As Long
                Dim pset As IUISimplePropertySet
                Dim psa As LongPtr
                Dim parray As LongPtr
                Dim ct As Long
                Dim pv As Variant
                Dim blnRaw As Integer
                If VariantUI4ToI4(currentValue, nItem) Then
                    LogMsg "Clicked Recent Items (MRU) List item " & nItem
                End If
                If IsEqualPKEY(pk, UI_PKEY_RecentItems) Then
                    Debug.Print "Got RecentItems pkey in cmdExec, valuetype=" & VTtoStr(VarType(currentValue))
                    If VarType(currentValue) = (VT_ARRAY Or VT_UNKNOWN) Then
                       
                        CopyMemory parray, ByVal PointerAdd(VarPtr(currentValue), 8), LenB(Of LongPtr)
                        SafeArrayCopy ByVal parray, psa
                        Dim res As Long = SafeArrayGetUBound(psa, 1, ct)
                        If res = S_OK Then
                            Dim i As Long
                            For i = 0 To ct
                                If SafeArrayGetElement(psa, 1, pset) = S_OK Then
                                    pset.GetValue UI_PKEY_Pinned, pv
                                    Debug.Print "VarType(pv)=" & VTtoStr(VarType(pv))
                                    If VarType(pv) = VT_BOOL Then
                                        CopyMemory blnRaw, ByVal PointerAdd(VarPtr(pv), 8), 2
                                        Debug.Print "RawVal=0x" & Hex$(blnRaw)
                                    End If
                                    bMRUPinned(i) = CBool(pv)
                                    Debug.Print "Pinned(" & i & ")=" & bMRUPinned(i)
                                End If
                            Next
                        End If
                        SafeArrayDestroy psa
                    End If
                End If

异常现象

代码执行无报错:调试输出确认获取到的项数与MRU列表数量一致,且每次都能获取到有效的VT_BOOL类型变体,但无论使用自动布尔转换还是直接读取原始内存数据,所有项的固定状态始终返回0(即false)。

我已全面检索相关示例(包括搜索UI_PKEY_Pinned相关实现),但未找到问题原因或可行的替代方案。


内容的提问来源于stack exchange,提问作者Jon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 12:02:53