⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digitalpoweranalystview.cpp

📁 串行通讯程序,为电池分析仪与电脑通讯软件,效果不错.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	char tmpChar[6];
		m_DCodeDlg.m_nStation=2;
	m_ComPort.WriteToDevice((char ) 0x8C,m_DCodeDlg.m_nStation,0,"",0);
	Sleep(1000);

	m_DCodeDlg.m_sCaptionTiltle=_T("分析配置_Station");
	m_DCodeDlg.m_sCaptionTiltle+=itoa(m_DCodeDlg.m_nStation,tmpChar,10);
	m_DCodeDlg.IsDlgShow=TRUE;
	OnStopTimer();//m_ComPort.WriteToDevice((char ) 0x83,01,07,"",0);
 	m_ComPort.WriteToDevice((char ) 0x88,m_DCodeDlg.m_nStation,0,"",0);
	m_DCodeDlg.DoModal();//	m_AnalysisSetupDlg
  	OnStartTimer(); 
}

void CDigitalPowerAnalystView::OnSTATICStation3() 
{
	// TODO: Add your control notification handler code here
	CString tmpStr;
	char tmpChar[6];
		m_DCodeDlg.m_nStation=3;
	m_ComPort.WriteToDevice((char ) 0x8C,m_DCodeDlg.m_nStation,0,"",0);
	Sleep(1000);

	m_DCodeDlg.m_sCaptionTiltle=_T("分析配置_Station");
	m_DCodeDlg.m_sCaptionTiltle+=itoa(m_DCodeDlg.m_nStation,tmpChar,10);
	m_DCodeDlg.IsDlgShow=TRUE;
	OnStopTimer();//m_ComPort.WriteToDevice((char ) 0x83,01,07,"",0);
 	m_ComPort.WriteToDevice((char ) 0x88,m_DCodeDlg.m_nStation,0,"",0);
	m_DCodeDlg.DoModal();//	m_AnalysisSetupDlg
  	OnStartTimer(); 
}

void CDigitalPowerAnalystView::OnSTATICStation4() 
{
	// TODO: Add your control notification handler code here
	CString tmpStr;
	char tmpChar[6];
		m_DCodeDlg.m_nStation=4;
	m_ComPort.WriteToDevice((char ) 0x8C,m_DCodeDlg.m_nStation,0,"",0);
  	Sleep(1000);

	m_DCodeDlg.m_sCaptionTiltle=_T("分析配置_Station");
	m_DCodeDlg.m_sCaptionTiltle+=itoa(m_DCodeDlg.m_nStation,tmpChar,10);
	m_DCodeDlg.IsDlgShow=TRUE;
	OnStopTimer();//m_ComPort.WriteToDevice((char ) 0x83,01,07,"",0);
 	m_ComPort.WriteToDevice((char ) 0x88,m_DCodeDlg.m_nStation,0,"",0);
	m_DCodeDlg.DoModal();//	m_AnalysisSetupDlg
  	OnStartTimer(); 
}

void CDigitalPowerAnalystView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CRecordView::OnTimer(nIDEvent);

	GetDataTimes();	
	//OnAdd();
 
 
}



void CDigitalPowerAnalystView::OnStartTimer() 
{
   m_nTimer = SetTimer(1, 1500, 0);
}



void CDigitalPowerAnalystView::OnStopTimer() 
{
   KillTimer(m_nTimer);   
}

