home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / vcterm / termedit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  1.7 KB  |  73 lines

  1. // termedit.cpp : implementation of the CTermEdit class
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1998 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include "stdafx.h"
  15. #include "vcterm.h"
  16. #include "termedit.h"
  17. #include "mainfrm.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CTermEdit
  27.  
  28. CTermEdit::CTermEdit()
  29. {
  30.     m_bEcho = FALSE;
  31. }
  32.  
  33. CTermEdit::~CTermEdit()
  34. {
  35. }
  36.  
  37. BEGIN_MESSAGE_MAP(CTermEdit, CEdit)
  38.     //{{AFX_MSG_MAP(CTermEdit)
  39.     ON_WM_CHAR()
  40.     ON_WM_CREATE()
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CTermEdit message handlers
  46.  
  47. int CTermEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
  48. {
  49.     if (CEdit::OnCreate(lpCreateStruct) == -1)
  50.         return -1;
  51.  
  52.     m_pCommCtrl = ((CMainFrame*)AfxGetMainWnd())->GetCommCtrl();
  53.  
  54.     return 0;
  55. }
  56.  
  57. void CTermEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  58. {
  59.     CString ch(nChar);
  60.     VARIANT var;
  61.     CCommCtrl* pCommCtrl = ((CMainFrame*)AfxGetMainWnd())->GetCommCtrl();
  62.     if (pCommCtrl->GetPortOpen())
  63.     {
  64.         var.vt = VT_BSTR;
  65.         var.bstrVal = ch.AllocSysString();
  66.         pCommCtrl->SetOutput(var);
  67.         VariantClear(&var);
  68.     }
  69.  
  70.     if (m_bEcho || !pCommCtrl->GetPortOpen())
  71.         CEdit::OnChar(nChar, nRepCnt, nFlags);
  72. }
  73.