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
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...
>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