/*
// get the default printer
CPrintDialog dlg(FALSE);
dlg.GetDefaults();

// is a default printer set up?
HDC hdcPrinter = dlg.GetPrinterDC();
if (hdcPrinter == NULL)
{
   MessageBox(_T("Buy a printer!"));
}
else
{
   // create a CDC and attach it to the default printer
   CDC dcPrinter;
   dcPrinter.Attach(hdcPrinter);

   // call StartDoc() to begin printing
   DOCINFO docinfo;
   memset(&docinfo, 0, sizeof(docinfo));
   docinfo.cbSize = sizeof(docinfo);
   docinfo.lpszDocName = _T("CDC::StartDoc() Code Fragment");

   // if it fails, complain and exit gracefully
   if (dcPrinter.StartDoc(&docinfo) < 0)
   {
      MessageBox(_T("Printer wouldn't initalize"));
   }
   else
   {
      // start a page
      if (dcPrinter.StartPage() < 0)
      {
         MessageBox(_T("Could not start page"));
         dcPrinter.AbortDoc();
      }
      else
      {
         // actually do some printing
         CGdiObject* pOldFont = dcPrinter.SelectStockObject(SYSTEM_FONT);

         dcPrinter.TextOut(50, 50, _T("Hello World!"), 12);

         dcPrinter.EndPage();
         dcPrinter.EndDoc();
         dcPrinter.SelectObject(pOldFont);
      }
   }
}
*/
void CDigitalPowerAnalystView::WriteGrid(CStatic * m_Static)
{
	   	CBrush m_Brush;
	CPen pen;
	pen.CreatePen(PS_DOT      ,1,RGB(155,155,155));//PS_SOLID

	m_Brush.CreateSolidBrush(RGB(255, 0, 0));
	CClientDC* pDC=new CClientDC(m_Static);//&m_StaticPicture);&m_StaticDataDisp
	CPen * oldPen=(CPen*)pDC->SelectObject(&pen);

	CString tmpStr;
    CRect rect;
	m_Static->GetClientRect(&rect);
	int nBottom=rect.bottom;
	int nTop=rect.top;
	int nLeft=rect.left ;
	int nRight=rect.right ;
     m_nLineWindth=nRight;
     m_nLineHeight=nLeft;

	for(int i=0;i<9;i++)
	{
	pDC->MoveTo(nLeft+(nRight-nLeft)*i/8,nTop);
	pDC->LineTo(nLeft+(nRight-nLeft)*i/8,nBottom);//nTop+(nBottom-nTop)*i/8
	pDC->MoveTo(nLeft,nTop+(nBottom-nTop)*i/8);
	pDC->LineTo(nRight,nTop+(nBottom-nTop)*i/8);


	//tmpStr.Format("%5d",rect.bottom);
	//pDC->TextOut( pt[i].x, pt[i].y,tmpStr);
	}
 	CBrush * oldBrush=(CBrush*) pDC->SelectObject(&m_Brush);
	 //FloodFill(*pDC,nLeft+(nRight-nLeft)*3/16,nTop+(nBottom-nTop)*3/16,0);
	 pDC->SelectObject(oldPen);
	 pDC->SelectObject(oldBrush);
	delete[] pDC;
}

void CDigitalPowerAnalystView::InsertVolumn(CListCtrl *pListCtrl, EVENT_INFO *pIn)
{
	LVITEM	lvIt;
	char tmpChar[256];
	int iIcon,nItem=1;
	CString fileName=pIn->sBaterryName;
	iIcon=pIn->nStation;
	lvIt.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
	lvIt.iImage=iIcon;
	lvIt.lParam=pIn->nStation;
	lvIt.pszText=(char *)(LPCSTR)pIn->sDeviceType ;
	lvIt.iSubItem=0;
	lvIt.iItem=nItem;
	int iPos=pListCtrl->InsertItem(&lvIt);
	lvIt.mask=LVIF_TEXT;
	lvIt.iItem=iPos;
	lvIt.pszText=itoa(pIn->nStation,tmpChar,10);
	lvIt.iSubItem=1;
	pListCtrl->SetItem(&lvIt);
	lvIt.pszText=(char *)(LPCSTR)pIn->sBaterryName;
	lvIt.iSubItem=2;
	pListCtrl->SetItem(&lvIt);

	lvIt.pszText=(char *)(LPCSTR)pIn->nEventType;
	lvIt.iSubItem=3;
	pListCtrl->SetItem(&lvIt);
}

void CDigitalPowerAnalystView::InintLst()
{


 	static struct
	{
		LPSTR pszText;
		int uiFormat;
	}columns[]={
		_T("设备类型"),LVCFMT_LEFT,
		_T("站号"),LVCFMT_CENTER,
		_T("电池名称"),LVCFMT_CENTER,
		_T("事件类型"),LVCFMT_RIGHT
	};
	for(int i=0,j=120;i<sizeof(columns)/sizeof(columns[0]);i++,j-=10)
		m_ListCtrlStation.InsertColumn(i,columns[i].pszText,columns[i].uiFormat,j);
     //m_EventInfo

}




