www.gusucode.com > QQ界面的模拟实现(下)JavaScript源码程序 > QQ界面的模拟实现(下)/myqqapp/MyQQapp/QQSendMessage.cpp

    // QQSendMessage.cpp : implementation file
//

#include "stdafx.h"
#include "MyQQ.h"
#include "QQSendMessage.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CQQSendMessage dialog


 CQQSendMessage::CQQSendMessage(CWnd* pParent /*=NULL*/)
 	: CDialog(CQQSendMessage::IDD, pParent)
 {
 	//{{AFX_DATA_INIT(CQQSendMessage)
 	//}}AFX_DATA_INIT
 }


void CQQSendMessage::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQQSendMessage)
	DDX_Control(pDX, IDC_STATIC1, m_static1);
	DDX_Control(pDX, IDC_LIST1, m_list1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CQQSendMessage, CDialog)
	//{{AFX_MSG_MAP(CQQSendMessage)
	ON_WM_ERASEBKGND()
	ON_BN_CLICKED(IDC_SEND, OnSend)
	ON_EN_SETFOCUS(IDC_EDITSHOWMES, OnSetfocusEditshowmes)
	ON_WM_CREATE()
	ON_BN_CLICKED(IDC_SEND2, OnSend2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQQSendMessage message handlers

BOOL CQQSendMessage::OnInitDialog() 
{
	listboxitem=0;
	CDialog::OnInitDialog();	

	CenterWindow(GetDesktopWindow());
	CRect rect;
	m_list1.GetWindowRect(&rect);
	if(!btMyface.Create("▼我的形象>>", WS_CHILD| WS_BORDER|WS_VISIBLE , 
		CRect(0, 0, rect.Width(), 22), &m_list1, 101))
	{
		MessageBox("创建按钮失败");
		return -1;
	}

	if(!btQQ.Create("▼QQ留言>>", WS_CHILD|WS_VISIBLE , 
		CRect(0, 100, rect.Width(), 125), &m_list1, 102))
	{
		MessageBox("创建按钮失败");
		return -1;
	}
	
	return TRUE;  
}

BOOL CQQSendMessage::OnEraseBkgnd(CDC* pDC) 
{
	
	CRect rc;
	GetClientRect(&rc);
	CBrush brush, *pOldbrush;
	brush.CreateSolidBrush(RGB(93, 183, 255));
	pOldbrush=pDC->SelectObject(&brush);
	pDC->FillRect(&rc, &brush);
	pDC->SelectObject(pOldbrush);
	return true;
}

void CQQSendMessage::OnSend() 
{
	// TODO: Add your control notification handler code here
	CString str, mes;
	GetDlgItem(IDC_EDIT1)->GetWindowText(str);
	if(str.GetLength()<1)
	{
		MessageBox("发送消息不能为空", "阿帅友情提示");
		return;
	}

	CEdit *pEditCtrl=(CEdit *)GetDlgItem(IDC_EDITSHOWMES);
	pEditCtrl->GetWindowText(mes);
	mes+="小蛤蟆帅(276490908)说:\r\n ";
	mes+=str+"\r\n\r\n";
	pEditCtrl->SetWindowText(mes);

	//////////////////////////////////////////////////////////////////////////
	// 模拟回复
	PlaySound("msg.wav",  AfxGetResourceHandle(),
		SND_RESOURCE|SND_ASYNC|SND_NODEFAULT);

	mes+=msg+"回复时说:\r\n";
	mes+=" 我吃饭去啦,暂时无法联系......\r\n\r\n";
	pEditCtrl->SetWindowText(mes);
	  
	pEditCtrl->LineScroll(pEditCtrl->GetLineCount()); 
	GetDlgItem(IDC_EDIT1)->SetWindowText("");
	GetDlgItem(IDC_EDIT1)->SetFocus();
}

void CQQSendMessage::OnSetfocusEditshowmes() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_EDIT1)->SetFocus();
}

