// IrScopeWnd.cpp : implementation file // #include "stdafx.h" #include "IRScope.h" #include "IrScopeWnd.h" #include "IrScopeConfigDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CIrScopeWnd BEGIN_MESSAGE_MAP(CIrScopeWnd, CWnd) //{{AFX_MSG_MAP(CIrScopeWnd) ON_WM_PAINT() ON_WM_DESTROY() ON_WM_LBUTTONDBLCLK() //}}AFX_MSG_MAP END_MESSAGE_MAP() CIrScopeWnd::CIrScopeWnd() { m_uTimesCnt=0; m_piTimes=NULL; m_counts=NULL; m_uPixelTime=20; m_bShowElapsedTime=TRUE; m_bShowPulseTimes=TRUE; m_bShowPulseCounts=TRUE; } CIrScopeWnd::~CIrScopeWnd() { delete[] m_piTimes; delete[] m_counts; } CString CIrScopeWnd::m_sWndClass; int CIrScopeWnd::RegisterWndClass(void) { if(!m_sWndClass.IsEmpty()) return 1; m_sWndClass=AfxRegisterWndClass( CS_HREDRAW | CS_DBLCLKS | CS_GLOBALCLASS, LoadCursor(NULL,IDC_ARROW), NULL, ::LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_IRSCOPE))); return 0; } int CIrScopeWnd::CloseAll(void) { ASSERT(!m_sWndClass.IsEmpty()); HWND hwnd; int i=0; while(hwnd=::FindWindowEx(::GetDesktopWindow(),NULL,m_sWndClass,NULL)) { ::DestroyWindow(hwnd); ++i; } return i; } ///////////////////////////////////////////////////////////////////////////// // CIrScopeWnd message handlers void CIrScopeWnd::OnPaint() { if(IsIconic()) return; CPaintDC dc(this); // device context for painting RECT rectClip,rectClient; dc.GetClipBox(&rectClip); GetClientRect(&rectClient); dc.FillSolidRect(&rectClip,RGB(255,255,255)); CFont* fontOld=dc.SelectObject(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FONT))); CSize large_font_size=dc.GetTextExtent("0",1); dc.SelectObject(&m_fontSmall); CSize small_font_size=dc.GetTextExtent("0",1); int iY=4; dc.SelectObject(fontOld); dc.SetTextColor(0); dc.SetTextAlign(TA_TOP | TA_LEFT); dc.TextOut(4,iY,m_TitleText); iY+=(large_font_size.cy+4); UINT clr_index=0; dc.SelectObject(fontOld); int iYHigh=iY; int iYLow=iYHigh+((m_bShowPulseCounts && m_counts!=NULL)?small_font_size.cy:10); const int iLineHeight=(iYLow-iYHigh)+(m_bShowPulseTimes?small_font_size.cy:0)+5; const int iTraceSpacing=__max(iLineHeight,large_font_size.cy); const int iTextMargin=rectClient.left+(m_bShowElapsedTime?large_font_size.cx*9:0); const int iLeftMargin=iTextMargin+4; const int iRightMargin=rectClient.right-1-4; const UINT uLineTime=(iRightMargin-iLeftMargin+1)*m_uPixelTime; UINT uStartTime=0; if(m_bShowElapsedTime) { dc.SetTextAlign(TA_RIGHT | TA_TOP); dc.TextOut(iTextMargin,iYHigh,"0",1); } UINT uXTime=0; int iX=iLeftMargin; UINT chunk_start_index=0; //dc.MoveTo(iX,iYHigh); for(UINT u=0; u < m_uTimesCnt; u++) { if(iYHigh>rectClip.bottom) break; const int uTime=abs(m_piTimes[u]); const BOOL bHigh=m_piTimes[u]>0; CString s; if(m_bShowPulseTimes) { s.Format("%i",uTime); dc.SelectObject(&m_fontSmall); dc.SetTextAlign(TA_LEFT | TA_TOP); dc.TextOut(iX,iYLow+1,s); } if(m_bShowPulseCounts && m_counts!=NULL && m_counts[u]!=0) { s.Format("%i",m_counts[u]); dc.SelectObject(&m_fontSmall); dc.SetTextAlign(TA_LEFT | TA_TOP); dc.TextOut(iX+3,iYHigh+1,s); } if(bHigh) { dc.MoveTo(iX,iYLow); dc.LineTo(iX,iYHigh); } else { dc.MoveTo(iX,iYHigh); dc.LineTo(iX,iYLow); } uXTime+=uTime; iX=iLeftMargin + uXTime/m_uPixelTime; while(iX > iRightMargin) { dc.LineTo(iRightMargin,bHigh?iYHigh:iYLow); iYHigh+=iTraceSpacing; iYLow+=iTraceSpacing; uStartTime+=uLineTime; if(m_bShowElapsedTime) { s.Format("%i",uStartTime); dc.SelectObject(fontOld); dc.SetTextAlign(TA_RIGHT | TA_TOP); dc.TextOut(iTextMargin,iYHigh,s); } dc.MoveTo(iLeftMargin,bHigh?iYHigh:iYLow); uXTime-=uLineTime; iX=iLeftMargin + uXTime/m_uPixelTime; } dc.LineTo(iX,bHigh?iYHigh:iYLow); } dc.SelectObject(fontOld); // Do not call CWnd::OnPaint() for painting messages } void CIrScopeWnd::OnDestroy() { CWnd::OnDestroy(); delete this; } int CIrScopeWnd::Create(HWND hwndParent) { ASSERT(!m_sWndClass.IsEmpty()); ASSERT(!IsWindow(m_hWnd)); m_fontSmall.CreatePointFont(90,"Courier New"); return CreateEx(0, m_sWndClass, "IR Scope", WS_VISIBLE | WS_OVERLAPPEDWINDOW, 20,50,720,480, //10,100,1400,1000, hwndParent, 0); } int CIrScopeWnd::SetData(UINT uTimesCnt, int* piTimes, short int* counts) { m_uTimesCnt=uTimesCnt; m_piTimes=piTimes; m_counts=counts; Invalidate(); return 0; } int CIrScopeWnd::CopyData(UINT uTimesCnt, int* piTimes, short int* counts) { m_uTimesCnt=uTimesCnt; m_piTimes=new int[m_uTimesCnt]; memcpy(m_piTimes,piTimes,m_uTimesCnt*sizeof(int)); if(counts) { m_counts=new short int[m_uTimesCnt]; memcpy(m_counts,counts,m_uTimesCnt*sizeof(short int)); } else { m_counts=NULL; } Invalidate(); return 0; } void CIrScopeWnd::OnLButtonDblClk(UINT nFlags, CPoint point) { //TRACE0("Double Click!\n"); CIrScopeConfigDlg dlg(this); dlg.m_uPixelTime=m_uPixelTime; dlg.m_bShowElapsedTime=m_bShowElapsedTime; dlg.m_bShowPulseTimes=m_bShowPulseTimes; dlg.m_bShowPulseCounts=m_bShowPulseCounts; if(dlg.DoModal()==IDOK) { m_uPixelTime=dlg.m_uPixelTime; m_bShowElapsedTime=dlg.m_bShowElapsedTime; m_bShowPulseTimes=dlg.m_bShowPulseTimes; m_bShowPulseCounts=dlg.m_bShowPulseCounts; Invalidate(); } }