void CDigitalPowerAnalystView::OnMouseMove(UINT nFlags, CPoint point)  
{
	// TODO: Add your message handler code here and/or call default
   
	CString tmpStr;
    POINT pt=point;
   static int DrawFalg=0;
   static POINT oldpoint;
   static int ValidFlag=0;
   static int i=0;
	MousePoint=point;
		 CFont font;
VERIFY(font.CreateFont(
   22,                        // nHeight
   0,                         // nWidth
   0,                         // nEscapement
   0,                         // nOrientation
   FW_HEAVY,//FW_NORMAL,                 // nWeight
   FALSE,                     // bItalic
   FALSE,                     // bUnderline
   0,                         // cStrikeOut
   DEFAULT_CHARSET,              // nCharSetANSI_CHARSET
   OUT_DEFAULT_PRECIS,        // nOutPrecision
   CLIP_DEFAULT_PRECIS,       // nClipPrecision
   PROOF_QUALITY,//DEFAULT_QUALITY,           // nQuality
   DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
   "隶书"));                 // lpszFacename

// Do something with the font just created...
  

 

// Done with the font.  Delete the font object.

	CClientDC * pDCMouse;
	pDCMouse=new CClientDC(&m_StaticPicture);//&m_StaticPicture
	CFont* def_font = pDCMouse->SelectObject(&font);
	pDCMouse->SetBkMode(TRANSPARENT);
 
    
    for(int j=1;j<5;j++)
	{
	  if((nLeft[j]<=pt.x)&&(pt.x<=nRight[j])&&(nTop[j]<=pt.y)&&(pt.y<=nBottom[j]))
	  {
	    break;
	  }
	}//测在不在区间
	if(((j>0)&&(j<5))&&(i!=j))
	DrawFalg=1;
	if(!((j>0)&&(j<5))&&(i!=j))
	ValidFlag=1;
	i=j;
//	if(nFlags==6)
//	ValidFlag=1;

  if(ValidFlag==1)
  {
     m_StaticPicture.Invalidate(TRUE);//BOOL InvalidateRect( LPCRECT lpRect, BOOL bErase = TRUE );
     ValidFlag=0;
  }
  //pDCMouse->UpdateColors( );;//R2_XORPEN//R2_MERGEPEN

 	 //m_StaticPicture.InvalidateRect(&rectLcd  ,  TRUE );
  
   
	 pDCMouse->FillRgn(&rectLcd, &pBrushClear);
	 pDCMouse->SetTextColor( RGB(0, 255, 255));//RGB(125, 25, 255)RGB(205, 255, 205)
	 tmpStr =m_StationOnLine[1]?(m_BatteryStatus[1]? m_sConstantCycle[m_nCycleAll[1] -1]:NoBattery):NoStation;
 
  	pDCMouse->TextOut(  (nRight[0])*0/7 +1, (nBottom[0]-nTop[0])*2/5-10,tmpStr);
	tmpStr =m_StationOnLine[2]? (m_BatteryStatus[2]? m_sConstantProgram[m_sProgram[2]]:NoBattery):NoStation;
	
 
  	pDCMouse->TextOut(   (nRight[0])*2/7-15, (nBottom[0]-nTop[0])*2/5-10,tmpStr);
	tmpStr =m_StationOnLine[3]? (m_BatteryStatus[3]?m_sConstantProgram[m_sProgram[3]]  :NoBattery):NoStation;
	 
  	pDCMouse->TextOut(   (nRight[0])*3.5/7-5, (nBottom[0]-nTop[0])*2/5-10,tmpStr);
	tmpStr =m_StationOnLine[4]? (m_BatteryStatus[4]?m_sConstantCycle[m_nCycleAll[4]-1]:NoBattery):NoStation;
 
   	pDCMouse->TextOut(  (nRight[0])*5/7, (nBottom[0]-nTop[0])*2/5-10,tmpStr);
//	pDCMouse->SetTextColor( RGB(0, 255, 205));
	
	tmpStr=m_BatteryStatus[1]?  m_StationItem[1][10]: m_sConstantProgram[m_sProgram[1]];
	pDCMouse->TextOut(  (nRight[0])*0/7+1, (nBottom[0]-nTop[0])*1/2-5,tmpStr);
	tmpStr=m_BatteryStatus[2]?  m_StationItem[2][10]:m_sConstantCycle[m_nCycleAll[2] ] ;
 	pDCMouse->TextOut(  (nRight[0])*2/7-15, (nBottom[0]-nTop[0])*1/2-5,tmpStr); 
	tmpStr=m_BatteryStatus[3]?  m_StationItem[3][10]: m_sConstantCycle[m_nCycleAll[3]];
 	pDCMouse->TextOut(  (nRight[0])*3.5/7-5, (nBottom[0]-nTop[0])*1/2-5,tmpStr); 
	tmpStr=m_BatteryStatus[4]?  m_StationItem[4][10]:m_sConstantProgram[m_sProgram[4]]  ;
	pDCMouse->TextOut(   (nRight[0])*5/7, (nBottom[0]-nTop[0])*1/2-5,tmpStr);
  //  pDCMouse->SetTextColor( RGB(255,0,255));
	tmpStr=m_StationItem[1][11];
 	pDCMouse->TextOut( (nRight[0])*0/7+1, (nBottom[0]-nTop[0])*3/5-10,tmpStr); 
	tmpStr=m_StationItem[2][11];
 	pDCMouse->TextOut(  (nRight[0])*2/7-15, (nBottom[0]-nTop[0])*3/5-10,tmpStr); 
	tmpStr=m_StationItem[3][11];
 	pDCMouse->TextOut(  (nRight[0])*3.5/7-5, (nBottom[0]-nTop[0])*3/5-10,tmpStr); 
	tmpStr=m_StationItem[4][11];
 	pDCMouse->TextOut(  (nRight[0])*5/7, (nBottom[0]-nTop[0])*3/5-10,tmpStr); 



	if(DrawFalg==1)
	  {	CPen * oldPenMouse;
    	CBrush * oldBrushMouse;

   	    CBrush m_Brush;
	    CPen pen;

		m_Brush.CreateSolidBrush(RGB(0, 0,225));//CreateStockObject(0);//( BS_HOLLOW   , RGB(0, 0,225) );//CreateSolidBrush(RGB(0, 0,225));
	//PS_DOTHS_DIAGCROSS
		    pen.CreatePen(PS_DOT ,1,RGB(20, 255,225));	
		oldPenMouse=(CPen*)pDCMouse->SelectObject(&pen);
		//oldBrushMouse=(CBrush*) pDCMouse->SelectObject(&m_Brush);

	     tmpStr.Format("%5d",i);
  

		pDCMouse->Arc(nLeft[i],nTop[i] ,nRight[i]-10,nBottom[i]-17,nRight[i]-10,nTop[i],nRight[i]-10,nTop[i]);
pDCMouse->SetTextColor( RGB(255,0,255));
  	pDCMouse->TextOut( (nRight[0])*6/7-5, (nBottom[0]-nTop[0])*2/5-10,tmpStr);  
	//	FloodFill(*pDCMouse,nLeft[i]+(nRight[i]-10-nLeft[i])/2,nTop[i]+(nBottom[i]-17-nTop[i])/2,0);
//ScreenToClient
		DrawFalg=0;

	}
	    	
	  /* else
	   {              
 		   if((!((nLeft[i]<=pt.x: if(&(pt.x<=nRight[i]: if(&(nTop[i]<=pt.y: if(&(pt.y<=nBottom[i]))))
		  {//if(DrawFalg==1) 
	         m_StaticPicture.Invalidate(TRUE);
          // DrawFalg=0;
		   }
 
        	 
	   }*/


pDCMouse->SelectObject(def_font);
font.DeleteObject();
    delete [] pDCMouse;

	//CRecordView::OnMouseMove(nFlags, point);
}

