Getting screen names

I ran into a problem when it comes to loading a convenient setting for a game.

What am I trying to do:
I am trying to load the name of all monitors in a different way.


What I tried:


WMIC:

C:\Users\Matt>wmic wmic:root\cli>DESKTOPMONITOR Availability Bandwidth Caption ConfigManagerErrorCode ConfigManagerUserConfig CreationClassName Description DeviceID DisplayType ErrorCleared ErrorDescription InstallDate IsLocked LastErrorCode MonitorManufacturer MonitorType Name PixelsPerXLogicalInch PixelsPerYLogicalInch PNPDeviceID PowerManagementCapabilities PowerManagementSupported ScreenHeight ScreenWidth Status StatusInfo SystemCreationClassName SystemName 8 Generic PnP Monitor 0 FALSE Win32_DesktopMonitor Generic PnP Monitor DesktopMonitor1 (Standard monitor types) Generic PnP Monitor Generic PnP Monitor 96 96 DISPLAY\LGD02DA\4&265EFD6&0&UID67568640 OK Win32_ComputerSystem ALIENWARE 3 Generic PnP Monitor 0 FALSE Win32_DesktopMonitor Generic PnP Monitor DesktopMonitor2 (Standard monitor types) Generic PnP Monitor Generic PnP Monitor 96 96 DISPLAY\SAM08D6\5&14F3DA9&0&UID1078064 1080 1920 OK Win32_ComputerSystem ALIENWARE wmic:root\cli>DESKTOP BorderWidth Caption CoolSwitch CursorBlinkRate Description DragFullWindows GridGranularity IconSpacing IconTitleFaceName IconTitleSize IconTitleWrap Name Pattern ScreenSaverActive ScreenSaverExecutable ScreenSaverSecure ScreenSaverTimeout SettingID Wallpaper WallpaperStretched WallpaperTiled 1 500 TRUE Segoe UI 9 TRUE NT AUTHORITY\SYSTEM (None) FALSE FALSE 1 530 TRUE 43 Segoe UI 9 TRUE Alienware\Matt 0 FALSE 0 C:\Users\Matt\Pictures\Wall Papers\daftpunk3.png TRUE FALSE 1 500 TRUE Segoe UI 9 TRUE .DEFAULT (None) FALSE FALSE 


GraphicsEnvironment (Java code):

  final GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (GraphicsDevice device : environment.getScreenDevices()) { System.out.println(device); System.out.println("\t" + device.getIDstring()); System.out.println("\t" + device.getType()); } 

Output:

 D3DGraphicsDevice[screen=0] \Display0 0 null D3DGraphicsDevice[screen=1] \Display1 0 null D3DGraphicsDevice[screen=2] \Display2 0 null 

What I expect:

 Screen[0]: S23C350 Screen[1]: Mobile PC Display Screen[2]: S23B350 

I have 3 monitors. Each of these names are names taken from the Screen Resolution control panel.


Additionally:
Another thing I'm trying to achieve is to determine the orientation of the screen. From what I saw: it can be a landscape, a portrait, a landscape (inverted) or a portrait (inverted). I would then just want to start the game on Landscape - turned upside down or not.

Being able to distinguish between the two main types will be the next step for me.

Thank you for taking the time to read this, I apologize if something is unclear about this question in advance.

I am ready to use registry access and a possible dll implementation, so I decided to tag those if that happens.

+4
source share
3 answers

Road to success

The monitor name information you want to receive is contained in the Windows registry key:

 SYSTEM\CurrentControlSet\Enum\DISPLAY 

In the accepted answer to the question Get information about a PC monitor using .NET / WMI, there is a link pointing to WMIMonitor .

As a sourceforge project, a source is available that you can check to see the internal operation of this custom WMI tool:

Therefore, if this WMI extension works for you, I think you need a library to access the registry from java, and you need to rewrite the code here .

Access to the registry: read / write to the Windows registry using Java

Fails

Using various calls in WMI, the actual monitor names were not displayed. However, it was very informative, as there is information that describes the WMI library, for example:

+2
source

You can execute wmic DESKTOPMONITOR from your Java program and get the names from it.

 InputStream screenInfo = Runtime.getRuntime().exec("wmic DESKTOPMONITOR").getInputStream(); 

Now you can read the information from screenInfo and find the Names. (Regex?)

+1
source

To get display names from OS X, you can use the command-line utility (call using Runtime.exec(...) ):

 system_profiler SPDisplaysDataType [-xml] 

The optional -xml gives you the (huge) xml PropertyList structure, but should be well-versed using your favorite XML libraries. Without the switch, you will have indented text, I'm not sure how safe this format is for parsing.

+1
source

Source: https://habr.com/ru/post/1487807/


All Articles