Skip to main content
 首页 » 编程设计

c#之无法完成 IDeskBand2 接口(interface)的实现

2024年02月13日13JeffreyZhao

我正在尝试在我的应用程序的任务栏中实现 DeskBand,我已经检查了 documentation但它非常稀疏。它没有解释如何实现 IDeskBand2 接口(interface)。

我在网上找到的关于此的信息很少,而且我找到的东西也不起作用。我发现 CodeProject 上看起来很有前途的一段代码只不过是编译时错误的源泉,直到今天,当我偶然发现 this 时。网站。

到目前为止,我得到的是:

class COMInterop 
{ 
    [ComImport] 
    [InterfaceType(ComInterfaceType.InterfaceIsDual)] 
    [Guid("79D16DE4-ABEE-4021-8D9D-9169B261D657")] 
 
    public interface IDeskBand2 
    { 
        void GetWindow(out System.IntPtr phwnd); 
        void ContextSensitiveHelp([In] bool fEnterMode); 
        void ShowDW([In] bool fShow); 
        void CloseDW([In] UInt32 dwReserved); 
        void ResizeBorderDW(IntPtr prcBorder, [In, MarshalAs(UnmanagedType.IUnknown)] Object punkToolbarSite, bool fReserved); 
 
        void GetBandInfo(UInt32 dwBandID, UInt32 dwViewMode, ref DESKBANDINFO pdbi); 
        bool CanRenderComposited(); 
        bool GetCompositionState(); 
        void SetCompositionState(bool fCompositionEnabled); 
    } 
} 

它位于名为 COMInterop.cs 的类文件中。

我现在遇到的问题是第 24 行。它说 The type or namespace 'DESKBANDINFO could not be found。 (您是否缺少 using 指令或程序集引用?)

我如何实现它 - 您是否有适用于 Windows 7+ 的 DeskBand(见下图)的任何好的文档?

请您参考如下方法:

DESKBAND 信息是一个记录的结构 here .您可以在 pinvoke.net 上找到 C# 翻译.

[StructLayout(LayoutKind.Sequential)] 
public struct POINT 
{ 
    public int X; 
    public int Y; 
 
    public POINT(int x, int y) 
    { 
        this.X = x; 
        this.Y = y; 
    } 
 
    public POINT(System.Drawing.Point pt) : this(pt.X, pt.Y) { } 
 
    public static implicit operator System.Drawing.Point(POINT p) 
    { 
        return new System.Drawing.Point(p.X, p.Y); 
    } 
 
    public static implicit operator POINT(System.Drawing.Point p) 
    { 
        return new POINT(p.X, p.Y); 
    } 
} 
 
[StructLayout (LayoutKind.Sequential, CharSet=CharSet.Unicode)] 
struct DESKBANDINFO { 
    public uint dwMask; 
    public Point ptMinSize; 
    public Point ptMaxSize; 
    public Point ptIntegral; 
    public Point ptActual; 
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)] 
    public String wszTitle; 
    public uint dwModeFlags; 
    public Int32 crBkgnd;  
} 

桌面 API documentation明确指出它是一个已弃用的 API。它说:

Important You should use thumbnail toolbars in new development in place of desk bands, which are not supported as of Windows 7.

换句话说,您几乎肯定不会使用 deskband API 来解决您的问题。

也就是说,如果您想学习如何使用 deskband API,请查看 C++ 中的示例代码。不要将搜索限制为 C#。希望在 C++ 中找到很好的示例,但在 C# 中找不到。