Undrawing Text

Undrawing Text

I have been drawing lines with the MoveToEx & LineTo commands.

To undraw them I just draw the line twice but set the SetROP2 function to R2_XORPEN in between the two draws to invert ther pixels.

I am now trying to do the same with text where I am use the TextOut function.
Is there a function similar to SetROP2 (which just seems to be for pens) for text?

Or is there another way to undraw the text by inverting the pixels.
I don't want to just draw the text again in black (the background colour).

By the way, I have spent a long time searching the help and I am hoping to get 'the' book.



2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Well, generaly speaking, problem of undoing something is far from trivial... For
the actual question, I assume that you want to have the place where text was
drawn restored to the previous state.

A good place to start would be to involve double (or, in this case, perhaps
triple) buffering of DC. This is common technique for drawing complex images on
the screen: you draw into a buffer (compatible DC) instead of
real window DC, and on WM_PAINT just "copy&paste" its contents into window DC.
I'm talking about something like:

(In WinMain)

(in WinMain "program"):

hWinDC = GetDC(hChild)                        !Window's DC 
hMemDC = CreateCompatibleDC(hWinDC)       !A memory DC -- buffer 
hBmp = CreateCompatibleBitmap(hWinDC,jWidth,jHeight)    !Bitmap of appropriate 
iSt = SelectObject(xMemDC%hDC,hBmp)           !...must be selected into memory 

In window procedure:

      IF (GetUpdateRect(hWnd,Rect,.FALSE.)) THEN 
            !BitBlt copies the bit-by-bit from one DC (xMemDC%hDC) to another 
            iSt=BitBlt(hDC,Rect%Left,Rect%Top,  & 
                       Rect%Right-Rect%Left,Rect%Bottom-Rect%Top, & 
      END IF 

In the sample above, you draw into hMemDC wherever you want in your
program. (and call RedrawWindow at the end to get results updated).

BitBlt has the capability you need (replacing SRCCOPY with another
flag). Now, you can create one or few compatible DCs (take into account
that each compatible bitmap consumes memory) and play with them:
say, keep one for previous screen state and another for the current
state; or, draw font into hMemDC and transfer the block into hDC using
...hell, I don't know exactly which flag is equivalent to R2_XORPEN...

Now, take into account that BitBlt uses orthogonal rectangles.
However, there are also MaskBlt and PlgBlt to look at (I have never used them,


Leave a Comment

Please sign in to add a comment. Not a member? Join today