I'm working on a project where I need to draw into a device context that doesn't actually display on the screen. (I'm "writing" some text to the DC and measuring it before I actually display it.) What I'd like to use would be a DC which I can draw into without having to worry about interfering with the actual display DC I'm using for that window.
What I've done in the meantime, which works OK, is to draw into a DC that I create (using GetDC() ), but "off-screen". To do this, I use a negative y-coordinate, so that the text is clipped and never actually appears in the window. But it seems like somewhat of a kluge ...
Is there a way to get such an "invisible" DC? The other thing that occurred to me was to draw/paint using NULL brushes and pens, but that seems like more hassle, and besides it didn't work correctly anyhow.
Common practice is to use CreateCompatibleDC. Search the forum for BeginPaint CreateCompatibleDC
e.g.:
mov esi,rv(GetDC,rv(GetDesktopWindow))
mov hDC,rv(CreateCompatibleDC,esi)
mov hBmpSave,rv(SelectObject,hDC,rv(CreateCompatibleBitmap,esi,width,height))
invoke ReleaseDC,rv(GetDesktopWindow),esi
qWord,
Give him a chance to do something useful :wink
mov esi,rv(GetDC,rv(GetDesktopWindow))
mov hDC,rv(CreateCompatibleDC,esi)
mov hBmpSave,rv(SelectObject,hDC,rv(CreateCompatibleBitmap,esi,width,height))
... do stuff ...
invoke ReleaseDC,rv(GetDesktopWindow),esi
Quote from: jj2007 on April 11, 2012, 06:31:23 AM
qWord,
Give him a chance to do something useful :wink
mov esi,rv(GetDC,rv(GetDesktopWindow))
mov hDC,rv(CreateCompatibleDC,esi)
mov hBmpSave,rv(SelectObject,hDC,rv(CreateCompatibleBitmap,esi,width,height))
... do stuff ...
invoke ReleaseDC,rv(GetDesktopWindow),esi
:naughty:
mov esi,rv(GetDC,rv(GetDesktopWindow))
mov hDC,rv(CreateCompatibleDC,esi)
mov hBmpSave,rv(SelectObject,hDC,rv(CreateCompatibleBitmap,esi,width,height))
invoke ReleaseDC,rv(GetDesktopWindow),esi
;...
; do stuff ;-D
;...
invoke DeleteObject,rv(SelectObject,hDC,hBmpSave)
invoke DeleteDC,hDC
:bdg
GetTextExtentPoint32
http://msdn.microsoft.com/en-us/library/dd144938%28v=vs.85%29.aspx
GetTextExtentExPoint
http://msdn.microsoft.com/en-us/library/dd144935%28v=vs.85%29.aspx
btw, all DC's are "invisible" until you display the contents (c programmers call them "objects") :bg