Assertion error in OnDraw
-
I have drawn graph in OnDraw function,i got the graph..but when i minimized the window and getting back the position..it shows assertion error..What is tht? How cud i get rid of tht?
-
I have drawn graph in OnDraw function,i got the graph..but when i minimized the window and getting back the position..it shows assertion error..What is tht? How cud i get rid of tht?
-
Perhaps you can provide us with the code of the OnDraw function? Er zit een korstje op mijn aars.
void CLineView::OnDraw(CDC* pDC) { //CLineDoc* pDoc = GetDocument(); //ASSERT_VALID(pDoc); // TODO: add draw code for native data here GetClientRect(&rect); pDC->FillRect((LPCRECT)rect,&CBrush(RGB(0,0,0))); CPoint PtLine[] = { CPoint( 100, 20), CPoint(100, 420), CPoint(700, 420) }; pDC->SelectStockObject(WHITE_PEN); pDC->SetBkColor(RGB(0,0,0)); pDC->SetTextColor(RGB(19,133,255)); pDC->MoveTo(PtLine[0]); pDC->LineTo(PtLine[1]); pDC->LineTo(PtLine[2]); int x1=160,y1=420,x2=100,y2=60; for(int i = 0;i<9;i++) { pDC->MoveTo(x1,y1); pDC->LineTo(x1,y1+5); x1=x1+60; pDC->MoveTo(x2,y2); pDC->LineTo(x2-5,y2); y2=y2+40; } gpen1.CreatePen(PS_SOLID,2,RGB(255,0,0)); pDC->SelectObject(&gpen1); for(int j= 0;j<8;j++) { pDC->SetPixel(a[j]+100,420-b[j],RGB(0,255,0)); pDC->MoveTo(a[j]+100,420-b[j]); pDC->LineTo(a[j+1]+100,420-b[j+1]); } pDC->TextOut(650,450,"X-AXIS"); pDC->TextOut(45,25,"Y-AXIS"); }
-
void CLineView::OnDraw(CDC* pDC) { //CLineDoc* pDoc = GetDocument(); //ASSERT_VALID(pDoc); // TODO: add draw code for native data here GetClientRect(&rect); pDC->FillRect((LPCRECT)rect,&CBrush(RGB(0,0,0))); CPoint PtLine[] = { CPoint( 100, 20), CPoint(100, 420), CPoint(700, 420) }; pDC->SelectStockObject(WHITE_PEN); pDC->SetBkColor(RGB(0,0,0)); pDC->SetTextColor(RGB(19,133,255)); pDC->MoveTo(PtLine[0]); pDC->LineTo(PtLine[1]); pDC->LineTo(PtLine[2]); int x1=160,y1=420,x2=100,y2=60; for(int i = 0;i<9;i++) { pDC->MoveTo(x1,y1); pDC->LineTo(x1,y1+5); x1=x1+60; pDC->MoveTo(x2,y2); pDC->LineTo(x2-5,y2); y2=y2+40; } gpen1.CreatePen(PS_SOLID,2,RGB(255,0,0)); pDC->SelectObject(&gpen1); for(int j= 0;j<8;j++) { pDC->SetPixel(a[j]+100,420-b[j],RGB(0,255,0)); pDC->MoveTo(a[j]+100,420-b[j]); pDC->LineTo(a[j+1]+100,420-b[j+1]); } pDC->TextOut(650,450,"X-AXIS"); pDC->TextOut(45,25,"Y-AXIS"); }
Anu_Bala wrote:
gpen1.CreatePen(PS_SOLID,2,RGB(255,0,0)); pDC->SelectObject(&gpen1);
First when ever you use SelectObject don't forget to Select back the old object e.g CPen NewPen; CPen* pOldPen; NewPen.CreatePen((PS_SOLID,2,RGB(255,0,0)); pOldPen = pDC->SelectObject(&NewPen); : :Draw the rest.... : // After Drawing pDC->SelectObject(pOldPen);
Anu_Bala wrote:
for(int j= 0;j<8;j++) { pDC->SetPixel(a[j]+100,420-b[j],RGB(0,255,0)); pDC->MoveTo(a[j]+100,420-b[j]); pDC->LineTo(a[j+1]+100,420-b[j+1]); }
Second .. I think you might have problem in data of array a[] and b[] which may cause assertion. Where they are changing plz check. Regards Anil