?? sendview.cpp
字號:
// SendView.cpp : implementation file
//
#include "stdafx.h"
#include "ChatClient.h"
#include "ChatClientDoc.h"//添加的代碼
#include "SendView.h"
#include <stdlib.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSendView
IMPLEMENT_DYNCREATE(CSendView, CEditView)
CSendView::CSendView()
{
m_TimerID = 0;
}
CSendView::~CSendView()
{
}
BEGIN_MESSAGE_MAP(CSendView, CEditView)
//{{AFX_MSG_MAP(CSendView)
ON_WM_CHAR()
ON_WM_TIMER()
ON_COMMAND(ID_FILE_LEAVE, OnFileLeave)
ON_UPDATE_COMMAND_UI(ID_FILE_LEAVE, OnUpdateFileLeave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSendView drawing
void CSendView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CSendView diagnostics
#ifdef _DEBUG
void CSendView::AssertValid() const
{
CEditView::AssertValid();
}
void CSendView::Dump(CDumpContext& dc) const
{
CEditView::Dump(dc);
}
CChatClientDoc* CSendView::GetDocument() // non-debug version is inline
{
return STATIC_DOWNCAST(CChatClientDoc, m_pDocument);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSendView message handlers
BOOL CSendView::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
if (m_TimerID != 0)
KillTimer(m_TimerID);
return CEditView::DestroyWindow();
}
BOOL CSendView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
BOOL ret = CEditView::PreCreateWindow(cs);
cs.style = AFX_WS_DEFAULT_VIEW | WS_VSCROLL | ES_AUTOHSCROLL |
ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL;
return ret;
}
void CSendView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
//當不是回車鍵時,通過父類的實現函數處理即可
if ((nChar != VK_RETURN) || (nRepCnt!=1))
{
CEditView::OnChar(nChar, nRepCnt, nFlags);
return;
}
//如果是回車鍵
else
{
//得到文檔類的指針,同時確保它是非空的
CChatClientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString strText;
//得到發送窗口里的要發送的字符串
GetEditCtrl().GetWindowText(strText);
//調用SendMsg函數進行發送
pDoc->SendMsg(strText);
//字符串發送成功后將發送窗口的 內容清空
strText=_T("");
GetEditCtrl().SetWindowText(strText);
}
CEditView::OnChar(nChar, nRepCnt, nFlags);
}
void CSendView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CChatClientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (pDoc->m_bAutoChat)
{
CString temp =TakeString();
if (!temp.IsEmpty())
pDoc->SendMsg(temp);
}
else
{
KillTimer(m_TimerID);
m_TimerID = 0;
}
CEditView::OnTimer(nIDEvent);
}
void CSendView::OnFileLeave()
{
// TODO: Add your command handler code here
//在這里通知文檔類:
//完成自動的從String資源里得到相應的字符串
//然后發送出去
CChatClientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc->m_bAutoChat)
{
pDoc->m_bAutoChat = TRUE;
m_TimerID = SetTimer(1, 1000, NULL);
}
else
{
pDoc->m_bAutoChat = FALSE;
KillTimer(m_TimerID);
}
}
void CSendView::OnUpdateFileLeave(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CChatClientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pCmdUI->SetCheck(pDoc->m_bAutoChat);
}
CString CSendView::TakeString()
{
CString strResult;
strResult.LoadString(IDS_LEAVE);
return strResult;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -