Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetDeviceCaps for Monitor

3 views
Skip to first unread message

Bill

unread,
Aug 15, 2002, 2:21:31 PM8/15/02
to
I'm trying to get the PixelsPerInch value for the monitor and I've tried:
ppi= GetDeviceCaps(Screen->Monitors[0]->Handle,LOGPIXELSX);
ppi= GetDeviceCaps(ThisForm->Monitor->Handle,LOGPIXELSX);

Both return 0. Is there another way to get both the X & Y PixelsPerInch?
Or should I use Screen->PixelsPerInch and assume square pixels?

TIA

B

Remy Lebeau [TeamB]

unread,
Aug 15, 2002, 2:47:12 PM8/15/02
to
GetDeviceCaps() expects an HDC, but you're passing it an HMONITOR instead.
You need to manually obtain the proper HDC for a particular monitor first

According to MSDN:

"Any function that returns a display device context (DC) normally
returns a DC for the primary monitor. To obtain the DC for another monitor,
use the EnumDisplayMonitors function. Or, you can use the device name from
the GetMonitorInfo function to create a DC with CreateDC."


Gambit

"Bill" <Bi...@bill.net> wrote in message news:3D5BF12B...@bill.net...

Bill

unread,
Aug 15, 2002, 3:46:46 PM8/15/02
to
"Remy Lebeau [TeamB]" wrote:

> GetDeviceCaps() expects an HDC, but you're passing it an HMONITOR instead.

Ah....

> You need to manually obtain the proper HDC for a particular monitor first
>
> According to MSDN:
>
> "Any function that returns a display device context (DC) normally
> returns a DC for the primary monitor. To obtain the DC for another monitor,
> use the EnumDisplayMonitors function. Or, you can use the device name from
> the GetMonitorInfo function to create a DC with CreateDC."

The Win32 SDK help doesn't have any information on GetMonitorInfo or
EnumDisplayMonitors. Is there another place I can find information on these?

B

Bill

unread,
Aug 15, 2002, 4:07:26 PM8/15/02
to
> The Win32 SDK help doesn't have any information on GetMonitorInfo or
> EnumDisplayMonitors. Is there another place I can find information on these?

Never mind... Did a google search and found a posting with the appropriate
information.

Thanks...

B

Remy Lebeau [TeamB]

unread,
Aug 15, 2002, 4:32:14 PM8/15/02
to
http://msdn.microsoft.com


Gambit

"Bill" <Bi...@bill.net> wrote in message news:3D5C0525...@bill.net...

Rodolfo Frino

unread,
Aug 15, 2002, 5:03:53 PM8/15/02
to
I have an example in my WEB page:

http://home.iprimus.com.au/starcinema2001/GetMonitorInfo.html

That I hope it helps

Rodolfo

"Bill" <Bi...@bill.net> wrote in message news:3D5BF12B...@bill.net...

Rodolfo Frino

unread,
Aug 15, 2002, 5:13:56 PM8/15/02
to
and including the ppi :

void Get_MonitorInfo()
{

String S_xscreen;
String S_yscreen;
String S_screenwidth_mm;
String S_screenheight_mm;
String S_bitsperpixel;
String S_ppi_x;
String S_ppi_y;

HWND hDesktop = GetDesktopWindow();
HDC hdc = GetDC( hDesktop );

S_xscreen = String( GetSystemMetrics( SM_CXSCREEN ) );
S_yscreen = String( GetSystemMetrics( SM_CYSCREEN ) );
S_bitsperpixel = String( GetDeviceCaps(hdc,BITSPIXEL) );
S_screenwidth_mm = String( GetDeviceCaps( hdc, HORZSIZE ) );
S_screenheight_mm = String( GetDeviceCaps( hdc, VERTSIZE ) );
S_ppi_x = String( GetDeviceCaps( hdc, LOGPIXELSX ) );
S_ppi_y = String( GetDeviceCaps( hdc, LOGPIXELSY ) );

ShowMessage( "Screen Resolution (pixels) "
+ S_xscreen + "x"
+ S_yscreen + "\n"
+ "Screen Width " + S_screenwidth_mm + " mm" + "\n"
+ "Screen Height " + S_screenheight_mm + " mm" + "\n"
+ "Bits per pixel " + S_bitsperpixel + "\n"
+ "Pixels per inch (x) " + S_ppi_x + "\n"
+ "Pixels per inch (y) " + S_ppi_y );
}

Rodolfo

0 new messages