📄 chatroomclientdlg.cpp
字号:
// ChatRoomClientDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ChatRoomClient.h"
#include "ChatRoomClientDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChatRoomClientDlg dialog
CChatRoomClientDlg::CChatRoomClientDlg(CClientSocket *tmp,CWnd* pParent /*=NULL*/)
: CDialog(CChatRoomClientDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChatRoomClientDlg)
m_IDC_EDIT_MESSAGE = _T("");
m_1 = FALSE;
m_2 = FALSE;
m_3 = FALSE;
m_4 = FALSE;
m_5 = FALSE;
m_6 = FALSE;
m_7 = FALSE;
m_8 = FALSE;
m_9 = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
myServerSocket=tmp;
}
void CChatRoomClientDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChatRoomClientDlg)
DDX_Control(pDX, IDC_EDIT1, m_DATA);
DDX_Control(pDX, IDC_STATIC_NIKENAME, m_STATIC_NIKENAME_CONTROL);
DDX_Control(pDX, IDC_LIST_CHATBOX, m_IDC_LIST_CHATBOX_CONTROL);
DDX_Text(pDX, IDC_EDIT_MESSAGE, m_IDC_EDIT_MESSAGE);
DDX_Check(pDX, IDC_CHECK1, m_1);
DDX_Check(pDX, IDC_CHECK2, m_2);
DDX_Check(pDX, IDC_CHECK3, m_3);
DDX_Check(pDX, IDC_CHECK4, m_4);
DDX_Check(pDX, IDC_CHECK5, m_5);
DDX_Check(pDX, IDC_CHECK6, m_6);
DDX_Check(pDX, IDC_CHECK7, m_7);
DDX_Check(pDX, IDC_CHECK8, m_8);
DDX_Check(pDX, IDC_CHECK9, m_9);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChatRoomClientDlg, CDialog)
//{{AFX_MSG_MAP(CChatRoomClientDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
ON_EN_CHANGE(IDC_EDIT_MESSAGE, OnChangeEditMessage)
ON_WM_CTLCOLOR()
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChatRoomClientDlg message handlers
BOOL CChatRoomClientDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_STATIC_NIKENAME_CONTROL.SetWindowText(myServerSocket->NikeName);
// TODO: Add extra initialization here
m_1=TRUE;
m_9=TRUE;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CChatRoomClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CChatRoomClientDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CChatRoomClientDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CChatRoomClientDlg::GetMessage()
{
char buff[1000];
int count;
count=myServerSocket->Receive(buff,1000);
buff[count]=0;
if(m_IDC_LIST_CHATBOX_CONTROL.m_hWnd)
m_IDC_LIST_CHATBOX_CONTROL.AddString(buff);
return true;
}
void CChatRoomClientDlg::OnButtonSend()
{
UpdateData(TRUE);
CString cs;//=CString(m_quantic)
cs.Format("%d%d%d%d%d%d%d%d%d",m_1,m_2,m_3,m_4,m_5,m_6,m_7,m_8,m_9);
m_duoxs=cs;
// TODO: Add your control notification handler code here
MessageBox(cs);
int n;
char message[1000];
UpdateData(TRUE);
n=cs.GetLength()+m_IDC_EDIT_MESSAGE.GetLength();
m_IDC_EDIT_MESSAGE=cs+":"+m_IDC_EDIT_MESSAGE;
m_IDC_EDIT_MESSAGE.Replace(" ", "");
n=m_IDC_EDIT_MESSAGE.GetLength();
//message=new char(n+1);
sprintf(message,"%s",m_IDC_EDIT_MESSAGE.GetBuffer(n));
message[n]=0;
if (myServerSocket->Send(message,n+1))
{
m_IDC_EDIT_MESSAGE="";
UpdateData(FALSE);
}
else
{
AfxMessageBox("网络传输错误!!!");
}
}
void CChatRoomClientDlg::OnChangeEditMessage()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
//UpdateData(FALSE);
// TODO: Add your control notification handler code here
}
HBRUSH CChatRoomClientDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
switch(nCtlColor)
{
case CTLCOLOR_EDIT:
{
if(pWnd->GetDlgCtrlID()==IDC_EDIT_MESSAGE)
{
//CBrush brh(&bmp);
//pDC->SetBkMode(TRANSPARENT);
//pDC->FillRect(rc,&brh);
pDC->SetBkColor(RGB(200,10,200));
hbr =(HBRUSH)::GetStockObject(HOLLOW_BRUSH);
}
break;
}
default:
break;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CChatRoomClientDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
UpdateData(TRUE);
CString cs,sdata="";
m_DATA.GetWindowText(cs);
sdata=cs+"00000000";
int count=sdata.GetLength();
cs=cs+"00000000";
char *buf=(char *)(LPCSTR)cs;
if(!IsNumeric(buf))
{MessageBox("不能输入除1 或 0 外的数字!!");
m_DATA.SetWindowText("");
return;
}
char *quantic=(char *)(LPCSTR)m_duoxs;
int i=0;
int k=8;
while(k<=count-1)
{
int j=i,m=0;
if(buf[j]=='0')
{
i++;
k++;
// cs=cs+"0";
continue;
}
else
{
for(;j<=k;j++,m++)
{
if(buf[j]==quantic[m])
buf[j]='0';
else
buf[j]='1';
}
// cs=cs+"1";
// cs.Format("%s%c",cs,'1');
i++;
k++;
}
}
UpdateData(TRUE);
m_DATA.GetWindowText(sdata);
sdata=sdata+"00000000";
//MessageBox(sdata);
//m_DATA.SetWindowText(sdata);
char *send=(char *)(LPCSTR)sdata;
for(i=0;i<count;i++)
{
if(buf[i]==send[i])
send[i]='0';
else
send[i]='1';
}
//sdata=sdata.Left(count);
m_IDC_EDIT_MESSAGE.Format("%s",send);
UpdateData(FALSE);
// TODO: Add your control notification handler code here
}
BOOL IsNumeric(char *buff)
{
// validate data
char *ptr = buff;
while(*ptr)
{
if (*ptr=='0'||*ptr=='1'||*ptr==':')
{
ptr++;
}
else
return FALSE;
}
return TRUE;
}
void CChatRoomClientDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString cs;//=CString(m_quantic)
cs.Format("%d%d%d%d%d%d%d%d%d",m_1,m_2,m_3,m_4,m_5,m_6,m_7,m_8,m_9);
m_duoxs=cs;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -