void CMyHidDlg::DrawGrid(void)
{
CPen *OldPen;
double nWide,nHigh;
CPoint sPos(0,0),dPos(0,0);
CDC* pDC=GetDC();
m_pGridDC = new CDC();
m_pGridDC->CreateCompatibleDC(pDC);
CPen Pen(PS_SOLID,1,m_GridColor);
nWide=(double)(m_rect.right-m_rect.left)/m_uSensorNum;
nHigh=(double)(m_rect.bottom-m_rect.top)/m_uDriverNum;
m_rect.right=(double)nWide*m_uSensorNum+m_rect.left+2;//调整长宽
m_rect.bottom=(double)nHigh*m_uDriverNum+m_rect.top+2;
m_pBitMapMem=new CBitmap;
m_pBitMapMem->CreateCompatibleBitmap(pDC,m_rect.Width(),m_rect.Height());
m_pGridDC->SelectObject(m_pBitMapMem);
m_pGridDC->FillSolidRect(0,0,m_rect.Width(),m_rect.Height(),m_BackColor);
OldPen=m_pGridDC->SelectObject(&Pen);
sPos.y=0;
dPos.y=m_rect.Height();
for(int i=0;i<=m_uSensorNum;i++)
{
m_pGridDC->MoveTo(sPos);
m_pGridDC->LineTo(dPos);
dPos.x+=nWide;
sPos.x+=nWide;
}
sPos.x=0;
sPos.y=0;
dPos.x=m_rect.Width();
dPos.y=0;
for(int i=0;i<=m_uDriverNum;i++)
{
m_pGridDC->MoveTo(sPos);
m_pGridDC->LineTo(dPos);
dPos.y+=nHigh;
sPos.y+=nHigh;
}
m_pGridDC->SelectObject(OldPen);
ReleaseDC(pDC);
delete m_pBitMapMem;
}
/************************************************************************/
/*消息响应函数,响应消息函数,进行重绘窗口用
时间:2012年3月23日
DrawView()函数主要是实现在格子中显示数组中的数据
*/
/************************************************************************/
LRESULT CMyHidDlg::DrawView(WPARAM wParam, LPARAM lParam)
{
int x = m_rect.left, y = m_rect.top;
CDC DataDC;
CDC * pDC=GetDC();
DataDC.CreateCompatibleDC(pDC);
CBitmap BmpMem;
BmpMem.CreateCompatibleBitmap( pDC,m_rect.Width(), m_rect.Height() );
DataDC.SelectObject(&BmpMem);
DataDC.FillSolidRect(m_rect,m_pGridDC->GetBkColor());
DataDC.BitBlt(0,0,m_rect.Width(),m_rect.Height(),m_pGridDC,0,0,SRCCOPY); //将网格DC拷入整个视图DC
CFont *OldFont;
OldFont=DataDC.SelectObject(&m_DataFont);
int nWide = (double)m_rect.Width()/m_uSensorNum;
int nHigh = (double)m_rect.Height()/m_uDriverNum;
CString ts;
int nIndex = 0;
m_CriticalSection.Lock();
//
if (m_eStatus==E_RUNNING)
{
for( int nY = 0, y = nHigh/2 - 16 + m_rect.top; nY < m_uDriverNum; nY++ )
{
for( int nX = 0, x = 4 + m_rect.left; nX < m_uSensorNum; nX++ )
{
ts.Format( _T("%d"), g_DataBuf[nIndex++] );//g_diff_data[nIndex++]
DataDC.TextOut( x, y, ts );
x += nWide;
}
y += nHigh;
}
}
//显示状态切换到差值状态
if (m_eStatus==E_DIFF)
{
for(int nY = 0, y = 0; nY < m_uDriverNum; nY++)
{
for(int nX = 0, x = 0; nX < m_uSensorNum; nX++)
{
/改变字体颜色///
//if (g_DataBuf[nIndex]<0)
//{
// DataDC.SetTextColor(RGB(0,100-g_DataBuf[nIndex],0));
//}
//else if (g_DataBuf[nIndex]>64)
//{
// DataDC.SetTextColor(RGB(255,1000-g_DataBuf[nIndex],1000-g_DataBuf[nIndex]));
// if (g_DataBuf[nIndex]>255)
// {
// DataDC.SetTextColor(RGB(255,0,0));
// }
//}
//else
//{
// DataDC.SetTextColor(RGB(0,0,0));
//}
/************************************************************************/
/* */
/************************************************************************/
CBrush brush( RGB(255,255-g_DataBuf[nIndex],255-g_DataBuf[nIndex]) );
if( g_DataBuf[nIndex] > 30 )
{
DataDC.FillRect( CRect(x, y, x + nWide, y + nHigh ), &brush);
}
DataDC.SetBkMode( TRANSPARENT );
//显示差值数据
ts.Format( _T("%d"), g_DataBuf[nIndex++] );
DataDC.TextOut( x, y, ts );
x += nWide;
}
y+=nHigh;
}
}
m_CriticalSection.Unlock();
pDC->BitBlt( m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), &DataDC, 0, 0, SRCCOPY );
DataDC.SelectObject(OldFont);
DataDC.DeleteDC();
BmpMem.DeleteObject();
ReleaseDC(pDC);
return 0;
}
/************************************************************************/
/*坐标画圆函数
*/
/************************************************************************/
void CMyHidDlg::DrawLocation()
{
CDC DataDc;
CDC * pDC=GetDC();
DataDc.CreateCompatibleDC(pDC);
CBitmap BmpMem;
BmpMem.CreateCompatibleBitmap( pDC,m_rect.Width(), m_rect.Height() );
DataDc.SelectObject(&BmpMem);
DataDc.FillSolidRect(m_rect,m_pGridDC->GetBkColor());
m_CriticalSection.Lock();
CPoint Picture[5];
for( int i = 0; i < 5; i++ )
{
Picture[i].x = Touch[i].y * m_rect.Width()/800 + m_startPoint.x;
Picture[i].y = Touch[i].x * m_rect.Height()/480 + m_startPoint.y;
if( Picture[i].x == 0 )
{
Picture[i].x -= 1000;
Picture[i].y -= 1000;
}
}
for( int i = 0; i < 5; i++ )
{
if( TrickId[i] == (i + 1) )
{
DataDc.SelectObject( pen[i] );
DataDc.SelectObject( brush[i] );
if( DataDc.Ellipse( Picture[i].x, Picture[i].y, Picture[i].x+25, Picture[i].y + 25 ))
{
DataDc.MoveTo( m_startPoint.x, Picture[i].y + 12 );
DataDc.LineTo( m_startPoint.x + m_rect.Width(), Picture[i].y + 12 );
DataDc.MoveTo( Picture[i].x + 12 ,m_startPoint.y );
DataDc.LineTo( Picture[i].x + 12, m_startPoint.y + m_rect.Height() );
}
}
}
m_CriticalSection.Unlock();
pDC->BitBlt( m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), &DataDc, 0, 0, SRCCOPY );
ReleaseDC(pDC);
DataDc.DeleteDC();
}
void CMyHidDlg::OnShowxydata()
{
// TODO: 在此添加命令处理程序代码
if(hHidShowXYThread != NULL)
{
static int ShowxyFlag = 1;
if(ShowxyFlag)
{
SuspendThread( hHidShowXYThread );
ShowxyFlag = 0;
}
else
{
ResumeThread( hHidShowXYThread );
ShowxyFlag = 1;
}
}
else
{
hHidShowXYThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)CHid::ThreadFuncShowxyData, m_pHid, 0, NULL );
}
}
void CMyHidDlg::OnSourcedata()
{
// TODO: 在此添加命令处理程序代码
//m_eStatus = E_DIFF; //此时将状态标识置为差值状态
m_eStatus = E_RUNNING;
if( hHidSourceDataThread != NULL )
{
static int SourceDataFlag = 1;
if( SourceDataFlag )
{
SuspendThread( hHidSourceDataThread );
SourceDataFlag = 0;
}
else
{
ResumeThread( hHidSourceDataThread );
SourceDataFlag = 1;
}
}
else
{
hHidSourceDataThread = CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE )CHid::ThreadFuncSourceData, m_pHid, 0, NULL );
}
}
void CMyHidDlg::OnDiffdata()
{
// TODO: 在此添加命令处理程序代码
// TODO: 在此添加控件通知处理程序代码
m_eStatus = E_DIFF;
if(hHidDiffDataThread != NULL)
{
static int DiffDataFlag = 1;
if( DiffDataFlag )
{
SuspendThread( hHidDiffDataThread );
DiffDataFlag = 0;
}
else
{
ResumeThread( hHidDiffDataThread );
DiffDataFlag = 1;
}
}
else
{
hHidDiffDataThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)CHid::ThreadFuncDiffData, m_pHid, 0, NULL );
}
}
void CMyHidDlg::OnPutconfig()
{
// TODO: 在此添加命令处理程序代码
// TODO: 在此添加命令处理程序代码
CFileDialog fileDlg( TRUE );
fileDlg.m_ofn.lpstrTitle = _T("导入配置文件");
fileDlg.m_ofn.lpstrFilter = _T("Text Files(*.cfg)\0*.cfg\0A11 Files(*.*)\0*.*\0\0");
if( IDOK == fileDlg.DoModal() )
{
CFile file( fileDlg.GetFileName(), CFile::modeRead );
char *pBuf,ConfigData[106] = {0}, ConfigDataBuffer[300] = {0};
DWORD dwFileLen;
dwFileLen = file.GetLength();
pBuf = new char[dwFileLen + 1];
pBuf[dwFileLen] = 0;
file.Read( pBuf, dwFileLen );
file.Close();
MessageBox( pBuf );
/*
pBuf指向配置信息的首地址,然后我只需一个个截取下来将每一个数据存入一个数组中就可
*/
for( DWORD i = 0, j = 0; i < dwFileLen + 1; i += 5,j += 2)
{
if( pBuf[i] == '0' )
{
if( pBuf[i+1] == 'x' )
{
if( (pBuf[i+2] >= '0') && pBuf[i+2] <= '9' )
{
ConfigDataBuffer[j] = pBuf[i+2] - '0';
}
else if( (pBuf[i+2] >= 'A') && (pBuf[i+2] <= 'F') )
{
ConfigDataBuffer[j] = pBuf[i+2] - 65 + 10;
}
if((pBuf[i+3] >= '0') && pBuf[i+3] <= '9')
{
ConfigDataBuffer[j+1] = pBuf[i+3] - '0';
}
else if((pBuf[i+3] >= 'A') && (pBuf[i+3] <= 'F') )
{
ConfigDataBuffer[j+1] = pBuf[i+3] - 65 + 10;
}
}
}
}
for(int i = 0, j = 0; i < 212; i += 2, j++ )
{
ConfigData[j] = ( ConfigDataBuffer[i] << 4 ) + ConfigDataBuffer[i+1];
}
unsigned char WHConfigDataA[64] = {0};
unsigned char WHConfigDataB[64] = {0};
for( int i = 0; i < 53; i++ )
{
WHConfigDataA[i] = ConfigData[i];
WHConfigDataB[i] = ConfigData[i + 53];
}
WHConfigDataA[63] = 0xaa;
WHConfigDataB[63] = 0xaa;
m_pHid->WriteHid(WHConfigDataA, 64);//先发送第一帧数据
//unsigned char RHConfigFlag = 0;
// m_pHid->ReadHid( &RHConfigFlag, 1 );//读取标志看是否下位机有回应
Sleep(10);
m_pHid->WriteHid(WHConfigDataB, 64);//发送第二帧数据
//CString str=pBuf,temp;
//int index;
//while((index=str.Find(','))!=-1)
//{
// temp = str.Left(index);
// m_charlist.push_back(temp);
// str=str.Mid(index+1,str.GetLength()-index-1);
// //AfxMessageBox(temp);
//}
//m_charlist.push_back(str);
//
MessageBox( pBuf );
到此已经将文本文件中数据读取到pBuf指向的内存中,
只需要把这些数据通过USB发送到STM32然后再通过IIC发送到GT818
m_pHid->WriteHid(pBuf, 64);
//int i = 0;
//for(std::vector<CString>::iterator iter=m_charlist.begin();iter!=m_charlist.end();iter++,i++)
//{
// buffer[i] = atoi((*iter));
//}
//buffer[i] = '\0';
}
}
void CMyHidDlg::draw()
{
CDC *dc = this->GetWindowDC();
LOGBRUSH logBrush;
CBrush brush;
logBrush.lbStyle = BS_SOLID;
logBrush.lbColor = RGB(220,230,255);
logBrush.lbHatch = HS_CROSS;
brush.CreateBrushIndirect(&logBrush);
CBrush* pOldBrush = (CBrush*)dc->SelectObject(&brush);
GetClientRect(&m_drawRect);
将所需矩形对象的左上角和右下角都定义好
m_drawRect.top += 50;
m_drawRect.left += 8;
m_drawRect.bottom += 60;
m_drawRect.right += 10;
dc->FillRect( m_drawRect, &brush );
dc->SelectObject(pOldBrush);
dc->DeleteDC();
}