📄 pictalkdlg.cpp
字号:
#include "stdafx.h"
#include "pictalk.h"
#include "pictalkDlg.h"
#include "ConnectDialog.h"
#include "SetDialog.h"
#include "MyEdit.h"
#include "SetDlg.h"
#include "ShowSen.h"
#include "ShowInfo.h"
//#include "TransparentWnd.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()
/////////////////////////////////////////////////////////////////////////////
// CPictalkDlg dialog
CPictalkDlg::CPictalkDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPictalkDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPictalkDlg)
m_Sendinfo = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pNet=NULL;
}
void CPictalkDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPictalkDlg)
DDX_Text(pDX, IDC_TALK, m_Sendinfo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPictalkDlg, CDialog)
//{{AFX_MSG_MAP(CPictalkDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_INFO_SEND, OnInfoSend)
ON_COMMAND(ID_MENU_LINK, OnMenuLink)
ON_COMMAND(ID_MENU_STOP, OnMenuStop)
ON_COMMAND(ID_MENU_SERVER, OnMenuServer)
ON_WM_TIMER()
ON_COMMAND(ID_BK_COLOR, OnBkColor)
ON_COMMAND(ID_FONT_COLOR, OnFontColor)
ON_BN_CLICKED(IDC_BUTTON_ANGRY, OnButtonAngry)
ON_BN_CLICKED(IDC_BUTTON_CRY, OnButtonCry)
ON_BN_CLICKED(IDC_BUTTON_SIT, OnButtonSit)
ON_THREAD_MESSAGE(ID_ACCEPT_MESSAGE,OnAcceptMessage)
ON_BN_CLICKED(IDC_BUTTON_SMILE, OnButtonSmile)
ON_BN_CLICKED(IDC_BUTTON_HELLO, OnButtonHello)
ON_BN_CLICKED(IDC_BUTTON_SEN, OnButtonSen)
ON_MESSAGE(WM_SENDLGCLOSE,OnDlgSenClose)
ON_MESSAGE(WM_SHOWINFOCLOSE,OnDlgInfoClose)
ON_EN_CHANGE(IDC_TALK, OnChangeTalk)
ON_BN_CLICKED(IDC_BUTTON_SHOWINFO, OnButtonShowinfo)
ON_WM_MOUSEMOVE()
ON_THREAD_MESSAGE(ID_CONNECTOVER,OnConnectOver)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPictalkDlg message handlers
BOOL CPictalkDlg::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
// TODO: Add extra initialization here
m_pMyEdit=new CMyEdit(this);
m_pMyEdit->SubclassDlgItem(IDC_TALK,this);
m_bConnected=FALSE;
m_pUserList.RemoveAll();
m_pShowSen=NULL;
m_pShowInfo=NULL;
m_UserCount=0;
m_pPW=&((CPictalkApp *)AfxGetApp())->pw;
m_pPW->Create(this,&m_pUserList);
CSetDlg dlg;
dlg.SetBMP(&(m_pPW->m_bm));
if(dlg.DoModal()==IDOK){
}
m_pUser=new CUserInfo(this);
m_pUser->m_Name=dlg.m_Name;
m_pUser->m_pic=dlg.m_PicID;
m_pUser->m_nAge=dlg.m_nAge;
m_pUser->m_Sex=dlg.m_Sex;
m_pUser->m_ICQ.Format("%s:%u",dlg.m_IcqType,dlg.m_IcqNum);
m_pUser->m_Job=dlg.m_Job;
m_pUser->m_Address=dlg.m_Address;
m_pUser->m_pPW=m_pPW;
m_bSendOut=TRUE;
{
WORD wversionrequested;
WSADATA wsadata;
CString str;
char name[255];
PHOSTENT hostinfo;
wversionrequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wversionrequested, &wsadata ) == 0 ){
if( gethostname ( name, sizeof(name)) == 0){
if((hostinfo = gethostbyname(name)) != NULL){
str = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
}
m_pUser->m_IP=str;
}
m_MainUser=0;
return TRUE; // return TRUE unless you set the focus to a control
}
void CPictalkDlg::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 CPictalkDlg::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
{
CEdit * pEdit=(CEdit *)GetDlgItem(IDC_TALK);
if(pEdit)
pEdit->SetFocus();
CDialog::OnPaint();
CClientDC dc(this);
m_pPW->paint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPictalkDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPictalkDlg::OnInfoSend()
{
// TODO: Add your control notification handler code here
if(m_bConnected)
{
UpdateData(TRUE);
if(m_Sendinfo.IsEmpty())
return;
mpack Msgpack;
Msgpack.m_MsgID=MID_PUBLICMSG;
Msgpack.m_ComID=MID_SENTENCE;
Msgpack.m_ID=m_pUser->m_ID;
Msgpack.m_state=m_pUser->m_state;
Msgpack.m_x=m_pUser->m_x;
Msgpack.m_y=m_pUser->m_y;
Msgpack.m_bSit=m_pUser->m_bSit;
Msgpack.m_Sen=m_Sendinfo;
SendMsg(Msgpack);
m_pUser->m_ComArray.Add(Msgpack);
m_Sendinfo="";
UpdateData(FALSE);
}
else
MessageBox("尚未连接","MB_OK");
}
void CPictalkDlg::ShowMsg(mcom &Msgcom)
{
CUserInfo * tempUser;
if(!m_MapUser.Lookup(Msgcom.m_ID,tempUser))
return;
tempUser->m_ComArray.Add(Msgcom);
}
void CPictalkDlg::OnMenuLink()
{
// TODO: Add your command handler code here
if(m_bConnected){
MessageBox("已建立连接!","警告信息",MB_OK);
return;
}
CConnectDialog m_Dlg1;
if(m_Dlg1.DoModal()==IDOK)
{
m_pNet=new CNet(this,m_Dlg1.m_ServerName,m_Dlg1.m_PortAddress);
m_pUserList.AddTail(m_pUser);
m_pUser->ShowUser();
m_bConnected=TRUE;
SetTimer(2,5000,NULL);
// if(((CCliNet *)m_pNet)->m_pSocket)
// {
// m_SenList.RemoveAll();
// m_bConnected=TRUE;
// OnButtonShowinfo();
// SendUser();
// m_time=SetTimer(1,500,NULL);
// m_contype=2;
// AfxBeginThread(AcceptWinInetThreadProc, GetSafeHwnd(), THREAD_PRIORITY_NORMAL);
// }
}
}
void CPictalkDlg::OnMenuStop()
{
// TODO: Add your command handler code here
if(m_bConnected)
{
if(m_bSendOut)
SendOut();
KillTimer(1);
StopLink();
}
else
MessageBox("未连接到任何服务器!","警告信息",MB_OK);
}
void CPictalkDlg::OnMenuServer()
{
// TODO: Add your command handler code here
CSetDialog m_Dlg1;
if(m_Dlg1.DoModal()==IDOK)
{
m_pNet=new CNet(this,m_Dlg1.m_PortAddress);
mpack::m_OldID=1;
if(m_pNet->m_pListeningSocket)
{
m_UserCount=1;
m_pUser->m_ID=m_UserCount;
m_SenList.RemoveAll();
m_bConnected=TRUE;
m_MapUser.SetAt(m_pUser->m_ID,m_pUser);
m_RoomName=m_Dlg1.m_RoomName;
m_pUserList.AddTail(m_pUser);
SetTimer(2,5000,NULL);
OnButtonShowinfo();
// m_time=SetTimer(1,500,NULL);
m_pUser->ShowUser();
m_contype=1;
m_MainUser=1;
if(m_Dlg1.m_bShowWeb)
{
roomid=0;
m_PortAddress=m_Dlg1.m_PortAddress;
m_time=SetTimer(1,5000,NULL);
g_strShowInfo.Format("port=%d&name=%s",m_Dlg1.m_PortAddress,m_RoomName);
AfxBeginThread(ShowWinInetThreadProc,GetSafeHwnd(),THREAD_PRIORITY_NORMAL);
}
}
}
}
void CPictalkDlg::CheckMsg(mpack & Msgpack)
{
switch(Msgpack.m_MsgID)
{
case MID_PUBLICMSG:
ShowMsg(Msgpack);
break;
case MID_ADDUSER:
AddUser(Msgpack);
break;
case MID_USERID:
GetID(Msgpack);
break;
case MID_DELUSER:
DelUser(Msgpack);
break;
default:
break;
}
}
void CPictalkDlg::AddUser(mcom &Msgcom)
{
CUserInfo * tempUser;
if(m_MapUser.Lookup(Msgcom.m_ID,tempUser))
return;
CUserInfo *pNewUser=new CUserInfo(this);
pNewUser->m_pic=Msgcom.m_pic;
pNewUser->m_ID=Msgcom.m_ID;
pNewUser->m_x=Msgcom.m_x;
pNewUser->m_y=Msgcom.m_y;
pNewUser->m_bSit=Msgcom.m_bSit;
pNewUser->m_state=Msgcom.m_state;
pNewUser->m_pPW=m_pPW;
pNewUser->m_IP=Msgcom.m_IP;
pNewUser->m_Name=Msgcom.m_Name;
pNewUser->m_nAge=Msgcom.m_nAge;
pNewUser->m_Sex=Msgcom.m_Sex;
pNewUser->m_ICQ=Msgcom.m_ICQ;
pNewUser->m_Job=Msgcom.m_Job;
pNewUser->m_Address=Msgcom.m_Address;
pNewUser->m_nPort=Msgcom.m_nPort;
m_MapUser.SetAt(pNewUser->m_ID,pNewUser);
m_pUserList.AddTail(pNewUser);
pNewUser->ShowUser();
}
void CPictalkDlg::SendUser()
{
mpack Msgpack;
Msgpack.m_MsgID=MID_ADDUSER;
Msgpack.m_ID=m_pUser->m_ID;
Msgpack.m_state=m_pUser->m_state;
Msgpack.m_x=m_pUser->m_x;
Msgpack.m_y=m_pUser->m_y;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -