I think I might be having a moment here :biggrin:
Is there anyway to hang onto an hDC when drawing in GDI.
I was wondering if one could eliminate all the re-creation and destroying of DC's Handles and Objects, every time one has to update the drawing areas.
Seems like such a waste of code space and time.
:dazzled:
Plonk them into GLOBAL values, create them at the start and deallocate them on exit.
i suppose there is a trade-off here
you may reduce the code and even speed it up a little
but, you are also using system resources when you hang on to a DC
don't get me wrong - i do this myself sometimes
but, it's good to understand the downside
there are a limited number of DC's that may be created
granted, it's a fairly large number
also - creating a DC consumes memory
Maybe I didn't explain myself properly ;)
You BeginPaint with a window handle and it returns a device context (also in the PaintStruct), which one uses to paint.
You EndPaint with the window handle and the PaintStuct, which contains the device context.
If I understand it correctly,... only after EndPaint does all the painting happen...
From what i understand is that you lose the Device Context here.. forcing you to repeat the whole context allocation process.
Question.. is the Device Context handle really lost here or can one reuse it (keep it in a global variable)?
Reuse it with the same window handle.. that is!
a lot of "what if's" i don't know the answers to - lol
but, i can tell you 2 things.....
1) BeginPaint/EndPaint do more than assign a DC
they also manage the update region, and probably do other things behind the scene
2) if you want to use a DC that way, use GetDC (or GetWindowDC if you want the entire window)
BeginPaint and EndPaint should only be used in response to a WM_PAINT message
i would imagine the DC handle is only valid for that time
the DC i was refering to above was a memory DC, not a physical device DC
Quote from: dedndave on February 09, 2016, 11:00:37 PM
2) if you want to use a DC that way, use GetDC (or GetWindowDC if you want the entire window)
BeginPaint and EndPaint should only be used in response to a WM_PAINT message
i would imagine the DC handle is only valid for that time
Thanks... this what I think it is :t
Another possibility is a Private Display Device Context (https://msdn.microsoft.com/en-us/library/windows/desktop/dd162872(v=vs.85).aspx).
Nice... thank you sire :t