?? 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();
//add begin
cfm.cbSize=sizeof(cfm);
cfm.bCharSet=GB2312_CHARSET;
cfm.crTextColor=RGB(0,0,0);
cfm.dwMask=CFM_CHARSET | CFM_COLOR ;
cfm.dwEffects=0;
//CRichEditView::GetRichEditCtrl Call this function to retrieve the CRichEditCtrl object associated with the CRichEditView object.
//此函數(shù)的原型是:CRichEditCtrl& GetRichEditCtrl( ) const; 我對此函數(shù)比較熟悉,在微軟的WordPad程序中經(jīng)常用到此函數(shù)。
//CRichEditCtrl::SetDefaultCharFormat Sets the character formatting attributes for new text in this CRichEditCtrl object.
GetRichEditCtrl().SetDefaultCharFormat(cfm);
//add end
// 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()
{//發(fā)消息
CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();
CEdit* pEdit=(CEdit*)pWnd->m_wndSend.GetDlgItem(IDC_EDIT1);
CString temp;
pEdit->GetWindowText(temp);
if(temp.IsEmpty())
{
MessageBox("不能發(fā)送空信息!!!","警告");
pEdit->SetFocus();
return;
}
// temp=temp+"\n";
if(chattrue)
{
MessageBox("沒有連上服務(wù)器!!!","警告");
pEdit->SetFocus();
return;
}
temp="客戶端: "+temp;
temp=temp+"\n";
Message((LPCTSTR)temp,RGB(255,0,0));
m_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;
}
//工具條上的“連接”按鈕的消息響應(yīng)函數(shù)。
void CClient1View::OnConnect()
{
//聯(lián)接服務(wù)器
CMainFrame* pWnd=(CMainFrame*)AfxGetMainWnd();
CClient1App* pApp=(CClient1App*)AfxGetApp();
CString str;
int beDownloading;
beDownloading=0;
//m_work變量,對應(yīng)于那個顯示“文件下載進(jìn)度”的List控件。
//用下面的這個循環(huán)來查看是否有文件正在下載。
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)
{
beDownloading++;
}
}
if(beDownloading>0)
{
AfxMessageBox("有文件正在下載!!!");
}
else
{
CString aaa;
//獲取在工具條上的“子窗口控件”中設(shè)定的IP地址串。
pWnd->m_ip1.GetWindowText(m_csIP);
g_csIP=m_csIP;
m_down[0]=new cdownload(0);
//給服務(wù)器發(fā)送type=0的命令(所謂的LIST命令),以獲取服務(wù)上可下載的文件信息列表。
int cc=m_down[0]->SendListCmd();
//如果不是“服務(wù)器接不上!”,則
if(cc!=-1)
{
//如果聊天socket還沒有接好,則
if(chattrue)
{
m_chatsocket=new mysocket(this);
m_chatsocket->Create();
m_chatsocket->Connect(m_csIP,8888);
chattrue=FALSE;//設(shè)為false,表示聊天socket已經(jīng)連接好了。
}
aaa="月影傳書";
pApp->m_pMainWnd->SetWindowText(aaa);
}
}
}
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
/////////////////////////////////////////////////////////////////////////////
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -