www.pudn.com > QQ2004_Source_0.01.rar > SendDlg.cpp


// SendDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "QQClient.h" 
#include "SendDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CSendDlg dialog 
 
 
CSendDlg::CSendDlg(CWnd *mainWnd, CWnd* pParent /*=NULL*/) 
	: CDialog(CSendDlg::IDD, pParent) 
	, _message(_T("")) 
{ 
	//{{AFX_DATA_INIT(CSendDlg) 
	_sendMsg = _T(""); 
	//}}AFX_DATA_INIT 
	_mainWnd = mainWnd; 
	::ZeroMemory(&_friendAddr, sizeof(sockaddr_in)); 
} 
 
 
void CSendDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CSendDlg) 
	DDX_Text(pDX, IDC_EDIT_SEND, _sendMsg); 
	DDX_Text(pDX, IDC_EDIT_MSG, _message); 
	DDV_MaxChars(pDX, _message, 256); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CSendDlg, CDialog) 
	//{{AFX_MSG_MAP(CSendDlg) 
	ON_BN_CLICKED(IDC_SEND_BTN, OnSendBtn) 
	ON_WM_CLOSE() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CSendDlg message handlers 
 
void CSendDlg::OnSendBtn()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(TRUE); 
	if (_sendMsg.IsEmpty()) 
	{ 
		AfxMessageBox(_T("不可以发送空的消息")); 
		return ; 
	} 
 
	if (_comm.sendMsgToFriend(_sendMsg, _friendAddr, _userID) != S_OK) 
		return ; 
 
	insertMessage(_userName, _sendMsg); 
 
	_sendMsg.Empty(); 
 
	UpdateData(FALSE); 
} 
 
BOOL CSendDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO:  Add extra initialization here 
	SetWindowText(_friendName); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	// EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CSendDlg::insertMessage(CString nickname, CString message) 
{ 
	UpdateData(TRUE); 
 
	_message += nickname + _T(":\r\n"); 
	_message += message + _T("\r\n"); 
	_message += _T("\r\n"); 
 
	UpdateData(FALSE); 
 
	CEdit *edit = (CEdit*)GetDlgItem(IDC_EDIT_MSG); 
	edit->LineScroll(edit->GetLineCount()); 
} 
 
void CSendDlg::OnClose() 
{ 
	// TODO: Add your message handler code here 
	if (_mainWnd != NULL) 
	{ 
		TCHAR *friendID = new TCHAR[_friendID.GetLength() + 1]; 
		_tcscpy(friendID, _friendID); 
		_mainWnd->PostMessage(WM_SENDDLG_CLOSED, (WPARAM)friendID, 0); 
	} 
 
	DestroyWindow(); 
} 
 
void CSendDlg::OnCancel() 
{ 
	// TODO: Add your specialized code here and/or call the base class 
} 
 
void CSendDlg::OnOK() 
{ 
	// TODO: Add your specialized code here and/or call the base class 
}