6

I have come across an issue when it comes to loading up a user-friendly setting for a game.

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


What I have 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 am expecting:

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

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


Additional:
Another thing I am trying to achieve with this is being able to tell the orientation of the screen. From what I've seen: it can be either Landscape, Portrait, Landscape (flipped) or Portrait (flipped). I would then only like to run the game on Landscape - flipped or not.

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

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

I am prepared to use registry access and possible dll implementation, so I have decided to tag those in case it comes to that.

Jubin Patel
  • 1,959
  • 19
  • 38

3 Answers3

3

Road to Success

The monitor name information you wish to access is contained within the windows registry location:

SYSTEM\CurrentControlSet\Enum\DISPLAY

On the accepted answer from question Get PC's Monitor Information Using .NET / WMI , there is a link pointing to WMIMonitor .

As a sourceforge project the source is available can be checked to see the internal workings of this custom WMI enabler:

Therefore, if this WMI extension works for you I think a library to access the registry from java is needed, and for you to re-write the code here.

Accessing Registry: read/write to Windows Registry using Java

Fails

Using various calls to WMI, the actual names of the monitors were not displayed. It was however quite informative as there is information that describes the the WMI library, e.g.:

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155
  • I tried looking in the windows registry to no avail. It came up with data similar to that of the `PNPDeviceID` from the wmic. I also then tried parsing bytes from the EDID and no correct data showed up. Most of what I got were Chinese (?) characters or boxes. I tried replicated lines 135-138 in the given project, most of that data though didn't come back well-received. For example, line 135 gave me: `Ⱥ耘焸ⵀ堬䔀︟ᄀ` –  Jun 26 '13 at 17:32
  • That was done with UTF-16 encoding, I then tried UTF-8 encoding and got more promising results: `:�q8-@X,E` which makes me think one of the 4 parameters might actually be legible. –  Jun 26 '13 at 17:36
  • The fourth parameter returned the correct name of the monitor (I think) and appeared to be working. The problem is the huge amount of data at the front that was irrelevant. –  Jun 26 '13 at 17:38
  • Your implementing this in java using a library? – Menelaos Jun 26 '13 at 17:44
  • No. Just read the contents using a registry reader I made a while ago. –  Jun 26 '13 at 18:08
1

You could execute wmic DESKTOPMONITOR from your Java Program and get the names out of it.

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

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

s3lph
  • 4,575
  • 4
  • 21
  • 38
  • Thanks for the response, as stated in the question I have already tried this. The names returned were in no way correct. –  Jul 01 '13 at 20:50
  • If you take a look into your Device Manager and view the details of one of your screens, you'll see that these are all the information Windows got about your screens. What names do you really expect? Something like "SomeBrand SomeSeries SomeModelID"? – s3lph Jul 02 '13 at 09:38
1

To get the display names from OS X you could use the command line utility (invoke using Runtime.exec(...)):

system_profiler SPDisplaysDataType [-xml]

The optional -xml gives you a (huge) PropertyList xml structure, but should be okay to parse using your favorite XML libs. Without the switch, you'll have a indented plain text, I'm not sure how safe this format is to parse.

Harald K
  • 26,314
  • 7
  • 65
  • 111