我的程序是在图表上显示位置(x,y)的一些点。当我使用鼠标拖动任何点时,它的位置将自动更改。更新后的位置是在此代码之后实现的(使用线程):
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;
}
同时:
void CChartLabel<PointType>::SetLabelText(const TChartString& strText)
{
m_strLabelText = strText;
m_pParentCtrl->RefreshCtrlAtw();
}
和
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();
}
在图表上拖动点时我会收到这些错误:调试断言失败(afxwin1.inl,第639行和第646行)
_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;
}
你能帮我解决这个问题吗?我试图找到一些方法来修复但不起作用。 :(
答案 0 :(得分:1)
我的回答只是猜测,但原因可能是在第二个线程中使用来自一个线程(创建者)的MFC对象。这是一个猜测,因为你没有告诉我们ASSERT说的是什么,以及你正在使用的VS版本。
问题:在MFC中创建一些对象时,句柄值保存在一个允许MFC仅使用句柄值查找对象的映射中。 每个线程存储此句柄映射。
此外,如果窗口对象存储与这些句柄映射关联的其他对象,则另一个线程的使用将失败。
所以答案可以在调用堆栈中找到。它告诉你谁使用这样的对象。导致问题的对象简单地由ASSERT识别。