📄 client1view.cpp
字号:
// client1View.cpp : implementation of the CClient1View class
//
//*************************************************************
//作者:赵明
//EMAIL:zmpapaya@hotmail.com;papaya_zm@sina.com
//主页:http://h2osky.126.com
/********************************************************/
#include "stdafx.h"
#include "client1.h"
#include "MainFrm.h"
#include "client1Doc.h"
#include "CntrItem.h"
#include "client1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CClient1View * CCview;
/////////////////////////////////////////////////////////////////////////////
// CClient1View
IMPLEMENT_DYNCREATE(CClient1View, CRichEditView)
BEGIN_MESSAGE_MAP(CClient1View, CRichEditView)
//{{AFX_MSG_MAP(CClient1View)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_WM_DESTROY()
ON_MESSAGE(WM_AGE1, addmessage)
ON_MESSAGE(WM_KSEND,OnKSend)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_CONNECT, OnConnect)
ON_COMMAND(IDC_SEND, OnSend)
ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClient1View construction/destruction
CClient1View::CClient1View()
{
// TODO: add construction code here
chattrue=TRUE;
//CCview=this;
}
CClient1View::~CClient1View()
{
}
BOOL CClient1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRichEditView::PreCreateWindow(cs);
}
void CClient1View::Message(LPCTSTR lpszMessage,COLORREF clr)
{
//在窗口中显示聊天信息
cfm.cbSize=sizeof(cfm);
cfm.crTextColor=clr;
cfm.dwMask=CFM_COLOR;
CString strTemp = lpszMessage;
int len = GetWindowTextLength();
GetRichEditCtrl().SetSel(len,len);
GetRichEditCtrl().SetSelectionCharFormat(cfm);
GetRichEditCtrl().ReplaceSel(strTemp);
}
void CClient1View::OnInitialUpdate()
{
CRichEditView::OnInitialUpdate();
cfm.cbSize=sizeof(cfm);
cfm.bCharSet=GB2312_CHARSET;
cfm.crTextColor=RGB(0,0,0);
cfm.dwMask=CFM_CHARSET | CFM_COLOR ;
cfm.dwEffects=0;
GetRichEditCtrl().SetDefaultCharFormat(cfm);
// Set the printing margins (720 twips = 1/2 inch).
SetMargins(CRect(720, 720, 720, 720));
}
/////////////////////////////////////////////////////////////////////////////
// CClient1View printing
BOOL CClient1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CClient1View::OnSend()
{//发消息
CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();
CEdit* pEdit=(CEdit*)pWnd->m_wndSend.GetDlgItem(IDC_EDIT1);
CString temp;
pEdit->GetWindowText(temp);
if(temp.IsEmpty())
{
MessageBox("不能发送空信息!!!","警告");
pEdit->SetFocus();
return;
}
// temp=temp+"\n";
if(chattrue)
{
MessageBox("没有连上服务器!!!","警告");
pEdit->SetFocus();
return;
}
temp="客户端: "+temp;
temp=temp+"\n";
Message((LPCTSTR)temp,RGB(255,0,0));
chatsocket->Send(temp.GetBuffer(0),255);
temp.ReleaseBuffer();
pWnd->m_wndSend.GetDlgItem(IDC_EDIT1)->SetFocus();
pEdit->SetWindowText("");
}
LRESULT CClient1View::OnKSend(WPARAM wParam,LPARAM lParam)
{
OnSend();
return 0;
}
void CClient1View::OnConnect()
{
//联接服务器
CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();
CClient1App* pApp=(CClient1App*)AfxGetApp();
CString str;
int jj;
jj=0;
for(int i = 0; i <pWnd->m_work.m_ListCtrl-> GetItemCount(); i++){
str =pWnd->m_work.m_ListCtrl->GetItemText(i,4 );
if(strcmp(str, "下载中") == 0){
jj++;
}
}
if(jj>0)
{AfxMessageBox("有文件正在下载!!!");
}else
{
CString aaa;
//::AfxGetMainWnd()->GetDlgItem(IDC_IPADDRESS1)->SetWindowText("10.1.40.23");
// pWnd->m_ipbar.m_ip.SetWindowText("127.0.0.1");
pWnd->m_ip1.GetWindowText(ipT);
//pWnd->m_ipbar.m_ip.GetWindowText(strT);
//::AfxGetMainWnd()->m_ipbar;
ip=ipT;
down[0]=new cdownload(0);
int cc=down[0]->sendlist();
if(cc!=-1)
{
if(chattrue)
{chatsocket=new mysocket(this);
chatsocket->Create();
chatsocket->Connect(ipT,8888);
chattrue=FALSE;
}
// TODO: Add your control notification handler code here
aaa="传圣(测试版) 1.0----客户端已启动";
pApp->m_pMainWnd->SetWindowText(aaa);
// pWnd->m_wndStatusBar.SetPaneText(1,"在线人数:0");
// delete down[0];
}
}
}
LRESULT CClient1View::addmessage(WPARAM wParam, LPARAM lParam)
{
//显示信息
// MessageBox("aaa");
LPCTSTR pStr = (LPCTSTR)wParam;
Message(pStr,RGB(0,0,0));
return 1;
}
void CClient1View::OnDestroy()
{
// Deactivate the item on destruction; this is important
// when a splitter view is being used.
CRichEditView::OnDestroy();
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
}
/////////////////////////////////////////////////////////////////////////////
// CClient1View diagnostics
#ifdef _DEBUG
void CClient1View::AssertValid() const
{
CRichEditView::AssertValid();
}
void CClient1View::Dump(CDumpContext& dc) const
{
CRichEditView::Dump(dc);
}
CClient1Doc* CClient1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClient1Doc)));
return (CClient1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CClient1View message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -