|
-
July 15th, 2010, 01:53 AM
#1
Drawing in Dialog in VC++ MFC
I have drawn drawing on a dialog using CRect function with CClientDC. This drawing is set of 90 rectangles. I am updating the position of rectangles using the following code. The values of LeafA[i] value will be changes during the running time. automatically the rectangle position also should change. But updation is not happening. for that I am using InvalidateRect() function. Flickring is happening when I am using InvalidateRect() to update the rectangles position.
Please suggest if any thing is wrong or any other process to update or process for not flickering the region.
void CMLCTreatDlg::OnPaint()
{
CPaintDC dc(this);
DrawMLC();
}
void CMLCTreatDlg: rawMLC()
{
CPaintDC dc(this);
int lpos,spos;
int i;
HDC hdc;
CButton * but=(CButton*)GetDlgItem(IDC_STATIC_MLC);
but->GetWindowRect(rect);
CPen NewPen(PS_DASH,1,RGB(0,0,0));
CPen NewPen1(PS_SOLID,1,RGB(0,0,0));
CPen *OldPen;
CBrush WinBrush(RGB(236,233,216));
CBrush Setbrush(RGB(100,149,237));
CBrush Actbrush(RGB(150,0,90));
CBrush *OldBrush;//(RGB(216,233,236));
hdc = GetDC ()->m_hDC;
lpos=274,spos=157;
CClientDC dcline(this);
CClientDC actDC(this);
CClientDC setDC(this);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
/* HBITMAP hbmp=CreateCompatibleBitmap(dc.m_hDC,rectArea->right,rectArea->bottom);
HBITMAP hOld=(HBITMAP)memdc.SelectObject(hbmp);*/
dcline.SelectObject(NewPen);
actDC.SetBkMode(TRANSPARENT);
setDC.SetBkMode(TRANSPARENT);
setDC.SelectObject(Setbrush);
actDC.SelectObject(WinBrush);
GetClientRect(&rect);
int pos;
actDC.SetBkMode(TRANSPARENT);
actDC.SelectObject(Actbrush);
for(i=0;i<NOOFLEAVES;i++)
{
pos=(LEAFLENGTH/175)*LeafB[i];
rect=CRect(spos+pos,lpos,spos+LEAFLENGTH+pos,lpos+LEAFWIDTH);
setDC.Rectangle(rect);
t=(float)(LEAFLENGTH/175.0)*LeafA[i];
pos=(int)t;
if(((spos+2*LEAFLENGTH)+pos)<=847)
rect=CRect(spos+LEAFLENGTH+pos,lpos,(spos+2*LEAFLENGTH)+pos,lpos+LEAFWIDTH);
else
rect=CRect(spos+LEAFLENGTH+pos,lpos,847,lpos+LEAFWIDTH);
//RedrawWindow(rect,NULL,RDW_ERASE);
setDC.Rectangle(rect);
lpos+=LEAFWIDTH;
}
/*to draw X-Axis and Y axis*/
dcline.MoveTo(432,150);
dcline.LineTo(432,950);
dcline.MoveTo(25,550);
dcline.LineTo(835,550);
/*10x10 field*/
dcline.MoveTo(353,471);
dcline.LineTo(353,629);
dcline.MoveTo(511,471);
dcline.LineTo(511,629);
dcline.MoveTo(353,471);
dcline.LineTo(511,471);
dcline.MoveTo(353,629);
dcline.LineTo(511,629);
/*20x20 field*/
dcline.MoveTo(274,392);
dcline.LineTo(274,708);
dcline.MoveTo(590,392);
dcline.LineTo(590,708);
dcline.MoveTo(274,392);
dcline.LineTo(590,392);
dcline.MoveTo(274,708);
dcline.LineTo(590,708);
}
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
|