13 Replies - 2575 Views - Last Post: 13 August 2010 - 01:52 PM Rate Topic: -----

#1 spiderdan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 27-September 09

Hexadecimal sums and retrieve monitor make/model

Posted 09 August 2010 - 07:54 PM

EDIT: Please see update post below

I've searched long and far for a decent program to manage multiple monitors. UltraMon is alright, but I'm just not happy. So I thought I'd try my hand at making something. Below is my code so far. Its working well to get the current settings. I also was able to retrieve all functional settings with slight modifications. My real problem is this, I can get the name of the graphics card alright, but the best I can do for the monitor is Generic pnp Monitor. How can I get the make/model of the monitor? I'm also confused about how to use StateFlags to see what mode the monitor is in (primary, enabled, etc.) (see here). As you can see I outputted stateflags to the console. What is returned is a number of little significance to me. Unsure how to compare it to the constants described on the msdn page. I appreciate any help you can offer. I'm afraid this is the most difficult programming task I've ever undertaken, but I am learning. So far I'm only at the stage of gathering info about connected monitors. You may here more from me as I progress. :)

code
#include <windows.h>
#include <iostream.h>

int main(){
	DISPLAY_DEVICE lpDisplayDevice;
	lpDisplayDevice.cb = sizeof(lpDisplayDevice);
	DWORD iDevNum = 0;

		while (EnumDisplayDevices(0, iDevNum, &lpDisplayDevice, 0)){
		cout<<lpDisplayDevice.DeviceString<<endl;
		cout<<lpDisplayDevice.StateFlags<<endl;

		DEVMODE lpDevMode;
		lpDevMode.dmSize = sizeof(lpDevMode);
		if (EnumDisplaySettings(lpDisplayDevice.DeviceName, -1, &lpDevMode)){
			cout<<lpDevMode.dmDisplayFrequency<<endl;
			cout<<lpDevMode.dmPelsWidth<<endl;
			cout<<lpDevMode.dmPelsHeight<<endl
		}

		ZeroMemory(&lpDisplayDevice, sizeof(lpDisplayDevice));
		lpDisplayDevice.cb = sizeof(lpDisplayDevice);
		iDevNum++;
	}
}



code output (for me)
NVIDIA GeForce GTX 260
134217733
59
1680
1050
NVIDIA GeForce GTX 260
134217728
RDPDD Chained DD
8
RDP Encoder Mirror Driver
2097160
RDP Reflector Display Driver
2097160

This post has been edited by spiderdan: 10 August 2010 - 03:48 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Hexadecimal sums and retrieve monitor make/model

#2 spiderdan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 27-September 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 10 August 2010 - 03:46 PM

