www.pudn.com > mischat.rar > InputBar.cpp


// outputbar.cpp : implementation of the CInputBar class 
// 
 
#include "stdafx.h" 
#include "mischat.h" 
#include "inputbar.h" 
#include "mischatDoc.h" 
#include "NDKMessage.h" 
#include "ChatMessage.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
const int nBorderSize = 1; 
extern CmischatDoc* pDoc; 
 
///////////////////////////////////////////////////////////////////////////// 
// CInputBar 
 
BEGIN_MESSAGE_MAP(CInputBar, CBCGPDockingControlBar) 
	//{{AFX_MSG_MAP(CInputBar) 
	ON_WM_CREATE() 
	ON_WM_SIZE() 
	ON_WM_PAINT() 
	ON_WM_SETFOCUS() 
	ON_COMMAND(ID_INPUT_CLEAR, OnInputClear) 
	ON_COMMAND(ID_INPUT_SEND, OnInputSend) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CInputBar construction/destruction 
 
CInputBar::CInputBar() 
{ 
	// TODO: add one-time construction code here 
} 
 
CInputBar::~CInputBar() 
{ 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CInputBar message handlers 
 
int CInputBar::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CBCGPDockingControlBar::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	CRect rectDummy; 
	rectDummy.SetRectEmpty (); 
 
	// Create list window. 
	// TODO: create your own window here: 
	const DWORD dwViewStyle =	 
		WS_CHILD | WS_VISIBLE | WS_VSCROLL|ES_WANTRETURN|ES_MULTILINE; 
	 
	if (!m_wndEdit.Create (dwViewStyle, rectDummy, this, 1)) 
	{ 
		TRACE0("Failed to create input view\n"); 
		return -1;      // fail to create 
	} 
	CHARFORMAT2 cf; 
    cf.dwMask =CFM_COLOR|CFE_BOLD|CFM_SIZE|CFM_FACE ; 
	cf.dwEffects=CFE_BOLD; 
	cf.crTextColor=RGB(0,0,160); 
	cf.yHeight=200; 
	CString face=_T("ËÎÌå"); 
	lstrcpy(cf.szFaceName,face); 
	m_wndEdit.SetDefaultCharFormat(cf); 
 
	m_wndToolBar.Create (this, dwDefaultToolbarStyle, IDR_INPUT_TOOLBAR); 
	m_wndToolBar.LoadToolBar (IDR_INPUT_TOOLBAR, 0, 0, TRUE /* Is locked */); 
 
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | 
		CBRS_TOOLTIPS | CBRS_FLYBY); 
		 
	m_wndToolBar.SetBarStyle ( 
		m_wndToolBar.GetBarStyle () &  
			~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT)); 
 
	m_wndToolBar.SetOwner (this); 
 
	// All commands will be routed via this control , not via the parent frame: 
	m_wndToolBar.SetRouteCommandsViaFrame (FALSE); 
 
	AdjustLayout (); 
	return 0; 
} 
 
void CInputBar::AdjustLayout () 
{ 
	if (GetSafeHwnd () == NULL) 
	{ 
		return; 
	} 
 
	CRect rectClient; 
	GetClientRect (rectClient); 
 
	int cyTlb = m_wndToolBar.CalcFixedLayout (FALSE, TRUE).cy; 
 
	m_wndToolBar.SetWindowPos (NULL, rectClient.left, rectClient.top,  
								rectClient.Width (), cyTlb, 
								SWP_NOACTIVATE | SWP_NOZORDER); 
	m_wndEdit.SetWindowPos (NULL, rectClient.left + 1, rectClient.top + cyTlb + 1, 
								rectClient.Width () - 2, rectClient.Height () - cyTlb - 2, 
								SWP_NOACTIVATE | SWP_NOZORDER); 
} 
 
void CInputBar::OnSize(UINT nType, int cx, int cy)  
{ 
	CBCGPDockingControlBar::OnSize(nType, cx, cy); 
 
	AdjustLayout (); 
} 
 
void CInputBar::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	CRect rect; 
	m_wndEdit.GetWindowRect (rect); 
	ScreenToClient (rect); 
 
	rect.InflateRect (1, 1); 
	dc.Draw3dRect (rect,	::GetSysColor (COLOR_3DSHADOW),  
								::GetSysColor (COLOR_3DSHADOW)); 
} 
 
void CInputBar::OnInputClear()  
{ 
	m_wndEdit.SetWindowText (""); 
} 
 
void CInputBar::OnInputSend()  
{ 
	CString str; 
    m_wndEdit.GetWindowText(str); 
	if(str.IsEmpty ()) return; 
 
	CNDKMessage mg(ChatText); 
	mg.SetAt (0,str); 
	if(pDoc->server.isStart()) 
		pDoc->SendMsgToAll (mg); 
	if(pDoc->client.isStart()) 
		pDoc->SendMsg(mg); 
} 
 
void CInputBar::OnSetFocus(CWnd* pOldWnd)  
{ 
	CBCGPDockingControlBar::OnSetFocus(pOldWnd); 
	m_wndEdit.SetFocus (); 
}