int CQQSendMessage::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	/*
	if (!mesToolbar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC)
		||!mesToolbar.LoadToolBar(IDR_TOOLBARMES))
	{
		MessageBox("创建工具栏失败","友情提示");
		//EndDialog(IDCANCEL); 
		return -1;
	}
	*/
	/*
	CImageList mtoolbaricons;
	mtoolbaricons.Create(16, 16, TRUE | ILC_COLOR8, 4, 0);
	HICON hIcon = NULL;

	hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(), 
		MAKEINTRESOURCE(IDI_VEDIO), IMAGE_ICON, 32, 32, 0);

	mtoolbaricons.Add(hIcon);
	mtoolbaricons.Add(hIcon);
	mtoolbaricons.Add(hIcon);
	mtoolbaricons.Add(hIcon);
	mesToolbar.GetToolBarCtrl().SetImageList(&mtoolbaricons);
	*/

	/*
	CRect rect;
	mesToolbar.GetToolBarCtrl().GetWindowRect(&rect);
	ScreenToClient(&rect);
	mesToolbar.GetToolBarCtrl().MoveWindow(rect.left, rect.right, 120, rect.Height(), TRUE);

*//*
	CRect rcClientOld;   //   久客户区RECT   
	CRect rcClientNew;   //   加入TOOLBAR后的CLIENT   RECT   
	GetClientRect(rcClientOld);   //     
	//   Called   to   reposition   and   resize   control   bars   in   the   client   area   of   a   window   
	//   The   reposQuery   FLAG   does   not   really   traw   the   Toolbar.     It   only   does   the   calculations.   
	//   And   puts   the   new   ClientRect   values   in   rcClientNew   so   we   can   do   the   rest   of   the   Math.   
	//重新计算RECT大小   
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);   
    
	//   All   of   the   Child   Windows   (Controls)   now   need   to   be   moved   so   the   Tollbar   does   not   cover   them   up.   
	//所有的子窗口将被移动,以免被TOOLBAR覆盖   
	//   Offest   to   move   all   child   controls   after   adding   Tollbar   
	//计算移动的距离   
	CPoint   ptOffset(rcClientNew.left-rcClientOld.left,   
		rcClientNew.top-rcClientOld.top);   
    
	CRect rcChild;   
	CWnd* pwndChild   =   GetWindow(GW_CHILD);     //得到子窗口   
	while(pwndChild)   //   处理所有子窗口   
	{//移动所有子窗口   
		pwndChild->GetWindowRect(rcChild);   
		ScreenToClient(rcChild);     
		rcChild.OffsetRect(ptOffset);     
		pwndChild->MoveWindow(rcChild,FALSE);     
		pwndChild   =   pwndChild->GetNextWindow();   
	}   
    
	CRect rcWindow;   
	GetWindowRect(rcWindow);   //   得到对话框RECT   
	rcWindow.right   +=   rcClientOld.Width()   -   rcClientNew.Width();   //   修改对话框尺寸   
	rcWindow.bottom   +=   rcClientOld.Height()   -   rcClientNew.Height();     
	MoveWindow(rcWindow,FALSE);   //   Redraw   Window   
    */
	//positionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);   
	
	return 0;
}

BOOL CQQSendMessage::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN)
	{   
		if(pMsg->wParam==VK_RETURN   &&   GetKeyState(VK_CONTROL)&0x80)
		{   
			{
				//处理发送对话的内容   
				OnSend();
				return   1;   
			}
		}   
	}   
	return CDialog::PreTranslateMessage(pMsg);
}


void CQQSendMessage::OnSend2() 
{
	// TODO: Add your control notification handler code here
	CString str="";
	CString mes="7452521+1258?";
	GetDlgItem(IDC_EDIT1)->GetWindowText(str);
	if(str.GetLength()<1)
	{
		MessageBox("发送消息不能为空", "阿帅友情提示");
		return;
	}
	//////////////////////////////////////////////////////////////////////////
	// 将消息加密成2进制输出
	for(int i=0; i<str.GetLength(); i++)
	{
		char ch=str.GetAt(i);
		int tmp[8];
		memset(tmp, 0, 8);
		for(int j=0; j<8; j++)
		{
			tmp[j]=(ch%2+2)%2;
			ch/=2;
		}
		for(j=7; j>=0; j--)
		{
			CString strtmp;
			strtmp.Format("%d", tmp[j]);
			mes+=strtmp;
		}	
	}
	GetDlgItem(IDC_EDIT1)->SetWindowText(mes);
}