|
|
|
SI_COMM is not just for Visual Basic developers, Visual C++ developers can use it as well. SI_COMM comes complete with an MFC integration class that allows you to easily add SI_COMM to your MFC applications. All of SI_COMM's properties, methods, and events are accessible to you without having to write any supporting code to do it. The following code is from an example program included with SI_COMM. The program is a simple break out monitor that displays the state of the modem signals RI, CTS, DCD, and DSR. Shown below is the compiled program running under Windows 95.
/************************************************************************ SI_COMM.OCX Copyright (C) 1998 Software Innovations Inc All rights reserved. Description: MFC Example Code for SI_COMM OCX. ************************************************************************/ #include <afxwin.h> #include <afxdisp.h > #include "..\..\INC\SiCommCtrl.h" #include "BreakOutBox.h" #include "resource.h" CBreakOutBoxApp objApp; /*---------------------------------------------------------------------- -----------------------------------------------------------------------*/ BOOL CBreakOutBoxApp::InitInstance() { AfxEnableControlContainer(); m_pMainWnd = new CBreakOutWindow; m_pMainWnd->CenterWindow(NULL); m_pMainWnd->SetIcon(LoadIcon(IDI_APPICON),FALSE); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } BEGIN_MESSAGE_MAP(CBreakOutWindow,CFrameWnd) ON_WM_PAINT() ON_WM_DESTROY() ON_WM_CREATE() END_MESSAGE_MAP() BEGIN_EVENTSINK_MAP(CBreakOutWindow, CFrameWnd) ON_EVENT(CBreakOutWindow,100,1,CommEvent,VTS_I2) END_EVENTSINK_MAP() /*---------------------------------------------------------------------- -----------------------------------------------------------------------*/ CBreakOutWindow::CBreakOutWindow() { m_sDcd = "DCD"; m_sDsr = "DSR"; m_sRi = "RI"; m_sCts = "CTS"; Create(NULL,"RS232 Break OutBox",WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX, CRect(0,0,225,150)); } /*---------------------------------------------------------------------- -----------------------------------------------------------------------*/ int CBreakOutWindow::OnCreate( LPCREATESTRUCT lpCreateStruct ) { TEXTMETRIC tm; CClientDC *dc; if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!objSiComm.Create(this,100)) AfxThrowResourceException(); // Set the Delta DCD,DSR,CTS, and RI events.. objSiComm.SetDeltaDCD(TRUE); objSiComm.SetDeltaDSR(TRUE); objSiComm.SetDeltaCTS(TRUE); objSiComm.SetDeltaRI(TRUE); objSiComm.SetPortNumber(COMM1); objSiComm.SetPortOpen(TRUE); dc = new CClientDC( this ); dc->GetTextMetrics(&tm); m_cxChar = tm.tmAveCharWidth; m_cyChar = tm.tmHeight; delete dc; return 0; } /*---------------------------------------------------------------------- -----------------------------------------------------------------------*/ void CBreakOutWindow::OnDestroy( void ) { objSiComm.SetPortOpen(FALSE); } /*---------------------------------------------------------------------- -----------------------------------------------------------------------*/ void CBreakOutWindow::OnPaint( void ) { CPaintDC dc( this ); int x1,x2,y1,y2; x1 = 3 * m_cxChar; x2 = 16 * m_cxChar; y1 = m_cyChar; y2 = 4 * m_cyChar; dc.TextOut(x1,y1,m_sDcd,m_sDcd.GetLength()); dc.TextOut(x1,y2,m_sDsr,m_sDsr.GetLength()); dc.TextOut(x2,y1,m_sCts,m_sCts.GetLength()); dc.TextOut(x2,y2,m_sRi,m_sRi.GetLength()); DrawDiode(x1 + (5*m_cxChar),y1 + 2,objSiComm.GetDCD(),dc); DrawDiode(x1 + (5*m_cxChar),y2 + 2,objSiComm.GetDSR(),dc); DrawDiode(x2 + (5*m_cxChar),y1 + 2,objSiComm.GetCTS(),dc); DrawDiode(x2 + (5*m_cxChar),y2 + 2,objSiComm.GetRI(),dc); } /*---------------------------------------------------------------------- -----------------------------------------------------------------------*/ void CBreakOutWindow :: DrawDiode( int x, int y, BOOL on,CPaintDC &dc) { CBrush *pOldBrush; CBrush greenBrush(RGB(0,255,0)); CBrush blackBrush(RGB(0,0,0)); CRect rect; pOldBrush = dc.GetCurrentBrush(); rect.top = y; rect.left = x; rect.bottom = rect.top + 12; rect.right = rect.left + 12; if (on) dc.SelectObject(&greenBrush); else dc.SelectObject(&blackBrush); dc.Ellipse(&rect); dc.SelectObject(pOldBrush); } /*---------------------------------------------------------------------- -----------------------------------------------------------------------*/ BOOL CBreakOutWindow::CommEvent( unsigned short iEvent) { Invalidate(FALSE); return TRUE; }
|
For more information please email us at: info@rs232-serial-communications.com or call us at 845-566-1919Copyright © 2008
Software Innovations, Inc.
|