64,676
社区成员
发帖
与我相关
我的任务
分享
void CTcpclientDlg::OnBnClickedConnet()
{
CString str,str1,worn;//定义字符串
int port;//定义端变量
GetDlgItem(IDC_ADDR)->GetWindowText(str); //获取地址
GetDlgItem(IDC_PORT)->GetWindowText(str1);//获取端口
if (str==""||str1=="")
{
worn="服务地址或端口号不能为空";
MessageBox(worn);
}
else
{
port=atoi(str1.GetBuffer(1));
addr.sin_family=AF_INET;
addr.sin_addr.S_un.S_addr=inet_addr(str.GetBuffer(1));
}
数据类型
本章列出了微软基础类库中最常见的数据类型。大多数数据类型是与Windows软件开发工具包(SDK)中一致的,也有一些是MFC独有的。
下面的数据类型是Windows SDK 和MFC共用的: · BOOL 布尔值。
· BSTR 32位字符指针。
· BYTE 8位无符号整数。
· COLORREF 用作颜色值的32位值。
· DWORD 32位无符号整数,或者是段地址以及与之相关的偏移量。
· LONG 32位带符号整数。
· LPARAM 32位值,作为参数传递给一个窗口过程或者回调函数。
· LPCSTR 指向字符串常量的32位指针。
· LPSTR 指向字符串的32位指针。
· LPCTSTR 指向一个兼容 Unicode 和 DBCS 的字符串的32位指针。
· LPTSTR 指向一个兼容 Unicode 和 DBCS 的字符串的32位指针。
· LPVOID 指向一个未指定类型的32位指针。
· LRESULT 窗口过程或者回调函数返回的32位值。
· UINT 在Windows 3.0和3.1中表示16位的无符号整数,在Win32中表示32位的无符号整数。
· WNDPROC 指向一个窗口过程的32位指针。
· WORD 16位无符号整数。
· WPARAM 作为参数传递给窗口函数或者回调函数的值:在Windows 3.0和3.1 中为16位,在Win32中为32位。
微软基础类库中独有的数据类型如下: · POSITION 用于标记集合中一个元素的位置的值;被MFC中的集合类所使用。
· LPCRECT 指向一个RECT结构体常量(不能修改)的32位指针。
在《Win32 SDK 程序员参考》的“数据类型”部分,有个不太通用的数据类型的列表。
CString
CString does not have a base class.
A CString object consists of a variable-length sequence of characters. CString provides functions and operators using a syntax similar to that of Basic. Concatenation and comparison operators, together with simplified memory management, make CString objects easier to use than ordinary character arrays.
CString is based on the TCHAR data type. If the symbol _UNICODE is defined for your program, TCHAR is defined as type wchar_t, a 16-bit character type; otherwise, it is defined as char, the normal 8-bit character type. Under Unicode, then, CString objects are composed of 16-bit characters. Without Unicode, they are composed of 8-bit char type.
When not using _UNICODE, CString is enabled for multibyte character sets (MBCS, also known as double-byte character sets, DBCS). Note that for MBCS strings, CString still counts, returns, and manipulates strings based on 8-bit characters, and your application must interpret MBCS lead and trail bytes itself.
CString objects also have the following characteristics:
CString objects can grow as a result of concatenation operations.
CString objects follow “value semantics.” Think of a CString object as an actual string, not as a pointer to a string.
You can freely substitute CString objects for const char* and LPCTSTR function arguments.
A conversion operator gives direct access to the string’s characters as a read-only array of characters (a C-style string).