Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to copy one CDC to another CDC

302 views
Skip to first unread message

Li Peng

unread,
Jul 10, 1999, 3:00:00 AM7/10/99
to
In the Test2View.h,I define:
CDC *m_dc;

In the Test2View.cpp

CTest2View::CTest2View()
{
m_dc=new CDC;
}

CTest2View::~CTest2View()
{
delete m_dc;
}

void CTest2View::OnInitialUpdate()
{
CView::OnInitialUpdate();
CClientDC dc(this);
m_dc->CreateCompatibleDC(&dc);

}

void CTest2View::OnDraw(CDC* pDC)
{
m_dc->SelectStockObject(GRAY_BRUSH);
m_dc->Rectangle(CRect(0,0,100,100));
pDC->BitBlt(0,0,100,100,m_dc,0,0,SRCCOPY);
}

To my surprise,the client area display nothing,I want draw in "m_dc", and
copy it to the "pDC",why I can't,could you tell me,thanks in advance.
email:lp...@263.net


Kurt Krueckeberg

unread,
Jul 11, 1999, 3:00:00 AM7/11/99
to
The device context does not persist between messages; therefore, the CDC *
in OnInititalUpdate() is not the same as the CDC * in OnDraw().

If you want the device context to persist, you can use
CDC::SaveDC/CDC::RestoreDC; or
register a window class with class style of CS_CLASSDC. All windows created
with this style will share the same dc.

Li Peng <lp...@263.net> wrote in message news:O5gaL1qy#GA.304@cppssbbsa04...

Doug Harrison

unread,
Jul 11, 1999, 3:00:00 AM7/11/99
to
Li Peng wrote:

>In the Test2View.h,I define:
> CDC *m_dc;
>
>
>
>In the Test2View.cpp
>
>CTest2View::CTest2View()
>{
> m_dc=new CDC;
>}
>
>CTest2View::~CTest2View()
>{
> delete m_dc;
>}
>
>void CTest2View::OnInitialUpdate()
>{
> CView::OnInitialUpdate();
> CClientDC dc(this);
> m_dc->CreateCompatibleDC(&dc);
>
>}
>
>void CTest2View::OnDraw(CDC* pDC)
>{
> m_dc->SelectStockObject(GRAY_BRUSH);
> m_dc->Rectangle(CRect(0,0,100,100));
> pDC->BitBlt(0,0,100,100,m_dc,0,0,SRCCOPY);
>}
>
>To my surprise,the client area display nothing,I want draw in "m_dc", and
>copy it to the "pDC",why I can't,could you tell me,thanks in advance.

You forgot to create a bitmap and select it into your memory DC. Look up
CreateCompatibleDC in the Platform SDK docs in MSDN.

--
Doug Harrison
dHar...@worldnet.att.net
Visual C++ MVP


0 new messages