<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      記錄win11下,WPF設置 System.AppUserModel.PreventPinning 屬性用于阻止用戶將應用程序固定到任務欄

      本篇博文我僅僅是作為記錄者,實際上發(fā)現(xiàn)并編碼的是我們組的小伙伴天保同學。

      我們組小伙伴有個需求,需要將WPF應用的 任務欄右鍵菜單菜單,不顯示“固定到任務欄”。 

      如下圖:

      普通窗口的任務欄右鍵菜單:

      image

      image

       

      但是發(fā)現(xiàn)部分窗口有只顯示 “關閉窗口”

      “微信公眾號”的窗口

      image

       

      微軟的官方文檔:System.AppUserModel.PreventPinning - Win32 apps | Microsoft Learn 禁用將快捷方式或窗口固定到任務欄或 開始 菜單的功能。 此屬性還使項無法包含在 “開始” 菜單的“最常用的”(MFU)列表中。

      1、首先定義System.AppUserModel.PreventPinning:ROPERTYKEY(new Guid("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}"), 9):詳情看propertyKey的參數(shù)解釋:propertyKEY (wtypes.h) - Win32 apps | Microsoft Learn

      2、給IPropertyStore 定義 IID Guid IID_IPropertyStore = new Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99");

      3、調用shell32 的 SHGetPropertyStoreForWindow實現(xiàn) 禁用的功能

       

      代碼如下:

       public class NativeWin32
       {
           [DllImport("shell32.dll")]
           public static extern int SHGetPropertyStoreForWindow(IntPtr hwnd, ref Guid riid, out IPropertyStore propertyStore);
      
           [DllImport("ole32.dll")]
           public static extern int PropVariantClear(ref PROPVARIANT pvar);
      
           // Define IPropertyStore interface
           [ComImport]
           [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
           [Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99")]
           public interface IPropertyStore
           {
               void GetCount(out uint cProps);
               void GetAt(uint iProp, out PROPERTYKEY pkey);
               void GetValue(ref PROPERTYKEY key, out PROPVARIANT pv);
               void SetValue(ref PROPERTYKEY key, ref PROPVARIANT pv);
               void Commit();
           }
      
           // Define IID for IPropertyStore
           public static Guid IID_IPropertyStore = new Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99");
      
           // Define PROPERTYKEY struct
           [StructLayout(LayoutKind.Sequential, Pack = 4)]
           public struct PROPERTYKEY
           {
               public Guid fmtid;
               public uint pid;
      
               public PROPERTYKEY(Guid fmtid, uint pid)
               {
                   this.fmtid = fmtid;
                   this.pid = pid;
               }
           }
      
           // Define PROPVARIANT structure (simplified, we'll use a simple one for bool)
           [StructLayout(LayoutKind.Explicit)]
           public struct PROPVARIANT
           {
               // We'll only implement the necessary part for boolean
               [FieldOffset(0)] public ushort vt;
               [FieldOffset(8)] public byte boolVal;
      
               public void SetValue(bool value)
               {
                   // VT_BOOL
                   vt = 11;
                   boolVal = value ? (byte)1 : (byte)0;
               }
           }
       }

       

      在窗口加載的時候調用方法:

       public MainWindow()
       {
           InitializeComponent();
           SourceInitialized += MainWindow_SourceInitialized;
       }
      
       private void MainWindow_SourceInitialized(object? sender, EventArgs e)
       {
           SetPinning();
       }
      
       private void SetPinning()
       {
           IntPtr hwnd = new WindowInteropHelper(this).Handle;
      
           // Define the property key for System.AppUserModel.PreventPinning
           NativeWin32.PROPERTYKEY propKey = new NativeWin32.PROPERTYKEY(new Guid("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}"), 9);
      
           // Get the IPropertyStore for the window
           NativeWin32.IPropertyStore propStore;
           int hr = NativeWin32.SHGetPropertyStoreForWindow(hwnd, ref NativeWin32.IID_IPropertyStore, out propStore);
           if (hr != 0) // if failed
           {
               Marshal.ThrowExceptionForHR(hr);
           }
      
           try
           {
               // Create a PROPVARIANT with bool value: true
               NativeWin32.PROPVARIANT pv = new NativeWin32.PROPVARIANT();
               pv.SetValue(true);
      
               // Set the property
               propStore.SetValue(ref propKey, ref pv);
      
               // We must free the PROPVARIANT
               NativeWin32.PropVariantClear(ref pv);
           }
           finally
           {
               // Release the IPropertyStore
               Marshal.ReleaseComObject(propStore);
           }
       }

       

      結果如下:

      image

       

      代碼鏈接: wutangyuan/wutyDemo: Demo代碼備份

       

      參考資料:

      propertyKEY (wtypes.h) - Win32 apps | Microsoft Learn

      System.AppUserModel.PreventPinning - Win32 apps | Microsoft Learn

       應用程序用戶模型 ID (AppUserModelIDs) - Win32 apps | Microsoft Learn

      posted @ 2025-08-07 21:38  wuty007  閱讀(238)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 久久久久无码中| 国产免费AV片在线看| 精品黑人一区二区三区| 国产在线精品一区二区夜色| 国产一级特黄高清大片一| 日韩精品一区二区亚洲专区| 尼木县| 内射囯产旡码丰满少妇| 精品一区二区三区蜜桃麻豆| 午夜激情福利一区二区| 中文字幕理伦午夜福利片| 日本韩无专砖码高清观看| 国产99视频精品免费专区| 国产免费午夜福利在线播放| 成年无码av片在线蜜芽| 欧美变态另类zozo| 国产综合久久久久鬼色| 亚洲人成网网址在线看| 亚洲a∨无码无在线观看| 男人猛戳女人30分钟视频大全| 大陆精大陆国产国语精品| 久久国产精品老女人| 丁香五月亚洲综合深深爱| 日韩不卡一区二区在线观看| 欧美亚洲综合成人a∨在线| 精品日韩人妻中文字幕| 综合在线 亚洲 成人 欧美| 无码国内精品久久人妻蜜桃| 亚洲精品一区二区动漫| 成av人电影在线观看| 四虎国产精品成人| 亚洲国产在一区二区三区| 亚洲精品第一页中文字幕| 亚洲综合国产一区二区三区| 国产欧美日韩免费看AⅤ视频| 国产成人剧情AV麻豆果冻| 久久夜色噜噜噜亚洲av| 男人天堂亚洲天堂女人天堂| 亚洲熟妇自偷自拍另欧美| 国产精品国产精品无卡区| 久久亚洲国产成人亚|