?? testview.cpp
字號:
// TestView.cpp : implementation of the CTestView class
//
#include "stdafx.h"
#include <strstrea.h>
#include "Test.h"
#include "TestDoc.h"
#include "CntrItem.h"
#include "TestView.h"
#include "SendDlg.h"
#include "interface.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CTestView* g_pView;
void AddMsg(CString s,COLORREF c)
{
if(g_pView)
g_pView->AddMsg(s,c);
}
void rxLog(char * str)
{
AddMsg(str,RGB(128,0,0));
}
void AddCopyData(DWORD dw,unsigned len,unsigned char* buf,int snd)
{
char s[4096];
char* p;
COLORREF c;
c=snd ? RGB(0,0,200) : RGB(0,200,0);
if(snd)
AddMsg(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",c);
else
AddMsg("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",c);
sprintf(s,"data=0x%08x, len=%d",dw,len);
AddMsg(s,c);
unsigned i;
for(i=0;i<len;i++)
{
if(i%16==0)
{
s[0]=0;
p=s;
}
sprintf(p,"%02x ",buf[i]);
p+=3;
if(i%16==15)
{
AddMsg(s,c);
}
}
if(s[0])
AddMsg(s,c);
AddMsg("");
}
/////////////////////////////////////////////////////////////////////////////
// CTestView
IMPLEMENT_DYNCREATE(CTestView, CRichEditView)
BEGIN_MESSAGE_MAP(CTestView, CRichEditView)
//{{AFX_MSG_MAP(CTestView)
ON_WM_DESTROY()
ON_WM_CREATE()
ON_COMMAND(ID_CMD_SEND_DATA, OnCmdSendData)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestView construction/destruction
CTestView::CTestView()
{
// TODO: add construction code here
}
CTestView::~CTestView()
{
}
BOOL CTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRichEditView::PreCreateWindow(cs);
}
void CTestView::OnInitialUpdate()
{
CRichEditView::OnInitialUpdate();
// Set the printing margins (720 twips = 1/2 inch).
SetMargins(CRect(720, 720, 720, 720));
m_pRE=&GetRichEditCtrl();
m_pRE->GetSelectionCharFormat(m_cf);
strcpy(m_cf.szFaceName,"Fixedsys");
m_cf.dwEffects=0;
m_cf.crTextColor=RGB(0,128,0);
m_pRE->SetSelectionCharFormat(m_cf);
g_pView=this;
m_wndCd.CreateEx(0,NULL,"MyName",WS_POPUPWINDOW|WS_CAPTION|WS_THICKFRAME,
100,100,100,100,this->GetSafeHwnd(),NULL);
}
void CTestView::OnDestroy()
{
// Deactivate the item on destruction; this is important
// when a splitter view is being used.
g_pView=NULL;
CRichEditView::OnDestroy();
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
}
/////////////////////////////////////////////////////////////////////////////
// CTestView diagnostics
#ifdef _DEBUG
void CTestView::AssertValid() const
{
CRichEditView::AssertValid();
}
void CTestView::Dump(CDumpContext& dc) const
{
CRichEditView::Dump(dc);
}
CTestDoc* CTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDoc)));
return (CTestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestView message handlers
int CTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CRichEditView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
void CTestView::AddMsg(CString s, COLORREF c)
{
int n=GetWindowTextLength();
if(n>3000)
{
n=m_pRE->GetLineCount();
m_pRE->SetSel(0,m_pRE->LineIndex(n/3));
m_pRE->Clear();
}
s += _T("\r\n");
n = GetWindowTextLength();
m_pRE->SetSel(n,n);
m_cf.crTextColor=c;
m_pRE->SetSelectionCharFormat(m_cf);
m_pRE->ReplaceSel(s);
}
void CTestView::OnCmdSendData()
{
CSendDlg dlg(this);
if(dlg.DoModal()!=IDOK)
return;
DWORD data=dlg.m_uData;
DWORD len=0;
unsigned char buf[1024];
char in[1024];
strcpy(in,dlg.m_strBuf);
strcat(in," ");
istrstream is(in);
is>>hex;
unsigned t;
while(1)
{
is>>t;
if(!is.good())
break;
buf[len++]=(unsigned char)t;
}
UpData(data,len,buf);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -