AfxRegisterWndClass 到底有什么作用

doudoushen 2008-10-17 05:15:56
RT,看了解释不能明白 他到底有什么作用和好处
...全文
3258 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
岁月小龙 2011-12-09
  • 打赏
  • 举报
回复
我还是没看明白
neusoftlln 2009-03-11
  • 打赏
  • 举报
回复
AfxRegisterWndClass当然有用了,在用到CreateEx时要用到它返回的ClassName作为参数,不然会有断言,
比如:
lpszClassName = AfxRegisterWndClass(0);
BOOL bRet = CWnd::CreateEx(
NULL,
lpszClassName,
NULL,
WS_POPUP,
0,
0,
100,
60,
pParentWnd->GetSafeHwnd(),
NULL,
NULL);
wltg2001 2008-10-18
  • 打赏
  • 举报
回复
注册窗口类,是MFC的全局函数,和API的RegisterClass()功能一样,很少被用到,因为MFC程序不用自己注册窗口类,SDK程序用不了这个函数
Dan_M 2008-10-18
  • 打赏
  • 举报
回复
AfxRegisterWndClass 注册窗口
hbdycnm 2008-10-17
  • 打赏
  • 举报
回复
首先: 窗口类其实是一个结构体。
registerClass()来注册窗口类。

AfxRegisterWndClass只是一个封装而已。

作用: 没有用。
好处: 没有好处。
基本就不需要用到它。 差不多用用sdk编程的时候才可能有用。
//简单的说就是:系统自己保留了一个表格, 而这个就是往表格上添加了内容。
具体内容是什么呢? WNDCLASS 这个类的成员变量。


fx_guo 2008-10-17
  • 打赏
  • 举报
回复
相当于调用windows编程当中的registerClass()来注册窗口类.建议先学习一下<vc深入详解>
beyound 2008-10-17
  • 打赏
  • 举报
回复
我们看一下它的代码就知道了,就是注册一个窗口类,在内部指定窗口名称,风格,窗口过程函数地址,图标,光标等等相关的东东,最后通过AfxRegisterClass函数里调用API ::RegisterClass(宏对应RegisterClassA(W)) 实现注册的。


LPCTSTR AFXAPI AfxRegisterWndClass(UINT nClassStyle,
HCURSOR hCursor, HBRUSH hbrBackground, HICON hIcon)
{
// Returns a temporary string name for the class
// Save in a CString if you want to use it for a long time
LPTSTR lpszName = AfxGetThreadState()->m_szTempClassName;

// generate a synthetic name for this class
HINSTANCE hInst = AfxGetInstanceHandle();
if (hCursor == NULL && hbrBackground == NULL && hIcon == NULL)
wsprintf(lpszName, _T("Afx:%x:%x"), (UINT)hInst, nClassStyle);
else
wsprintf(lpszName, _T("Afx:%x:%x:%x:%x:%x"), (UINT)hInst, nClassStyle,
(UINT)hCursor, (UINT)hbrBackground, (UINT)hIcon);

// see if the class already exists
WNDCLASS wndcls;
if (::GetClassInfo(hInst, lpszName, &wndcls))
{
// already registered, assert everything is good
ASSERT(wndcls.style == nClassStyle);

// NOTE: We have to trust that the hIcon, hbrBackground, and the
// hCursor are semantically the same, because sometimes Windows does
// some internal translation or copying of those handles before
// storing them in the internal WNDCLASS retrieved by GetClassInfo.
return lpszName;
}

// otherwise we need to register a new class
wndcls.style = nClassStyle;
wndcls.lpfnWndProc = DefWindowProc;
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
wndcls.hInstance = hInst;
wndcls.hIcon = hIcon;
wndcls.hCursor = hCursor;
wndcls.hbrBackground = hbrBackground;
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = lpszName;
if (!AfxRegisterClass(&wndcls))
AfxThrowResourceException();

// return thread-local pointer
return lpszName;
}
doudoushen 2008-10-17
  • 打赏
  • 举报
回复
什么时候 必须要用这个函数注册类

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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