Can you create an information context for the display?
Adrian McCarthy asks, “Can you create an information context for the display? … I can call CreateDC(“DISPLAY”), but perhaps that wouldn’t generalize for a multiple-monitor display with different settings on each screen. I’m trying to avoid constantly creating and destroying DCs when all I need to do is measure strings, check color depth, dpi, etc.”
I admire the effort of trying to avoid creating a whole DC when all you want is to perform some inquiries. Some inquiries are monitor-independent, like getting the DPI or measuring strings, so you can just use
GetDC(NULL) to get a temporary DC. This is cheaper than a full-on
GetDC goes through the DC cache, so you’re just grabbing a DC out of the cache temporarily, doing a little computation, and then returning it to the cache (with
If you are doing something that is monitor-specific, like getting its color depth, you can call
EnumDisplayMonitors on the desktop DC to look at each monitor.
(And just for completeness, to get the name for a specific monitor if you really do want to create an IC for it, call
GetMonitorInfo with a MONITORINFOEX and look at the
Update: Original text said “DC” in the last sentence by mistake.