void CDigitalPowerAnalystView::GetDataTimes()
{
	static long lInterval=0;
 
  CString DayTime ,DayTime0;
	 char tmpChar[10];
	/*
	SYSTEMTIME m_CurrentTime;
    ::GetSystemTime(&m_CurrentTime);
    DayTime="";
	DayTime+=itoa(m_CurrentTime.wYear,tmpChar,10);
	DayTime+="-";
	DayTime+=itoa(m_CurrentTime.wMonth,tmpChar,10);
	DayTime+="-";
	DayTime+=itoa(m_CurrentTime.wHour,tmpChar,10);
	DayTime0=" ";
	DayTime0+=itoa(m_CurrentTime.wHour,tmpChar,10);
	DayTime0+="-";
	DayTime0+=itoa(m_CurrentTime.wMinute,tmpChar,10);
	DayTime0+="-";
	DayTime0+=itoa(m_CurrentTime.wSecond,tmpChar,10);
    if(lInterval%2==0 )
		((CMainFrame *)GetParentFrame( ))->SetStatusPaneText(0,">>>>=====>>>>=====");
	 else
		((CMainFrame *)GetParentFrame( ))->SetStatusPaneText(0,"=====>>>>=====>>>>");
		((CMainFrame *)GetParentFrame( ))->SetStatusPaneText(5,(char *)(LPCTSTR )DayTime);
		((CMainFrame *)GetParentFrame( ))->SetStatusPaneText(6,(char *)(LPCTSTR )DayTime0);

		*/


	switch (lInterval%50)
	{
 case 0:
	{
	m_ComPort.WriteToDevice((char ) 0x98,0,0,"",0);//24 Return whether a adapter is present in a station or not 
	}

   break; 
 case 2: 
	 if(m_StationOnLine[1])
   {
	m_ComPort.WriteToDevice((char ) 0x96,1,0,"",0);//22 Return whether a adapter is present in a station or not 
		
		   
		
   }
   break;  
 case 4: 
	 if(m_StationOnLine[2])
   {
	m_ComPort.WriteToDevice((char ) 0x96,2,0,"",0);//22 Return whether a adapter is present in a station or not 
		
	 	   
		
   }
   break; 
 case 6: 
	 if(m_StationOnLine[3])
   {
	m_ComPort.WriteToDevice((char ) 0x96,3,0,"",0);//22 Return whether a adapter is present in a station or not 
		
 	   
		
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -