Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

以 Managed Code 呼叫 Windows 7 工作列新功能:進度條、覆疊圖標實作教學

編輯:Windows 7 系統介紹

利用 Windows 7 SDK 中的 ShObjIdl.idl 介面定義,經 midl 編譯為 .tlb,再以 tlbimp 產生 Managed DLL,即可在 .NET 應用程式中呼叫工作列進度條與覆疊圖標 API。

關鍵步驟

  1. 取得 ShObjIdl.idl(SDK 或文後下載)。
  2. 將 HWND 參數改為 long 以利 Interop。
  3. midl ShObjIdl.idl → ShObjTlb.tlb。
  4. tlbimp ShObjTlb.tlb → Managed DLL。
  5. 專案加入參考,定義列舉 TbpFlag(Normal、Paused、Error、Indeterminate)。
  6. 呼叫 ITaskbarList3.SetProgressState 與 SetProgressValue 更新工作列按鈕進度。

midl 編譯

tlbimp 產生 DLL

20% 進度

50% 進度

100% 進度

非 Managed 代碼

C++ 實作更簡單,參考 SDK 範例:Microsoft SDKs\Windows\v7.0\Samples\winui\Shell\TaskbarIntegration\PeripheralStatus。

掌握此模式可輕鬆整合跳躍清單、縮圖工具列等其他工作列新功能。

Copyright © Windows教程網 All Rights Reserved