IMetroMode::IsLauncherVisible in C# via pInvoke?

后端 未结 2 718
礼貌的吻别
礼貌的吻别 2020-12-21 14:03

In C# in Windows 8, how can I pInvoke the IMetroMode::IsLauncherVisible method?

Details for the method are found here: http://msdn.microsoft.com/en-us/library/window

相关标签:
2条回答
  • 2020-12-21 14:31

    Couple of things:

    1. Looks like IMetroMode was removed from the RC and RTM builds of Windows 8.
    2. You don't use P/Invoke on WinRT calls, instead you should add a reference in your C# project to the appropriate WinMD file from C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral\. This will provide interop services complete with auto-completion that should provide access to whatever WinRT facilities you require. You can find more info here.
    0 讨论(0)
  • 2020-12-21 14:33

    Use the IAppVisibility interface instead of the obsolete IMetroMode interface

    Here is the sample code:

    /* From ShObjIdl.idl
    // CLSID_AppVisibility
    [ uuid(7E5FE3D9-985F-4908-91F9-EE19F9FD1514)] coclass AppVisibility { interface IAppVisibility; }
     */
    Type tIAppVisibility = Type.GetTypeFromCLSID(new Guid("7E5FE3D9-985F-4908-91F9-EE19F9FD1514"));
    IAppVisibility appVisibility = (IAppVisibility)Activator.CreateInstance(tIAppVisibility);
    bool launcherVisible;
    if(HRESULT.S_OK == appVisibility.IsLauncherVisible(out launcherVisible)) {
        // Here you can use the launcherVisible flag
    }
    

    The IAppVisibility interface definition:

    [ComImport, Guid("2246EA2D-CAEA-4444-A3C4-6DE827E44313"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IAppVisibility {
        HRESULT GetAppVisibilityOnMonitor([In] IntPtr hMonitor, [Out] out MONITOR_APP_VISIBILITY pMode);
        HRESULT IsLauncherVisible([Out] out bool pfVisible);
        HRESULT Advise([In] IAppVisibilityEvents pCallback, [Out] out int pdwCookie);
        HRESULT Unadvise([In] int dwCookie);
    }
    //...
    public enum HRESULT : long {
        S_FALSE = 0x0001,
        S_OK = 0x0000,
        E_INVALIDARG = 0x80070057,
        E_OUTOFMEMORY = 0x8007000E
    }
    public enum MONITOR_APP_VISIBILITY {
        MAV_UNKNOWN = 0,         // The mode for the monitor is unknown
        MAV_NO_APP_VISIBLE = 1,
        MAV_APP_VISIBLE = 2
    }
    [ComImport, Guid("6584CE6B-7D82-49C2-89C9-C6BC02BA8C38"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IAppVisibilityEvents {
        HRESULT AppVisibilityOnMonitorChanged(
            [In] IntPtr hMonitor,
            [In] MONITOR_APP_VISIBILITY previousMode,
            [In] MONITOR_APP_VISIBILITY currentMode);
    
        HRESULT LauncherVisibilityChange([In] bool currentVisibleState);
    }
    
    0 讨论(0)
提交回复
热议问题