MFC: Copying images from memory DC to display DC?

MFC: Copying images from memory DC to display DC?

Post by Andrey Prokosh » Sun, 13 Aug 1995 04:00:00


I am having trouble copying an image from a temporary memory DC to Display
DC.  Here's how the piece of my program looks:

void CTestView::OnFileTest()
{
CDC mDC;        //memory DC
        COLORREF color = RGB(0,128,0);
        CDC * pDC = GetDC();   //Display DC
    CPen Pen(PS_SOLID, 0, color);
        BOOL DCcreated = mDC.CreateCompatibleDC(pDC);

        CBrush pBrush;
        LOGBRUSH lbBrush;
        lbBrush.lbStyle = BS_SOLID;
        lbBrush.lbColor = color;
        lbBrush.lbHatch = HS_BDIAGONAL;
        pBrush.CreateBrushIndirect (&lbBrush);

        mDC.SelectObject(&pBrush);
    mDC.SelectObject(&Pen);
        mDC.Rectangle(10,10,30,30);

        pDC->BitBlt(10,10, 20, 20, &mDC, 10, 10, SRCCOPY);

        ReleaseDC(pDC);

Quote:}

If I use SelectObject and Rectangle functions directly on pDC, everything
works fine, but when I copy the image from mDC to pDC, it does not seem to
do anything.  When I use BLACKNESS as the last parameter in BitBlt, the black
rectangle appears on the screen with the same coordinates as in the
mDC.Rectangle function.
Could someone give me a clue what I am doing wrong?

The other small problem that I am having is that if I declare mDC to be a
pointer like pDC then windows crashed after CreateCompatibleDC function call.
Thanks.

 
 
 

MFC: Copying images from memory DC to display DC?

Post by Bruce J. Veaz » Mon, 14 Aug 1995 04:00:00



 >
 >
 >I am having trouble copying an image from a temporary memory DC to Display
 >DC.  Here's how the piece of my program looks:
 >
 >void CTestView::OnFileTest()
 >{
 >CDC mDC;        //memory DC
 >        COLORREF color = RGB(0,128,0);
 >        CDC * pDC = GetDC();   //Display DC
 >    CPen Pen(PS_SOLID, 0, color);
 >        BOOL DCcreated = mDC.CreateCompatibleDC(pDC);
 >    
 >        CBrush pBrush;
 >        LOGBRUSH lbBrush;
 >        lbBrush.lbStyle = BS_SOLID;
 >        lbBrush.lbColor = color;
 >        lbBrush.lbHatch = HS_BDIAGONAL;
 >        pBrush.CreateBrushIndirect (&lbBrush);
 >  
 >        mDC.SelectObject(&pBrush);
 >    mDC.SelectObject(&Pen);    
 >        mDC.Rectangle(10,10,30,30);
 >
 >        pDC->BitBlt(10,10, 20, 20, &mDC, 10, 10, SRCCOPY);
 >
 >        ReleaseDC(pDC);
 >}
 >
 >If I use SelectObject and Rectangle functions directly on pDC, everything
 >works fine, but when I copy the image from mDC to pDC, it does not seem to
 >do anything.  When I use BLACKNESS as the last parameter in BitBlt, the black
 >rectangle appears on the screen with the same coordinates as in the
 >mDC.Rectangle function.
 >Could someone give me a clue what I am doing wrong?
 >
 >The other small problem that I am having is that if I declare mDC to be a
 >pointer like pDC then windows crashed after CreateCompatibleDC function call.
 >Thanks.

Memory DC's are created with a 1x1 display area. Create a bitmap of the
required size and select it into mDC before you do any drawing.



 
 
 

MFC: Copying images from memory DC to display DC?

Post by Davor Slamn » Sat, 19 Aug 1995 04:00:00



> I am having trouble copying an image from a temporary memory DC to Display
> DC.  Here's how the piece of my program looks:

> void CTestView::OnFileTest()
> {
> CDC mDC;   //memory DC
>    COLORREF color = RGB(0,128,0);
>    CDC * pDC = GetDC();   //Display DC
>     CPen Pen(PS_SOLID, 0, color);
>    BOOL DCcreated = mDC.CreateCompatibleDC(pDC);

>    CBrush pBrush;
>            LOGBRUSH lbBrush;
>            lbBrush.lbStyle = BS_SOLID;
>    lbBrush.lbColor = color;
>            lbBrush.lbHatch = HS_BDIAGONAL;
>            pBrush.CreateBrushIndirect (&lbBrush);

>    mDC.SelectObject(&pBrush);
>     mDC.SelectObject(&Pen);    
>    mDC.Rectangle(10,10,30,30);

>    pDC->BitBlt(10,10, 20, 20, &mDC, 10, 10, SRCCOPY);

>    ReleaseDC(pDC);
> }

> If I use SelectObject and Rectangle functions directly on pDC, everything
> works fine, but when I copy the image from mDC to pDC, it does not seem to
> do anything.  When I use BLACKNESS as the last parameter in BitBlt, the black
> rectangle appears on the screen with the same coordinates as in the
> mDC.Rectangle function.
> Could someone give me a clue what I am doing wrong?

    As the VC++ Class Library Reference Help says:

    "CDC::CreateCompatibleDC(CDC *pDC)
    ... GDI output functions can be used with a memory device context only
    if a bitmap has been created and selected into that context."

    Use Cbitmap::CreateCompatibleBitmap()

Slama

 
 
 

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

I am having trouble copying an image from a temporary memory DC to Display
DC.  Here's how the piece of my program looks:

void CTestView::OnFileTest()
{
CDC mDC;        //memory DC
        COLORREF color = RGB(0,128,0);
        CDC * pDC = GetDC();   //Display DC
    CPen Pen(PS_SOLID, 0, color);
        BOOL DCcreated = mDC.CreateCompatibleDC(pDC);

        CBrush pBrush;
        LOGBRUSH lbBrush;
        lbBrush.lbStyle = BS_SOLID;
        lbBrush.lbColor = color;
        lbBrush.lbHatch = HS_BDIAGONAL;
        pBrush.CreateBrushIndirect (&lbBrush);

        mDC.SelectObject(&pBrush);
    mDC.SelectObject(&Pen);
        mDC.Rectangle(10,10,30,30);

        pDC->BitBlt(10,10, 20, 20, &mDC, 10, 10, SRCCOPY);

        ReleaseDC(pDC);

If I use SelectObject and Rectangle functions directly on pDC, everything
works fine, but when I copy the image from mDC to pDC, it does not seem to
do anything.  When I use BLACKNESS as the last parameter in BitBlt, the black
rectangle appears on the screen with the same coordinates as in the
mDC.Rectangle function.
Could someone give me a clue what I am doing wrong?
Thanks.

2. OS/2 Web Browser

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

4. How do I find my Xbox name

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

6. New contacts !! Recherche contacts !!

7. Is DC a memory dc ?

8. Steganography

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

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

11. DC copy in memory block

12. Copying a bitmap into a memory DC