StretchBlt difficulty with forms with TransparentColor = True

I am using the StretchBlt windows function to create a magnifier that follows the mouse in one of my applications,  However it does not "see" a Delphi form that has the TransparentColor property set to true.

I discovered long ago that when using BitBlt to take a screenshot I had to combine SCRCOPY with CAPTUREBLT  ($4000000) like so: SRCCOPY or CAPTUREBLT in order to "see" such forms in my screenshot.
 BitBlt(DestBitmap.Canvas.Handle, 0, 0, DestBitmap.Width, DestBitmap.Height, DC, ox, oy, SRCCOPY or CAPTUREBLT);
(That sees forms with TransparentColor=True)

However doing that with StretchBlt does not have the same effect:
  StretchBlt(Canvas.Handle, 0, 0, Width, Height, FDC,
    P.X, P.Y, SrcWidth, SrcHeight, SRCCOPY or CAPTUREBLT);
Does not see forms with TransparentColor = true.

Any suggestions on how to make that work?  Wheat I need to be able to do is see the portion of the form or of an image on the form that is in a color <other> than the defined transparent color.

Who is Participating?
DMTrumpAuthor Commented:
I have solved the problem!  
I first do a BitBlt to a from the Desktop to a Bitmap using the SRCCOPY or CAPTUREBLT values then
do a StretchBlt from the intermediate Bitmap to the final canvas.  

That works great.  I haven't timed it but it does not seem to cause any noticeable lag in performance on my rather slow test machine.

Here's the code:

// declare the intermediate bitmap
  XB: TBitmap;

// in the onCreate....

// In a timer handler
// where Zoom is the magnification factor
// and Width and Height are the dimensions of the target bitmap to show the stretched image
// PX is the upper left corner of the source
// FDC is GetDC(GetDesktopWindow);

SrcWidth := Width div Zoom;
SrcHeight:= Height div Zoom;

  BitBlt(XB.Canvas.Handle, 0, 0, XB.Width, XB.Height, FDC, P.X, P.Y, SRCCOPY or CAPTUREBLT);

  StretchBlt(Canvas.Handle, 0, 0, Width, Height, XB.Canvas.Handle,
    0, 0, SrcWidth, SrcHeight, SRCCOPY);

// In ondestroy

Did you try with SRCCAND?
DMTrumpAuthor Commented:
I assume you meant SRCAND?  Yes I had tried it - just gor a black image.
SRCCAND is not recognized.
DMTrumpAuthor Commented:
I'd still be glad to here a better solution than the one I arrived at and will award the remaining 450 points for it  Meanwhile, if anyone arrives here looking for a solution to the problem I posed - my method DOES work <BG>
DMTrumpAuthor Commented:
I gave 50 points to jimyX for at least trying to help - even though I figured out an acceptable solution on my own.
My solution may not be the only one or the best one but it works.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.