News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Need an "invisible" DC

Started by NoCforMe, April 11, 2012, 04:30:28 AM

Previous topic - Next topic

NoCforMe

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.

jj2007

Common practice is to use CreateCompatibleDC. Search the forum for BeginPaint CreateCompatibleDC

qWord

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
FPU in a trice: SmplMath
It's that simple!

jj2007

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

qWord

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
FPU in a trice: SmplMath
It's that simple!

dedndave

#5
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