|
-
June 4th, 2006, 12:42 AM
#1
drawing in the dialog
I am trying to draw something in a modeless dialog in some where other than OnPaint member function. I used a bitmap to save the drawing and show it in OnPaint. like this
void CMyDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
MemDC.TextOut(10, 10, "text 1");
CBitmap* pOldBmp = MemDC.SelectObject(&m_Bmp);
dc.BitBlt(0, 0, 100, 100, &MemDC, 0, 0, SRCCOPY);
MemDC.SelectObject(pOldBmp);
}
and did some drawing in another function
void CMyDialog: raw()
{
CClientDC dc(this);
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
CBitmap *pOldBmp = MemDC.SelectObject(&m_Bmp);
MemDC.TextOut(10, 30, "text 2");
MemDC.SelectObject(pOldBmp);
}
And after I create this modeless dialog, I ran Draw(). But only "text 1" was shown on the dialog, "text 2" was not. I know this method can be used in Doc/View without any problem, but why it didnot work in dialogs?
could you help me? thank you!
-
June 4th, 2006, 01:43 AM
#2
Re: drawing in the dialog
Well what is going on is after your dialog is Init OnPaint() is called and whenever OnPaint() is being called the painting on your dialog will be "1" cause this is what you drawing in OnPaint().
All drawing should be in OnPaint()!
Cheers
-
June 4th, 2006, 01:57 AM
#3
Re: drawing in the dialog
adding to golanshahar.... Even if you draw anything else it will be erased because of the code in OnPaint. OnPaint is called whenever the window or it's any area needs to be redrawn, like in case of Window is moved, certain other top level window was minimized and your window comes to top etc... so that makes a lot of times of OnPaint execution.
Regards,
Ramkrishna Pawar
-
June 4th, 2006, 12:19 PM
#4
Re: drawing in the dialog
But why I can do this similar thing without any problem in View? (using CClientDC in OnDraw instead of using CPaintDC in OnPaint)
What is the difference between CView and CDialog in terms of doing these kind of drawing job? thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|