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

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

Post by Andrey Prokosh » Tue, 15 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?
Thanks.

 
 
 

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

Post by Andrey Prokosh » Tue, 15 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?
: Thanks.
:  

There is a delay on our newsserver so I thought that the original message
was not posted. Sorry for the duplicate, please ignore this.

 
 
 

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

Post by thei.. » Tue, 15 Aug 1995 04:00:00



Quote:>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()
>{
>.....
>}
>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.

The memory DC is initialized with a 1x1 1bit Bitmap, this represents
the entire surface you are able to draw on, which isn't big enough for
the drawing you are doing. You will have to create a new bitmap, and
select it into your mDC.  I think the following code changes will fix
your problem.

Quote:>void CTestView::OnFileTest()
>{
>CDC mDC;    //memory DC

CBitmap myBmp, *oldBmp;
Quote:>    COLORREF color = RGB(0,128,0);
>    CDC * pDC = GetDC();   //Display DC
>    CPen Pen(PS_SOLID, 0, color);
>    BOOL DCcreated = mDC.CreateCompatibleDC(pDC);

        //Create a compatible bitmap large enough to do your drawing.
        myBmp.CreateCompatibleBitmap(pDC, 20, 20);

        // Select the bitmap into your DC, saving the default.                          
        oldBmp = mDC.SelectObject(&myBmp);

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

>>        mDC.SelectObject(&pBrush);
>>    mDC.SelectObject(&Pen);

        // Drawing the small square in memory: this will fill the entire
        // bitmap you have selected into mDC.
        mDC.Rectangle(0,0,20,20);

        // Blit the small square to the apporpriate place on the screen
        pDC->BitBlt(10,10, 20, 20, &mDC, 0, 0, SRCCOPY);

Quote:

>    ReleaseDC(pDC);

        // Deselect, and delete.
        mDC.SelectObject(oldBmp);
        myBmp.DeleteObject();
Quote:>}

 
 
 

1. MFC: 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?

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.

2. NEC printer

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

4. Slashed Zero?

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

6. Resetting trace info in ASP.NET

7. Is DC a memory dc ?

8. each CD - $45 - VSTUDIO97, MSoffice 97,WNT4, Corel 7, C++, Vbasic5 and million soft's

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