CreateDC of a monitor

7d4d56b962408d53af83794a02a6ff24
0
steinb 101 Dec 10, 2007 at 12:41

Following Visual c++ 2008 Express’ help on multiple monitors, I’ve managed to get a list of monitor devices via EnumDisplayDevices(..) [first enumerating adapters, then monitors in an inner loop]. Now I want to paint to one of the monitors; the help says I should just use

“hdc = CreateDC(lpszDisplayName, NULL, NULL, lpDevMode);
In this call, the lpszDisplayName parameter is one of the device names returned by EnumDisplayDevices and lpDevMode is a description of the graphics mode for this device. “

When I try this (with DISPLAY_DEVICE.DeviceName from EnumDisplayDevices, e.g. “\\.\DISPLAY1\Monitor0”, as lpszDisplayName, and NULL as lpDevMode), I get the error code ERROR_INVALID_PRINTER_NAME (1801).

How can I fix this?
And could anyone help me towards preparing a minimalistic DevMode for just any graphics mode (ok, maybe of a given resolution)?

5 Replies

Please log in or register to post a reply.

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Dec 10, 2007 at 16:27

Why not simply take the desktop HDC (GetDC(0)) and figure out the monitor’s area in the virtual desktop to paint on that monitor?

7d4d56b962408d53af83794a02a6ff24
0
steinb 101 Dec 10, 2007 at 16:54

Well, it would be much preferable not to allow the mouse or any windows, dialogs, etc. to wander into that region, so I would prefer having the monitor not attached (e.g. part of) the desktop.
I presume desktop and virtual desktop are identical in this sense?

I’ve meanwhile discovered

http://groups.google.com.au/group/microsoft.public.win32.programmer.kernel/browse_thread/thread/575f1452aacd4c8b?tvc=2&q=nvidia+createdc+%22%5C%5C.%5CDISPLAY1%22

It suggests that, whilst once possible, unattached screens cannot be painted on with modern versions of windows (or rather they can, but without producing actual output). It also claims that, as of 2004, the part of the visual studio help that I cited in the first post from my “2008 Express” version is outdated.

And the CreateDC approach I outlined before now works (without producing output on unattached screens, but also without any failing GDI drawing calls), with the code listed in the above link, although that seems to depend on compiling for unicode. This I’ve learned from (and partially verified)

http://www.realtimesoft.com/multimon/programming/independent_displays.asp

Guess I’ll resign into using a desktop extended over both monitors. Pity.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 10, 2007 at 17:00

Yeah, the way Windows manages multiple monitors is to have them occupy different rectangles of a virtual desktop. I don’t think you can have a monitor that can be drawn to independently but isn’t part of the virtual desktop.

Plus, it seems to me you shouldn’t really be drawing to the monitor’s DC anyway, but rather create a window that covers the entire monitor and draw to that. If you draw directly to the monitor’s DC, your drawing and Windows’ own drawing of the wallpaper and so forth might fight with each other.

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Dec 10, 2007 at 18:46

@steinb

It suggests that, whilst once possible, unattached screens cannot be painted on with modern versions of windows (or rather they can, but without producing actual output).

That’s true, if I disable the desktop on my other monitor it goes into standby, and changing the resolution in the config panel has no effect. But I wonder, what happens if you change the resolution using ChangeDisplaySettingsEx() for that display?

7d4d56b962408d53af83794a02a6ff24
0
steinb 101 Dec 11, 2007 at 10:19

Thanks for the help.

Obviously the window creation method is the better one;
the only reason I was interested in creating a DC for an entire monitor was that my Visual C++ 2008 Express Edition mislead me into thinking that this way I could use a monitor for output where windows intenionally cannot be created. Which apparently is a feature discontinued around the turn of the millenium.