I have found the solution to one of my two problems, which of course has opened a new question. The StateFlags value is the sum of the constants relative to that particular monitor as given on the msdn page (rather, the hexadecimal value of those constants. I was able to obtain the hex values from the official windows sdk and have added their values as definitions in the code below. I am using mingw so did not have these definitions simple by including windows.h Calling StateFlags returns the hex (DWORD) value of all applicable constants. I then need to know which combination of constants sums to this value so I can discover which constants are applicable. Is the only way to do this to calculate all the possible combinations? Or is there a better/more efficient way? Also, I am still wondering how I can obtain a more logical name for each monitor. Thanks ahead of time!

#include <windows.h>
#include <iostream.h>

#define DISPLAY_DEVICE_ACTIVE              0x00000001
#define DISPLAY_DEVICE_MIRRORING_DRIVER    0x00000008
#define DISPLAY_DEVICE_MODESPRUNED         0x08000000
#define DISPLAY_DEVICE_PRIMARY_DEVICE      0x00000004
#define DISPLAY_DEVICE_REMOVABLE           0x00000020
#define DISPLAY_DEVICE_VGA_COMPATIBLE      0x00000010

int main(){
	DISPLAY_DEVICE lpDisplayDevice;
	lpDisplayDevice.cb = sizeof(lpDisplayDevice);
	DWORD iDevNum = 0;

		while (EnumDisplayDevices(0, iDevNum, &lpDisplayDevice, 0)){
		cout<<lpDisplayDevice.DeviceString<<endl;
		cout<<lpDisplayDevice.StateFlags<<endl;

		DEVMODE lpDevMode;
		lpDevMode.dmSize = sizeof(lpDevMode);
		if (EnumDisplaySettings(lpDisplayDevice.DeviceName, -1, &lpDevMode)){
			cout<<lpDevMode.dmDisplayFrequency<<endl;
			cout<<lpDevMode.dmPelsWidth<<endl;
			cout<<lpDevMode.dmPelsHeight<<endl;		}

		ZeroMemory(&lpDisplayDevice, sizeof(lpDisplayDevice));
		lpDisplayDevice.cb = sizeof(lpDisplayDevice);
		iDevNum++;
	}
}

Was This Post Helpful? 0
  • +
  • -

#3 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 10 August 2010 - 04:37 PM

Quote

I then need to know which combination of constants sums to this value so I can discover which constants are applicable.
Bitwise AND.

Convert each of those hex values to binary. Do you see how bitwise AND can be used to determine what states are set and what aren't?
Was This Post Helpful? 1
  • +
  • -

#4 spiderdan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 27-September 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 10 August 2010 - 07:46 PM

Oler1s, thanks for the help! I researched bitwise and I thought I knew what you meant, but I'm afraid its not working like I expected. From what I read I would have thought this code would work.

updated code
#include <windows.h>
#include <iostream.h>

#define DISPLAY_DEVICE_ACTIVE              0x00000001
#define DISPLAY_DEVICE_MIRRORING_DRIVER    0x00000008
#define DISPLAY_DEVICE_MODESPRUNED         0x08000000
#define DISPLAY_DEVICE_PRIMARY_DEVICE      0x00000004
#define DISPLAY_DEVICE_REMOVABLE           0x00000020
#define DISPLAY_DEVICE_VGA_COMPATIBLE      0x00000010

int main(){
	DISPLAY_DEVICE lpDisplayDevice;
	lpDisplayDevice.cb = sizeof(lpDisplayDevice);
	DWORD iDevNum = 0;

		while (EnumDisplayDevices(0, iDevNum, &lpDisplayDevice, 0)){
		cout<<lpDisplayDevice.DeviceString<<endl;
		cout<<lpDisplayDevice.StateFlags<<endl;
		if (lpDisplayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE == DISPLAY_DEVICE_ACTIVE){
			cout<<"DISPLAY_DEVICE_ACTIVE"<<endl;
		}
		if (lpDisplayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER == DISPLAY_DEVICE_MIRRORING_DRIVER){
			cout<<"DISPLAY_DEVICE_MIRRORING_DRIVER"<<endl;
		}
		if (lpDisplayDevice.StateFlags & DISPLAY_DEVICE_MODESPRUNED == DISPLAY_DEVICE_MODESPRUNED){
			cout<<"DISPLAY_DEVICE_MODESPRUNED"<<endl;
		}
		if (lpDisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE == DISPLAY_DEVICE_PRIMARY_DEVICE){
			cout<<"DISPLAY_DEVICE_PRIMARY_DEVICE"<<endl;
		}
		if (lpDisplayDevice.StateFlags & DISPLAY_DEVICE_REMOVABLE == DISPLAY_DEVICE_REMOVABLE){
			cout<<"DISPLAY_DEVICE_REMOVABLE"<<endl;
		}
		if (lpDisplayDevice.StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE == DISPLAY_DEVICE_VGA_COMPATIBLE){
			cout<<"DISPLAY_DEVICE_VGA_COMPATIBLE"<<endl;
		}


		DEVMODE lpDevMode;
		lpDevMode.dmSize = sizeof(lpDevMode);
		if (EnumDisplaySettings(lpDisplayDevice.DeviceName, -1, &lpDevMode)){
			cout<<lpDevMode.dmDisplayFrequency<<endl;
			cout<<lpDevMode.dmPelsWidth<<endl;
			cout<<lpDevMode.dmPelsHeight<<endl;		}

		ZeroMemory(&lpDisplayDevice, sizeof(lpDisplayDevice));
		lpDisplayDevice.cb = sizeof(lpDisplayDevice);
		iDevNum++;
	}
}



updated output
NVIDIA GeForce GTX 260
134217733
DISPLAY_DEVICE_ACTIVE
DISPLAY_DEVICE_MIRRORING_DRIVER
DISPLAY_DEVICE_MODESPRUNED
DISPLAY_DEVICE_PRIMARY_DEVICE
DISPLAY_DEVICE_REMOVABLE
DISPLAY_DEVICE_VGA_COMPATIBLE
59
1680
1050
NVIDIA GeForce GTX 260
134217728
RDPDD Chained DD
8
RDP Encoder Mirror Driver
2097160
RDP Reflector Display Driver
2097160


As you can see all of the values return true for the first StateFlags, but none for the second. Should be a few for both.
Was This Post Helpful? 0
  • +
  • -

#5 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 10 August 2010 - 07:55 PM

Order of operations problems. == is evaluated before &. So you want to have ( (lpDisplayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE) == DISPLAY_DEVICE_ACTIVE) instead. Notice the extra pair of parens.

This post has been edited by Oler1s: 10 August 2010 - 07:55 PM

Was This Post Helpful? 1
  • +
  • -

#6 spiderdan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 27-September 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 10 August 2010 - 08:22 PM

I hate it when I miss something so simple. :) Thanks for all the help Oler1s! Still waiting to see if someone knows how to get the name of a monitor as far as make/model.
Was This Post Helpful? 0
  • +
  • -

