Example #1
0
  /**
   * Gets Display Information
   *
   * @return An array of Display objects representing monitors, etc.
   */
  public static Display[] getDisplays() {
    List<Display> displays = new ArrayList<>();

    Guid.GUID monitorGuid = new Guid.GUID("E6F07B5F-EE97-4a90-B076-33F57BF4EAA7");
    WinNT.HANDLE hDevInfo =
        SetupApi.INSTANCE.SetupDiGetClassDevs(
            monitorGuid, null, null, SetupApi.DIGCF_PRESENT | SetupApi.DIGCF_DEVICEINTERFACE);
    if (!hDevInfo.equals(WinNT.INVALID_HANDLE_VALUE)) {
      SP_DEVICE_INTERFACE_DATA deviceInterfaceData = new SetupApi.SP_DEVICE_INTERFACE_DATA();
      deviceInterfaceData.cbSize = deviceInterfaceData.size();

      // build a DevInfo Data structure
      SP_DEVINFO_DATA info = new SetupApi.SP_DEVINFO_DATA();

      for (int memberIndex = 0;
          SetupApi.INSTANCE.SetupDiEnumDeviceInfo(hDevInfo, memberIndex, info);
          memberIndex++) {
        HKEY key =
            SetupApi.INSTANCE.SetupDiOpenDevRegKey(
                hDevInfo,
                info,
                SetupApi.DICS_FLAG_GLOBAL,
                0,
                SetupApi.DIREG_DEV,
                WinNT.KEY_QUERY_VALUE);

        byte[] edid = new byte[1];
        Advapi32 advapi32 = Advapi32.INSTANCE;
        IntByReference pType = new IntByReference();
        IntByReference lpcbData = new IntByReference();

        if (advapi32.RegQueryValueEx(key, "EDID", 0, pType, edid, lpcbData)
            == WinError.ERROR_MORE_DATA) {
          edid = new byte[lpcbData.getValue()];
          if (advapi32.RegQueryValueEx(key, "EDID", 0, pType, edid, lpcbData)
              == WinError.ERROR_SUCCESS) {
            Display display = new WindowsDisplay(edid);
            displays.add(display);
          }
        }
        Advapi32.INSTANCE.RegCloseKey(key);
      }
    }
    return displays.toArray(new Display[displays.size()]);
  }
 @Override
 public void revertToSelf() {
   Advapi32.INSTANCE.RevertToSelf();
 }
 /**
  * Impersonate a logged on user.
  *
  * @param windowsIdentity Windows identity obtained via LogonUser.
  */
 public WindowsIdentityImpersonationContextImpl(HANDLE windowsIdentity) {
   if (!Advapi32.INSTANCE.ImpersonateLoggedOnUser(windowsIdentity)) {
     throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
   }
 }