The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: NoCforMe on April 11, 2012, 04:30:28 AM

Title: Need an "invisible" DC
Post by: NoCforMe on April 11, 2012, 04:30:28 AM
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.
Title: Re: Need an "invisible" DC
Post by: jj2007 on April 11, 2012, 05:36:47 AM
Common practice is to use CreateCompatibleDC. Search the forum for BeginPaint CreateCompatibleDC
Title: Re: Need an "invisible" DC
Post by: qWord on April 11, 2012, 05:38:05 AM
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
Title: Re: Need an "invisible" DC
Post by: 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
Title: Re: Need an "invisible" DC
Post by: qWord on April 11, 2012, 08:26:08 AM
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
Title: Re: Need an "invisible" DC
Post by: dedndave on April 11, 2012, 11:35:45 AM
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