写完之后,有点错误,错误排除
"CChatDlg"类。
...............
BEGIN_MESSAGE_MAP(CChatDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_RECVDATA,OnRecvData)
错误一:Error 1 error C2440: 'static_cast' : cannot convert from 'void (__thiscall CChatDlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\chat\chat\chatdlg.cpp 68 1 Chat
什么原因造成的,怎样修改???
错误六: 6 IntelliSense: invalid type conversion c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\chat\chat\chatdlg.cpp 68 2 Chat
什么原因造成的,怎样修改???
// ON_MESSAGE(WMUSER+1, &CChatDlg::WM_RECVDATA)
ON_BN_CLICKED(IDC_BTN_SEND, &CChatDlg::OnBnClickedBtnSend)
END_MESSAGE_MAP()
// CChatDlg message handlers
BOOL CChatDlg::OnInitDialog()
{
CDialogEx::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)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
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
//初始化套接字
InitSocket();
//创建接收线程
RECVPARAM *pRecvParam=new RECVPARAM;
pRecvParam->sock=m_socket;
pRecvParam->hwnd=m_hWnd;
HANDLE hThread=CreateThread(NULL,0,RecvProc,(LPVOID)pRecvParam,0,NULL);
//关闭该接收程句柄,释放其引用计数
CloseHandle(hThread);
return TRUE; // return TRUE unless you set the focus to a control
}
void CChatDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::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 CChatDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
{
CDialogEx::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CChatDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
bool CChatDlg::InitSocket(void)
{
//创建套接字
m_socket=socket(AF_INET,SOCK_DGRAM,0);
if (INVALID_SOCKET==m_socket)
{
MessageBox(_T("套接字创建失败!"));
return FALSE;
SOCKADDR_IN addrSock;
addrSock.sin_family=AF_INET;
addrSock.sin_port=htons(6000);
addrSock.sin_addr.S_un.S_addr=htonl(INADDR_ANY);
int retval;
//绑定套接字
retval=bind(m_socket,(SOCKADDR*)&addrSock,sizeof(SOCKADDR));
if (SOCKET_ERROR==retval)
{
closesocket(m_socket);
MessageBox(_T("绑定失败!"));
return FALSE;
}
return TRUE;
}
DWORD WINAPI CChatDlg::RecvProc(LPVOID lpParameter)
{
错误二:“{”提示错误如下:
Error 2 error C2601: 'CChatDlg::RecvProc' : local function definitions are illegal c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\chat\chat\chatdlg.cpp 199 1 Chat
什么原因,怎样修改???
错误七:“RecvProc”提示错误,信息如下:
7 IntelliSense: member function "CChatDlg::RecvProc" may not be redeclared outside its class c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\chat\chat\chatdlg.cpp 198 24 Chat
错误八:“{”提示错误,信息如下:
8 IntelliSense: expected a ';' c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\chat\chat\chatdlg.cpp 199 1 Chat
什么原因,怎样修改???
//获取主线程传递的套接字和窗口句柄
SOCKET sock=((RECVPARAM*)lpParameter)->sock;
HWND hwnd=((RECVPARAM*)lpParameter)->hwnd;
delete lpParameter;
SOCKADDR_IN addrFrom;
int len=sizeof(SOCKADDR);
char recvBuf[200];
char tempBuf[300];
int retval;
while(TRUE)
{
//接收数据
retval=recvfrom(sock,recvBuf,200,0,(SOCKADDR*)&addrFrom,&len);
if (SOCKET_ERROR==retval)
{
break;
sprintf(tempBuf,"%s说%s",inet_ntoa(addrFrom.sin_addr),recvBuf);
::PostMessage(hwnd,WM_RECVDATA,0,(LPARAM)tempBuf);
}
}
return 0;
}
//接收数据消息响应函数
void CChatDlg::OnRecvData(WPARAM wParam,LPARAM lParam)
{
错误三:“{”提示错误,信息如下:
Error 3 error C2601: 'CChatDlg::OnRecvData' : local function definitions are illegal c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\chat\chat\chatdlg.cpp 231 1 Chat
什么原因造成的,怎样修改???
//取出接收到的数据
CString str=(char*)lParam;
CString strTemp;
//获得已有数据
GetDlgItemText(IDC_EDIT_RECV,strTemp);
str+="\r\n";
str+=strTemp;
//显示所有接收到的数据
SetDlgItemText(IDC_EDIT_RECEV,str);
}
void CChatDlg::OnBnClickedBtnSend()
{
错误四:“{”提示错误,信息如下:
Error 4 error C2601: 'CChatDlg::OnBnClickedBtnSend' : local function definitions are illegal c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\chat\chat\chatdlg.cpp 301 1 Chat
什么原因???怎么“{”提示错误呢???
// TODO: Add your control notification handler code here
//获取对方IP
DWORD dwIP;
((CIPAddressCtrl*)GetDlgItem(IDC_IPADDRESS1))->GetAddress(dwIP);
SOCKADDR_IN addrTo;
addrTo.sin_family=AF_INET;
addrTo.sin_port=htons(6000);
addrTo.sin_addr.S_un.S_addr=htonl(dwIP);
CString strSend;
//获得待发送数据
GetDlgItemText(IDC_EDIT_SEND,strSend);
//发送数据
sendto(m_socket,strSend,strSend.GetLength()+1,0,(SOCKADDR*)&addrTo,sizeof(SOCKADDR));
//清空发送编辑框中的内容
SetDlgItemText(IDC_EDIT_SEND,"");
}
//最后一行的外面
问题五:最后一行的外面提示错误,信息如下;
Error 5 error C1075: end of file found before the left brace '{' at 'c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\chat\chat\chatdlg.cpp(172)' was matched c:\users\administrator.pc-20110905onbv\desktop\demo\vc\dialog\chat\chat\chatdlg.cpp 321 1 Chat
什么原因???怎样修正???
这些错误是什么原因造成的呢?怎样修改???