读书人

求一段E文翻译,该如何解决

发布时间: 2012-01-23 21:57:28 作者: rapoo

求一段E文翻译
CreateWindow
lpClassName

[in] Pointer to a null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero. If lpClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, provided that the module that registers the class is also the module that creates the window. The class name can also be any of the predefined system class names. For a list of system class names, see the Remarks section.

[解决办法]
lpClassName指向一个以null结束的字符串,或一个类的原子(?),创建于先前调用的RegisterClass或RegisterClassEx函数.如果lpClassName是原子,则原子在lpClassName的低字节处,高字节为0.如果lpClassName为字符串,则它为某个窗口类的名字.这个类名,可以是由RegisterClass或RegisterClassEx注册的,它既是类名也是窗口的名字.类名也可以是系统预定义的类名之一.要看系统预定义的类的名字列表,请看remark段.
[解决办法]
也就是说,你调用createWindow时,必须传入一个已经注册过的类,你可以直接传入类名,也可以传入代表这个类名的原子值,原子值和类名是对应的,并且是唯一的。
[解决办法]
atom是类似句柄的一个东西。
[解决办法]
An atom table is a system-defined table that stores strings and corresponding identifiers. An application places a string in an atom table and receives a 16-bit integer, called an atom, that can be used to access the string. A string that has been placed in an atom table is called an atom name.


[解决办法]
第一,你在createwindow时传入的参数,系统如何知道是string还是atom,这需要区别。
第二,lpClassName是一个指针,指针是32位的,而atom是16位的。

综上,为了区别字符串和atom,所以M$的开发人员规定,如果你传入的指针高位为0,那说明它实际是一个atom,而不是一个指向一串以0结尾的字符。

实际在使用资源时,这种约定在大量的使用。

当然,由于某些原因,普通的字符串指针的高位是不会为0的。具体原因就留给楼下的高手来回答吧,嘿嘿
[解决办法]
The most typical use for atoms is in Dynamic Data Exchange (DDE) applications. In the DDE protocol, applications use global atoms to identify the applications exchanging data, the nature of the data being exchanged, and the actual data items being exchanged.

查MSDN,有很多示例程序。
[解决办法]
ATOM rc;
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style= CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc= (WNDPROC)WndProc;
wcex.cbClsExtra= 0;
wcex.cbWndExtra= 16;
wcex.hInstance= hInstance;
wcex.hIcon= LoadIcon(NULL, (LPCTSTR)IDI_WINLOGO);
wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName= (LPCSTR)IDC_TEST;
wcex.lpszClassName= szWindowClass;
wcex.hIconSm= LoadIcon(NULL, (LPCTSTR)IDI_WINLOGO);

rc=RegisterClassEx(&wcex);

if(rc)
{
hFrame=CreateWindowEx(0, (LPCTSTR)rc, szWindowName, 1 < <31, 0, 1 < <31, 0,
(HWND)NULL, (HMENU)NULL, hInstance, 0L);


...
}
[解决办法]
CreateWindowEx比CreateWindow多了一个参数。

读书人网 >VC/MFC

热点推荐