#7 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 10 August 2010 - 09:34 PM

Quote

Still waiting to see if someone knows how to get the name of a monitor as far as make/model.
Can Windows do this right now? As in, can Device Manager or wherever get you the monitor name?
Was This Post Helpful? 1
  • +
  • -

#8 spiderdan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 27-September 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 11 August 2010 - 09:04 PM

Device manager lists the same thing I got, generic pnp monitor. Under change display settings, Nvidia Control Panel, and Ultramon my monitor is listed as X223W (the model name) and my tv is listed as LG TV. There must be a way, I'm just not sure how.
Was This Post Helpful? 0
  • +
  • -

#9 KYA  Icon User is offline

  • su wtf -am -i /doing/with/my/life
  • member icon

Reputation: 2979
  • View blog
  • Posts: 19,035
  • Joined: 14-September 07

Re: Hexadecimal sums and retrieve monitor make/model

Posted 11 August 2010 - 09:16 PM

My initial thought is to do it through the GPU. All Windows is being told is that it's a plug n play monitor.


My second thought is that there might be some info you could use in the registry, but my searching hasn't turned up anything helpful.
Was This Post Helpful? 1
  • +
  • -

#10 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 11 August 2010 - 09:23 PM

That's a pretty good guess. I'm thinking DXGI_OUTPUT_DESC.

EDIT: This might not be so straightforward, actually. I don't think what I suggested will pan out.

This post has been edited by Oler1s: 11 August 2010 - 10:08 PM

Was This Post Helpful? 1
  • +
  • -

#11 spiderdan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 27-September 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 12 August 2010 - 10:17 PM

Thanks for the tips guys. Gives me something to go on anyway. KYA, would going through the gpu require some Nvidia (ati, intel, etc) specific apis or something of the sort? Just seems like there must be a more generic way...

Oler1s, that is an interesting method. Why do you think it won't pan out? Tried to give it a shot but mingw has no DXGI.h! Might have to get visual studio running again (hadn't missed it since I switched over to eclipse). Is it possible to use Windows SDK 7.1 with eclipse? It does have "command line tools".
Was This Post Helpful? 0
  • +
  • -

#12 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 12 August 2010 - 10:49 PM

Quote

Oler1s, that is an interesting method. Why do you think it won't pan out?
Because I wrote code.

Quote

Tried to give it a shot but mingw has no DXGI.h!
DXGI.h is from the DirectX SDK.

Quote

Is it possible to use Windows SDK 7.1 with eclipse? It does have "command line tools".
You would have to switch over to the VC compiler.

My next guess would be WMI. But that's a bit of a pain to write code for, which I didn't have time to investigate when I made my last post. If I do investigate that route, I'll probably write code in C# or something to investigate if WMI does the job, and then only look at the C++ API.

I'm not sure, really. I haven't done this before, and it's not very clearly documented. It's not exactly rocket science to to investigate, but takes a bit of time.
Was This Post Helpful? 1
  • +
  • -

#13 spiderdan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 27-September 09

Re: Hexadecimal sums and retrieve monitor make/model

Posted 13 August 2010 - 11:23 AM

Oler1s, that definitely seems to be what I'm looking for. Have never messed with WMI/COM before, but I am reading up on it now. Hopefully I'll be able to make something of this. I appreciate all the help you've given me. May post back as I try to figure this out and, inevitably, come up with more questions.
Was This Post Helpful? 0
  • +
  • -

#14 KYA  Icon User is offline

  • su wtf -am -i /doing/with/my/life
  • member icon

Reputation: 2979
  • View blog
  • Posts: 19,035
  • Joined: 14-September 07

Re: Hexadecimal sums and retrieve monitor make/model

Posted 13 August 2010 - 01:52 PM

View Postspiderdan, on 12 August 2010 - 10:17 PM, said:

Thanks for the tips guys. Gives me something to go on anyway. KYA, would going through the gpu require some Nvidia (ati, intel, etc) specific apis or something of the sort?


When I wrote that, I was thinking DirectX, but Oler1s already tried that road.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1