Click here to Skip to main content
15,896,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My program is to display some points with their positions(x,y) on a graph. When I use mouse to drag any point, its position will automatically changed. Updated position is implemented following this code(using thread):

C++
m_thread =AfxBeginThread((AFX_THREADPROC)MainThread,this)
UINT CAtwWnd::MainThread(LPVOID pParam)
{
CAtwWnd *pMainDlg = (CAtwWnd*)pParam;

static SChartXYPoint pPoint;
TCHAR strTemp[32]={0,};

   while(1)
   {
        pMainDlg->m_chart.EnableRefresh(false);
        pMainDlg->InitGraph1();

        wsprintf(strTemp, _T("[%d](%d,%d)"), (int)index,(int)xPoint,(int) yPoint);
        pBalloon[index]->SetLabelText(strTemp);
        pBalloon[index] = pMainDlg->m_pPointSeries->CreateBalloonLabel(index, strTemp);

        pBalloon[index]->SetVisisble(true);
        pMainDlg->m_pPointSeries->SetVisible(true);
        pMainDlg->m_chart.EnableRefresh(true);
        pMainDlg->SetAtwGraphStep(1);
    }
return 0;
}


Mean while:
C++
void CChartLabel<PointType>::SetLabelText(const TChartString& strText)  
{  
   m_strLabelText = strText; 
   m_pParentCtrl->RefreshCtrlAtw();
}


And:
C++
void CChartCtrl::RefreshCtrlAtw()
{
// Window is not created yet, so skip the refresh.
if (!GetSafeHwnd())
    return;
if (m_iEnableRefresh < 1)
{
    m_bPendingRefresh = true;
    return;
}

// Retrieve the client rect and initialize the
// plotting rect
CClientDC dc(this) ;  
CRect ClientRect;
GetClientRect(&ClientRect);
m_PlottingRect = ClientRect;        

// If the backgroundDC was not created yet, create it (it
// is used to avoid flickering).
if (!m_BackgroundDC.GetSafeHdc() )
{
    CBitmap memBitmap;
    m_BackgroundDC.CreateCompatibleDC(&dc) ;
    memBitmap.CreateCompatibleBitmap(&dc, ClientRect.Width(),ClientRect.Height()) ;
    m_BackgroundDC.SelectObject(&memBitmap) ;
}

// Draw the chart background, which is not part of
// the DrawChart function (to avoid a background when
// printing).
DrawBackground(&m_BackgroundDC, ClientRect);
ClientRect.DeflateRect(3,3);
DrawChart(&m_BackgroundDC,ClientRect);
for (int i=0; i<4 ;i++)
{
    if (m_pAxes[i])
        m_pAxes[i]->UpdateScrollBarPos();
}

Invalidate();
}



when dragging points on graph I gets these errors somtimes: Debug Assertion Failed ( afxwin1.inl, line 639, and 646)
C++
_AFXWIN_INLINE CSize CDC::GetTextExtent(LPCTSTR lpszString, int nCount) const
{
    ASSERT(m_hAttribDC != NULL);
    SIZE size;
    VERIFY(::GetTextExtentPoint32(m_hAttribDC, lpszString, nCount, &size));
    return size;
}
_AFXWIN_INLINE CSize CDC::GetTextExtent(const CString& str) const
{
    ASSERT(m_hAttribDC != NULL);
    SIZE size;
    VERIFY(::GetTextExtentPoint32(m_hAttribDC, str, (int)str.GetLength(), &size));
    return size;
}


Could you help me to fix this problem? I tried to find some ways to fix but doesn't work. :(
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900