typedef与结构体的问题

gzsdome 2009-01-28 10:18:42
typedef struct tagWNDCLASSA

{

UINT style ;

WNDPROC lpfnWndProc ;

int cbClsExtra ;

int cbWndExtra ;

HINSTANCE hInstance ;

HICON hIcon ;

HCURSOR hCursor ;

HBRUSH hbrBackground ;

LPCSTR lpszMenuName ;

LPCSTR lpszClassName ;

}

WNDCLASSA, * PWNDCLASSA, NEAR * NPWNDCLASSA, FAR * LPWNDCLASSA ;

在这个里,是不是用WNDCLASSA或 * PWNDCLASSA或 NEAR * NPWNDCLASSA或 FAR * LPWNDCLASSA来代替 tagWNDCLASSA
类型?例如可以WNDCLASSA one, * PWndclassA two, NEAR * NPWNDCLASSA three, FAR * LPWNDCLASSA four,这样来创建四个tagWNDCLASSA
类型变量吗?还是怎么样?不明白~
...全文
193 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
YY009 2009-02-03
  • 打赏
  • 举报
回复
tagWNDCLASSA是一个类型,WNDCLASSA, * PWNDCLASSA是变量,tagWNDCLASSA相当于int a中的int,而WNDCLASSA, * PWNDCLASSA相当于a,至于后面的NEAR * NPWNDCLASSA, FAR * LPWNDCLASSA 就不知道了。
wangyaosuper 2009-02-03
  • 打赏
  • 举报
回复
这个可以这样理解,总的来说是一个typedef:

typedef tagWNDCLASSA WNDCLASSA, * PWNDCLASSA, NEAR * NPWNDCLASSA, FAR * LPWNDCLASSA ;



其中呢tagWNDCLASSA
他的声明则是
struct tagWNDCLASSA
{
UINT style ;

WNDPROC lpfnWndProc ;

int cbClsExtra ;

int cbWndExtra ;

HINSTANCE hInstance ;

HICON hIcon ;

HCURSOR hCursor ;

HBRUSH hbrBackground ;

LPCSTR lpszMenuName ;

LPCSTR lpszClassName ;
};
giant7 2009-01-29
  • 打赏
  • 举报
回复
typedef struct _TS1{

int x, y;

} TS1, *PTS1, ***PPPTS1; // TS1是结构体的名称,PTS1是结构体指针的名称

// 也就是将结构体struct _TS1 命名为TS1,

// 将struct _TS1 * 命名为 PTS1

// 将struct _TS1 *** 命名为 PPPTS1

waizqfor 2009-01-28
  • 打赏
  • 举报
回复
参考MSDN

typedef struct {
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
} WNDCLASS, *PWNDCLASS;
Members

style

Specifies the class style(s). This member can be any combination of the Class Styles.

lpfnWndProc

Pointer to the window procedure. You must use the CallWindowProc function to call the window procedure. For more information, see WindowProc.

cbClsExtra

Specifies the number of extra bytes to allocate following the window-class structure. The system initializes the bytes to zero.

cbWndExtra

Specifies the number of extra bytes to allocate following the window instance. The system initializes the bytes to zero. If an application uses WNDCLASS to register a dialog box created by using the CLASS directive in the resource file, it must set this member to DLGWINDOWEXTRA.

hInstance

Handle to the instance that contains the window procedure for the class.

hIcon

Handle to the class icon. This member must be a handle to an icon resource. If this member is NULL, the system provides a default icon.

hCursor

Handle to the class cursor. This member must be a handle to a cursor resource. If this member is NULL, an application must explicitly set the cursor shape whenever the mouse moves into the application's window.

hbrBackground

Handle to the class background brush. This member can be a handle to the physical brush to be used for painting the background, or it can be a color value. A color value must be one of the following standard system colors (the value 1 must be added to the chosen color). If a color value is given, you must convert it to one of the following HBRUSH types:
COLOR_ACTIVEBORDER
COLOR_ACTIVECAPTION
COLOR_APPWORKSPACE
COLOR_BACKGROUND
COLOR_BTNFACE
COLOR_BTNSHADOW
COLOR_BTNTEXT
COLOR_CAPTIONTEXT
COLOR_GRAYTEXT
COLOR_HIGHLIGHT
COLOR_HIGHLIGHTTEXT
COLOR_INACTIVEBORDER
COLOR_INACTIVECAPTION
COLOR_MENU
COLOR_MENUTEXT
COLOR_SCROLLBAR
COLOR_WINDOW
COLOR_WINDOWFRAME
COLOR_WINDOWTEXT
The system automatically deletes class background brushes when the class is unregistered by using UnregisterClass. An application should not delete these brushes.

When this member is NULL, an application must paint its own background whenever it is requested to paint in its client area. To determine whether the background must be painted, an application can either process the WM_ERASEBKGND message or test the fErase member of the PAINTSTRUCT structure filled by the BeginPaint function.

lpszMenuName

Pointer to a null-terminated character string that specifies the resource name of the class menu, as the name appears in the resource file. If you use an integer to identify the menu, use the MAKEINTRESOURCE macro. If this member is NULL, windows belonging to this class have no default menu.

lpszClassName

Pointer to a null-terminated string or is an atom. If this parameter is an atom, it must be a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpszClassName; the high-order word must be zero.
If lpszClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.
The maximum length for lpszClassName is 256.
yangkunhenry 2009-01-28
  • 打赏
  • 举报
回复

WNDCLASSA = struct tagWNDCLASSA;
PWNDCLASSA = struct tagWNDCLASSA *;
NPWNDCLASSA = NEAR struct tagWNDCLASSA *;
LPWNDCLASSA = FAR struct tagWNDCLASSA *;
//后三个都是typedef的指针。

for example:

WNDCLASSA wnd;
struct tagWNDCLASSA wnd
xiaoyisnail 2009-01-28
  • 打赏
  • 举报
回复
WNDCLASSA <=> tagWNDCLASSA
PWNDCLASSA, NPWNDCLASSA, LPWNDCLASSA都是指向tagWNDCLASSA/WNDCLASSA 的指针类型

你可以这样写:

WNDCLASSA wc;
LPWNDCLASSA wp = &wc;

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