📄 view.cpp
字号:
// view.cpp : implementation of the CClientView class
//
#include "stdafx.h"
#include "client.h"
#include "doc.h"
#include "view.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CClientView
IMPLEMENT_DYNCREATE(CClientView, CFormView)
BEGIN_MESSAGE_MAP(CClientView, CFormView)
//{{AFX_MSG_MAP(CClientView)
ON_WM_SIZE()
ON_WM_DESTROY()
ON_COMMAND(IDM_FREEZE, OnFreeze)
ON_UPDATE_COMMAND_UI(IDM_FREEZE, OnUpdateFreeze)
ON_BN_CLICKED(IDC_SOCKCONFIG, OnSockconfig)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClientView construction/destruction
CClientView::CClientView()
: CFormView(CClientView::IDD)
{
m_ListBoxAttach=FALSE;
//{{AFX_DATA_INIT(CClientView)
m_LocalPort = 0;
m_RemotePort = 0;
m_RemoteHost = "";
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CClientView::~CClientView()
{
}
void CClientView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CClientView)
DDX_Text(pDX, IDC_LOCALPORT, m_LocalPort);
DDX_Text(pDX, IDC_REMOTEPORT, m_RemotePort);
DDX_Text(pDX, IDC_REMOTEHOST, m_RemoteHost);
//}}AFX_DATA_MAP
}
/////////////////////////////////////////////////////////////////////////////
// CClientView diagnostics
#ifdef _DEBUG
void CClientView::AssertValid() const
{
CFormView::AssertValid();
}
void CClientView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CClientDoc* CClientView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClientDoc)));
return (CClientDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CClientView message handlers
void CClientView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// CView::OnSize(nType, cx, cy);
if(m_ListBoxAttach)
{
RECT ClientRect;
GetClientRect(&ClientRect);
//get size of config control group
RECT ConfigGroupRect;
GetDlgItem(IDC_SOCKSETGROUP)->GetWindowRect(&ConfigGroupRect);
ConfigGroupRect.left=0;
ConfigGroupRect.right=cx;
ConfigGroupRect.bottom=ConfigGroupRect.bottom-ConfigGroupRect.top;
ConfigGroupRect.top=0;
GetDlgItem(IDC_SOCKSETGROUP)->MoveWindow(&ConfigGroupRect);
if(cy>ConfigGroupRect.bottom){
ClientRect.top=ConfigGroupRect.bottom;
m_ListBox.MoveWindow(&ClientRect);
}
}
}
void CClientView::OnDestroy()
{
m_ListBox.Detach();
CFormView::OnDestroy();
// TODO: Add your message handler code here
}
void CClientView::OnFreeze()
{
m_TrackData=!m_TrackData;
}
void CClientView::OnUpdateFreeze(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_TrackData);
}
void CClientView::AddLog(const char *LogString)
{
if(m_TrackData)
{
m_LogCount++;
CString tmpstr;
CTime curtime=CTime::GetCurrentTime();
tmpstr.Format("%-5lu",m_LogCount);
tmpstr+=curtime.Format("%H:%M:%S ");
tmpstr+=LogString;
if(m_ListBox.GetCount())
m_ListBox.AddString("");
m_ListBox.AddString(tmpstr);
GetDocument()->SetModifiedFlag();
}
}
void CClientView::AddSubLog(const char *LogString)
{
if(m_TrackData)
{
CString tmpstr=" ";
tmpstr+=LogString;
m_ListBox.AddString(tmpstr);
GetDocument()->SetModifiedFlag();
}
}
int ReadStringFromAr(CArchive &ar,char *RowString);
void CClientView::LoadData(CArchive& ar)
{
char *RowString;
char nChar;
RowString=new char[300];
m_TrackData=FALSE;
while(nChar=ReadStringFromAr(ar,RowString))
{
RowString[nChar-2]='\0';
m_ListBox.AddString(RowString);
m_LogCount++;
}
delete []RowString;
}
int ReadStringFromAr(CArchive &ar,char *RowString)
{
int nChar=0;
char *CurPos=RowString;
do{
if(!ar.Read(CurPos,1))
return 0;
nChar++;
CurPos++;
}while(RowString[nChar-1]!='\n');
return nChar;
}
void CClientView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
((CClientApp *)AfxGetApp())->m_CurView=this;
m_TrackData=TRUE;
m_LogCount=0;
if(m_ListBoxAttach==FALSE)
{
HWND hWnd;
hWnd=::GetDlgItem(m_hWnd,IDC_LIST);
m_ListBox.Attach(hWnd);
m_ListBoxAttach=TRUE;
}
RECT ClientRect;
GetClientRect(&ClientRect);
OnSize(SIZE_RESTORED,ClientRect.right,ClientRect.bottom);
}
void CClientView::ResetContent()
{
if(m_ListBoxAttach==TRUE)
m_ListBox.ResetContent();
}
void CClientView::SaveData(CArchive& ar)
{
int Count=m_ListBox.GetCount();
char *RowString;
int nChar;
int i;
m_TrackData=FALSE;
for(i=0;i<Count;i++)
{
nChar=m_ListBox.GetTextLen(i);
RowString=new char[nChar+3];
m_ListBox.GetText(i,RowString);
RowString[nChar]='\r';
RowString[nChar+1]='\n';
RowString[nChar+2]='\0';
ar.Write(RowString,nChar+3);
delete []RowString;
}
}
void CClientView::OnSockconfig()
{
AfxGetMainWnd()->PostMessage(WM_COMMAND,IDM_SOCKCONFIG,0);
// AfxGetMainWnd()->OnCommand(IDC_SOCKCONFIG,0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -