Hello all,
I've just connected a second monitor to my 'puter and am looking a the results returned by the "EnumDisplayMonitors" (user32.dll) call. The callback returns both monitors *as long as* I provide a NULL as the DC argument (and the clipping rectangle argument).
When I set the DC argument to the output of "GetDC,0" (which should return the DC of the desktop) neither the primary nor the secondary monitor is shown.
I must be misunderstanding something, but I have no idea what ... :-(
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors
Regards,
Rudy Wieser
The given HDC doesn't really matter as long as it's a valid handle or is NULL.
So, chances are that you're giving a RECT which is outside of
all monitors' area.
Correction: HDC matters.
...
Otherwise, the origin is the window of the HDC.
Single monitor configuration:
I have no idea how you get five entries.
On my machine
"EnumDisplayMonitors" only calls its callback twice, once for each monitor
on the desktop (if I detach the second monitor from the desktop the callback gets called only once - for the primary monitor).
but rather a "in which monitor(s) does this area reside" indicator.
You misunderstood. Each "enum#" log represent each call
to EnumDisplayMonitors(), but with different arguments.
but rather a "in which monitor(s) does this area reside" indicator.
I was trying to tell you that. Maybe my English isn't good enough.
But that creates a problem: I've done the same four with-and-without DC and rectangle tests, but you get results back using a DC while I get none. :-|
The only difference I can currently imagine is the used OS. In my case
thats XPsp3.
This may seem overkill, but I'm trying to leave no stone unturned.
You may need to debug your program to check the arguments right before EnumDisplayMonitors() is called. i.e. after the arguments are pushed into
the stack.
Manually check the arguments in the memory to make sure they're
passed with the correct order, structure (plus alignments), value
types (or bitness), and values.
Then do a single step debugging
to make sure that its the EnumDisplayMonitors() function which
is called, instead of other function.
This may seem overkill, but I'm trying to leave no stone unturned.
JJ,
This may seem overkill, but I'm trying to leave no stone unturned.
I found it, and you will never guess to what the problem was/is ....
I ran that code from within a fullscreen (80x25 text mode) *console* . When I switched to windowed (GUI) mode I got four results for the four tests.
Although the GetDC,0 result looked to be OK, it must have pointed to something different than the actual virtual screen.
IOW, the function work, just not always.
Oh... If your program is built as a console application, it's
probably due to the fact that a console application's thread
by default is not a GUI thread.
... using `IsGUIThread()`, while according to the documentation ...
JJ,
Oh... If your program is built as a console application, it's
probably due to the fact that a console application's thread
by default is not a GUI thread.
I have a bit of a problem in understanding that. I'm asking for the destop DC (GetDC,0) but am not getting it. Why ? What has /my/ thread not being a GUI thread have anything to do with that ?
Also, what am I getting instead (and why does the MS documentation not mention it ? :-( ).
... using `IsGUIThread()`, while according to the documentation ...
The "docs.microsoft.com" description for that function is rather lacking in depth. Could you tell me which documentation you are referring to ?
I've tested as a console application, and sure enough, it still works.
(using ALT-tab)
JJ,
I've tested as a console application, and sure enough, it still works.
It does, as long as you are in GUI mode (a windowed console). It doesn't
(at least at my end) when you switch to full-screen text-mode. In my case I always start with "MODE CON COLS=80 LINES=25".
And I realized just now that that is what makes it extra strange : The app
is a console app one in both cases, but in the full-screen mode it suddenly looses track of its (GUI) desktop DC.
I just test to ask for the DC twice (and destroy it) ihn the same thread,
but in between switch from fullscreen console to GUI (windowed) mode (using ALT-tab). I get two different DC results. As a test I also just ran it fully in GUI and after in console mode. In the former I get the same DC
back twice. In the latter I get two different ones.
However, `GetDC(0)` returns a valid handle regardless. That confuses me.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 42:45:19 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,851 |