|
| 1 | +/* |
| 2 | + * Copyright 2014 Martin Steiger |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.sun.jna.contrib.demo; |
| 18 | + |
| 19 | +import com.sun.jna.Memory; |
| 20 | +import com.sun.jna.platform.EnumUtils; |
| 21 | +import com.sun.jna.platform.win32.Dxva2; |
| 22 | +import com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI; |
| 23 | +import com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_COLOR_TEMPERATURE; |
| 24 | +import com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_DISPLAY_TECHNOLOGY_TYPE; |
| 25 | +import com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_DRIVE_TYPE; |
| 26 | +import com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_GAIN_TYPE; |
| 27 | +import com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_POSITION_TYPE; |
| 28 | +import com.sun.jna.platform.win32.HighLevelMonitorConfigurationAPI.MC_SIZE_TYPE; |
| 29 | +import com.sun.jna.platform.win32.LowLevelMonitorConfigurationAPI.MC_TIMING_REPORT; |
| 30 | +import com.sun.jna.platform.win32.PhysicalMonitorEnumerationAPI.PHYSICAL_MONITOR; |
| 31 | +import com.sun.jna.platform.win32.User32; |
| 32 | +import com.sun.jna.platform.win32.WTypes.LPSTR; |
| 33 | +import com.sun.jna.platform.win32.WinDef.DWORD; |
| 34 | +import com.sun.jna.platform.win32.WinDef.DWORDByReference; |
| 35 | +import com.sun.jna.platform.win32.WinDef.HDC; |
| 36 | +import com.sun.jna.platform.win32.WinDef.LPARAM; |
| 37 | +import com.sun.jna.platform.win32.WinDef.RECT; |
| 38 | +import com.sun.jna.platform.win32.WinNT.HANDLE; |
| 39 | +import com.sun.jna.platform.win32.WinUser; |
| 40 | +import com.sun.jna.platform.win32.WinUser.HMONITOR; |
| 41 | +import com.sun.jna.platform.win32.WinUser.MONITORENUMPROC; |
| 42 | +import com.sun.jna.platform.win32.WinUser.MONITORINFOEX; |
| 43 | + |
| 44 | +/** |
| 45 | + * A small demo that tests the Win32 monitor API. |
| 46 | + * All available physical and virtual monitors are enumerated and |
| 47 | + * their capabilities printed to stdout |
| 48 | + * @author Martin Steiger |
| 49 | + */ |
| 50 | +public class MonitorInfoDemo |
| 51 | +{ |
| 52 | + /** |
| 53 | + * @param args (ignored) |
| 54 | + */ |
| 55 | + public static void main(String[] args) |
| 56 | + { |
| 57 | + System.out.println("Installed Physical Monitors: " + User32.INSTANCE.GetSystemMetrics(WinUser.SM_CMONITORS)); |
| 58 | + |
| 59 | + User32.INSTANCE.EnumDisplayMonitors(null, null, new MONITORENUMPROC() { |
| 60 | + |
| 61 | + @Override |
| 62 | + public int apply(HMONITOR hMonitor, HDC hdc, RECT rect, LPARAM lparam) |
| 63 | + { |
| 64 | + enumerate(hMonitor); |
| 65 | + |
| 66 | + return 1; |
| 67 | + } |
| 68 | + |
| 69 | + }, new LPARAM(0)); |
| 70 | + } |
| 71 | + |
| 72 | + static void enumerate(HMONITOR hMonitor) |
| 73 | + { |
| 74 | + System.out.println("Found HMONITOR: " + hMonitor.getPointer().toString()); |
| 75 | + |
| 76 | + MONITORINFOEX info = new MONITORINFOEX(); |
| 77 | + User32.INSTANCE.GetMonitorInfo(hMonitor, info); |
| 78 | + System.out.println("Screen " + info.rcMonitor); |
| 79 | + System.out.println("Work area " + info.rcWork); |
| 80 | + boolean isPrimary = (info.dwFlags & WinUser.MONITORINFOF_PRIMARY) != 0; |
| 81 | + System.out.println("Primary? " + (isPrimary ? "yes" : "no")); |
| 82 | + System.out.println("Device " + new String(info.szDevice)); |
| 83 | + |
| 84 | + DWORDByReference pdwNumberOfPhysicalMonitors = new DWORDByReference(); |
| 85 | + Dxva2.INSTANCE.GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, pdwNumberOfPhysicalMonitors); |
| 86 | + int monitorCount = pdwNumberOfPhysicalMonitors.getValue().intValue(); |
| 87 | + |
| 88 | + System.out.println("HMONITOR is linked to " + monitorCount + " physical monitors"); |
| 89 | + |
| 90 | + PHYSICAL_MONITOR[] physMons = new PHYSICAL_MONITOR[monitorCount]; |
| 91 | + Dxva2.INSTANCE.GetPhysicalMonitorsFromHMONITOR(hMonitor, monitorCount, physMons); |
| 92 | + |
| 93 | + for (int i = 0; i < monitorCount; i++) |
| 94 | + { |
| 95 | + HANDLE hPhysicalMonitor = physMons[0].hPhysicalMonitor; |
| 96 | + System.out.println("Monitor " + i + " - " + new String(physMons[i].szPhysicalMonitorDescription)); |
| 97 | + |
| 98 | + enumeratePhysicalMonitor(hPhysicalMonitor); |
| 99 | + } |
| 100 | + |
| 101 | + Dxva2.INSTANCE.DestroyPhysicalMonitors(monitorCount, physMons); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @param hPhysicalMonitor |
| 106 | + */ |
| 107 | + private static void enumeratePhysicalMonitor(HANDLE hPhysicalMonitor) |
| 108 | + { |
| 109 | + MC_DISPLAY_TECHNOLOGY_TYPE.ByReference techType = new MC_DISPLAY_TECHNOLOGY_TYPE.ByReference(); |
| 110 | + Dxva2.INSTANCE.GetMonitorTechnologyType(hPhysicalMonitor, techType); |
| 111 | + System.out.println("TECHTYPE: " + techType.getValue()); |
| 112 | + |
| 113 | + DWORDByReference temps = new DWORDByReference(); |
| 114 | + DWORDByReference caps = new DWORDByReference(); |
| 115 | + Dxva2.INSTANCE.GetMonitorCapabilities(hPhysicalMonitor, caps, temps); |
| 116 | + System.out.println("CAPS " + EnumUtils.setFromInteger(caps.getValue().intValue(), HighLevelMonitorConfigurationAPI.MC_CAPS.class)); |
| 117 | + System.out.println("Temps " + temps.getValue()); |
| 118 | + |
| 119 | + // Brightness |
| 120 | + DWORDByReference pdwMinimumBrightness = new DWORDByReference(); |
| 121 | + DWORDByReference pdwCurrentBrightness = new DWORDByReference(); |
| 122 | + DWORDByReference pdwMaximumBrightness = new DWORDByReference(); |
| 123 | + Dxva2.INSTANCE.GetMonitorBrightness(hPhysicalMonitor, pdwMinimumBrightness, pdwCurrentBrightness, pdwMaximumBrightness); |
| 124 | + |
| 125 | + System.out.println("Brightness Min: " + pdwMinimumBrightness.getValue()); |
| 126 | + System.out.println("Brightness Current: " + pdwCurrentBrightness.getValue()); |
| 127 | + System.out.println("Brightness Max: " + pdwMaximumBrightness.getValue()); |
| 128 | + |
| 129 | + // Contrast |
| 130 | + DWORDByReference pdwMinimumContrast = new DWORDByReference(); |
| 131 | + DWORDByReference pdwCurrentContrast = new DWORDByReference(); |
| 132 | + DWORDByReference pdwMaximumContrast = new DWORDByReference(); |
| 133 | + Dxva2.INSTANCE.GetMonitorContrast(hPhysicalMonitor, pdwMinimumContrast, pdwCurrentContrast, pdwMaximumContrast); |
| 134 | + |
| 135 | + System.out.println("Contrast Min: " + pdwMinimumContrast.getValue()); |
| 136 | + System.out.println("Contrast Current: " + pdwCurrentContrast.getValue()); |
| 137 | + System.out.println("Contrast Max: " + pdwMaximumContrast.getValue()); |
| 138 | + |
| 139 | + // Temperature |
| 140 | + MC_COLOR_TEMPERATURE.ByReference pctCurrentColorTemperature = new MC_COLOR_TEMPERATURE.ByReference(); |
| 141 | + Dxva2.INSTANCE.GetMonitorColorTemperature(hPhysicalMonitor, pctCurrentColorTemperature); |
| 142 | + System.out.println("Current Temp: " + pctCurrentColorTemperature.getValue()); |
| 143 | + |
| 144 | + // Capabilities string |
| 145 | + DWORDByReference pdwCapabilitiesStringLengthInCharacters = new DWORDByReference(); |
| 146 | + Dxva2.INSTANCE.GetCapabilitiesStringLength(hPhysicalMonitor, pdwCapabilitiesStringLengthInCharacters); |
| 147 | + DWORD capStrLen = pdwCapabilitiesStringLengthInCharacters.getValue(); |
| 148 | + |
| 149 | + LPSTR pszASCIICapabilitiesString = new LPSTR(new Memory(capStrLen.intValue())); |
| 150 | + Dxva2.INSTANCE.CapabilitiesRequestAndCapabilitiesReply(hPhysicalMonitor, pszASCIICapabilitiesString, capStrLen); |
| 151 | + System.out.println("Cap-String:" + new String(pszASCIICapabilitiesString.getPointer().getString(0))); |
| 152 | + |
| 153 | + // Position |
| 154 | + MC_POSITION_TYPE ptPositionType = MC_POSITION_TYPE.MC_HORIZONTAL_POSITION; |
| 155 | + DWORDByReference pdwMinimumPosition = new DWORDByReference(); |
| 156 | + DWORDByReference pdwCurrentPosition = new DWORDByReference(); |
| 157 | + DWORDByReference pdwMaximumPosition = new DWORDByReference(); |
| 158 | + Dxva2.INSTANCE.GetMonitorDisplayAreaPosition(hPhysicalMonitor, ptPositionType, pdwMinimumPosition, pdwCurrentPosition, pdwMaximumPosition); |
| 159 | + |
| 160 | + System.out.println("Position (horz) Min: " + pdwMinimumPosition.getValue()); |
| 161 | + System.out.println("Position (horz) Current: " + pdwCurrentPosition.getValue()); |
| 162 | + System.out.println("Position (horz) Max: " + pdwMaximumPosition.getValue()); |
| 163 | + |
| 164 | + // Size |
| 165 | + MC_SIZE_TYPE ptSizeType = MC_SIZE_TYPE.MC_WIDTH; |
| 166 | + DWORDByReference pdwMinimumSize = new DWORDByReference(); |
| 167 | + DWORDByReference pdwCurrentSize = new DWORDByReference(); |
| 168 | + DWORDByReference pdwMaximumSize = new DWORDByReference(); |
| 169 | + Dxva2.INSTANCE.GetMonitorDisplayAreaSize(hPhysicalMonitor, ptSizeType, pdwMinimumSize, pdwCurrentSize, pdwMaximumSize); |
| 170 | + |
| 171 | + System.out.println("Width Min: " + pdwMinimumSize.getValue()); |
| 172 | + System.out.println("Width Current: " + pdwCurrentSize.getValue()); |
| 173 | + System.out.println("Width Max: " + pdwMaximumSize.getValue()); |
| 174 | + |
| 175 | + // Gain |
| 176 | + MC_GAIN_TYPE ptGainType = MC_GAIN_TYPE.MC_RED_GAIN; |
| 177 | + DWORDByReference pdwMinimumGain = new DWORDByReference(); |
| 178 | + DWORDByReference pdwCurrentGain = new DWORDByReference(); |
| 179 | + DWORDByReference pdwMaximumGain = new DWORDByReference(); |
| 180 | + Dxva2.INSTANCE.GetMonitorRedGreenOrBlueGain(hPhysicalMonitor, ptGainType, pdwMinimumGain, pdwCurrentGain, pdwMaximumGain); |
| 181 | + |
| 182 | + System.out.println("Red Gain Min: " + pdwMinimumSize.getValue()); |
| 183 | + System.out.println("Red Gain Current: " + pdwCurrentSize.getValue()); |
| 184 | + System.out.println("Red Gain Max: " + pdwMaximumSize.getValue()); |
| 185 | + |
| 186 | + // Drive |
| 187 | + MC_DRIVE_TYPE ptDriveType = MC_DRIVE_TYPE.MC_RED_DRIVE; |
| 188 | + DWORDByReference pdwMinimumDrive = new DWORDByReference(); |
| 189 | + DWORDByReference pdwCurrentDrive = new DWORDByReference(); |
| 190 | + DWORDByReference pdwMaximumDrive = new DWORDByReference(); |
| 191 | + Dxva2.INSTANCE.GetMonitorRedGreenOrBlueDrive(hPhysicalMonitor, ptDriveType, pdwMinimumDrive, pdwCurrentDrive, pdwMaximumDrive); |
| 192 | + |
| 193 | + System.out.println("Red Drive Min: " + pdwMinimumSize.getValue()); |
| 194 | + System.out.println("Red Drive Current: " + pdwCurrentSize.getValue()); |
| 195 | + System.out.println("Red Drive Max: " + pdwMaximumSize.getValue()); |
| 196 | + |
| 197 | + // Timing Report |
| 198 | + MC_TIMING_REPORT pmtrMonitorTimingReport = new MC_TIMING_REPORT(); |
| 199 | + Dxva2.INSTANCE.GetTimingReport(hPhysicalMonitor, pmtrMonitorTimingReport); |
| 200 | + System.out.println("HorizontalFrequencyInHZ " + pmtrMonitorTimingReport.dwHorizontalFrequencyInHZ); |
| 201 | + System.out.println("VerticalFrequencyInHZ " + pmtrMonitorTimingReport.dwVerticalFrequencyInHZ); |
| 202 | + |
| 203 | + System.out.println("--------------------------------------"); |
| 204 | + } |
| 205 | + |
| 206 | +} |
0 commit comments