How to copy a window's DC to another DC?

How to copy a window's DC to another DC?

Post by Niraj Sha » Fri, 31 Jul 1998 04:00:00



Hello all,

How do you take a window's DC and copy it (and it's contents) to another
compatible DC?  I want to take a window and take it's UI contents and put it
in another compatible DC and then blt it out somewhere else on the screen.

The following is my guess on how to do this, but it doesn't work when I
bltblt the newDC out.

   // Get the current window position
   CRect rcStart;
   pWnd->GetWindowRect(rcStart);

   //get dc of window (not client, but window)
  CDC* pDC = pWnd->GetDCEx(NULL, DCX_WINDOW|DCX_CACHE);

  //create a compatible DC and cache the windows contents
 CDC newDC;
  newDC.CreateCompatibleDC(pDC);
  newDC.BitBlt(0,0,rcStart.Width(),rcStart.Height(),pDC,0,0,SRCCOPY);

Thanks in advance.

Niraj Shah
Active Voice Corporation

 
 
 

How to copy a window's DC to another DC?

Post by Dirk Djug » Sat, 01 Aug 1998 04:00:00



>Hello all,

>How do you take a window's DC and copy it (and it's contents) to another
>compatible DC?  I want to take a window and take it's UI contents and put
it
>in another compatible DC and then blt it out somewhere else on the screen.

You must select a bitmap before you can blit to a DC. See below.

Quote:>The following is my guess on how to do this, but it doesn't work when I
>bltblt the newDC out.

>   // Get the current window position
>   CRect rcStart;
>   pWnd->GetWindowRect(rcStart);

>   //get dc of window (not client, but window)
>  CDC* pDC = pWnd->GetDCEx(NULL, DCX_WINDOW|DCX_CACHE);

>  //create a compatible DC and cache the windows contents
> CDC newDC;
>  newDC.CreateCompatibleDC(pDC);

CBitmap Bmp;
Bmp.CreateCompatibleBitmap(pDC,rcStart.Width(),rcStart.Height());
CBitmap* pOldBmp=newDC.SelectObject(&Bmp);

Quote:>  newDC.BitBlt(0,0,rcStart.Width(),rcStart.Height(),pDC,0,0,SRCCOPY);

When you're done with newDC do this:

newDC.SelectObject(pOldBmp);

If you need it only later you must keep Bmp. You can create a "new newDC"
later, but the pixels are in Bmp.

cU
--

   http://djuga.home.ml.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Retriever 2.0 is out: http://retriever.home.ml.org

Shareware image viewer, thumbnailer & database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 
 
 

1. Printer DC's and Enhanced Metafile DC's and Memory DC's

I am having problems selecting a bitmap created via
CreateCompatibleBitmap() into a memory DC created via CreateCompatibleDC()
whose "hardware" DC is actually a metafile which was created from a printer
DC.  Whew!  

I can find no limitation in the documentation for doing this but
SelectObject() returns NULL when I try to select the compatible bitmap into
the compatible DC of the compatible EMF DC of the printer DC.   Have I
missed something in the docs?  Is this a bug?  If it is a bug, what's the
work-around?

Any help would be appreciated.

E.C.
--
Eric Chamberlain                eric dot chamberlain at graphicode dot com
GraphiCode, Inc.                Senior Software Engineer
6608 216th St. SW               Phone: (425) 672-1980
Suite 100                       Fax:   (425) 672-2705
Mountlake Terrace, WA 98043
USA                             Web Site: http://www.graphicode.com
**********************************************************************
*  Pursuant to US Code, Title 47, Chapter 5, Subchapter II, Sec. 227,
*  any and all nonsolicited commercial E-mail sent to this address is
*  subject to a download and archival fee in the amount of $500 US.
*  E-mailing denotes acceptance of these terms.
**********************************************************************

2. : Spelling checker checks not after /begin{document}

3. Are Memory DC's faster than Window DC's

4. how to read this data file

5. MFC: Help needed copying images from memory DC to display DC

6. FAQ: Team OS/2 Frequently Asked Questions

7. MFC: Copying images from memory DC to display DC?

8. DNS software crashes on startup help?

9. PrintPreview - Problem inTrying to copy Printpreview' DC's image

10. Is DC a memory dc ?

11. Call GetTextExtentPoint32 on the screen DC or the static control DC to calculate static text width???

12. BitBlt from device DC to compatible DC does nothing (win2000)?

13. Why replace original DC objects after changing the DC ?