2

在 Windows 8 的 C# 中,如何 pInvoke IMetroMode::IsLauncherVisible 方法?

该方法的详细信息可在此处找到:http: //msdn.microsoft.com/en-us/library/windows/desktop/hh404166 (v=vs.85).aspx

4

2 回答 2

4

使用IAppVisibility接口而不是过时的 IMetroMode 接口

这是示例代码:

/* 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
}

IAppVisibility 接口定义:

[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);
}
于 2012-08-17T17:57:11.290 回答
1

几件事:

  1. 看起来已从 Windows 8 的 RC 和 RTM 版本中IMetroMode删除。
  2. 不要在 WinRT 调用上使用 P/Invoke,而是应该在 C# 项目中添加对来自C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral\. 这将提供具有自动完成功能的互操作服务,该服务应提供对您需要的任何 WinRT 工具的访问。你可以在这里找到更多信息
于 2012-08-17T17:47:59.943 回答