AfxRegisterClass

使用此功能注册窗口类在使用 MFC 的 DLL。

BOOL AFXAPI AfxRegisterClass(
   WNDCLASS* lpWndClass 
);

参数

  • lpWndClass
    对包含有关窗口类的 WNDCLASS 结构的指针信息将注册。 有关此结构的更多信息,请参见 Windows SDK。

返回值

TRUE ,如果类成功签入;否则 FALSE

备注

如果使用此功能,类将自动中注销,当卸载 DLL 时。

在非 DLL 生成,因为,在应用程序注册的类将自动中注销, AfxRegisterClass 标识符定义为宏传递到函数 RegisterClass的映射。 如果使用 AfxRegisterClass 而不是 RegisterClass,您的代码来使用,而不需要对应用程序和在 DLL 中。

示例

// Register your unique class name that you wish to use
WNDCLASS wndcls;

memset(&wndcls, 0, sizeof(WNDCLASS));   // start with NULL defaults

wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;

//you can specify your own window procedure
wndcls.lpfnWndProc = ::DefWindowProc; 
wndcls.hInstance = AfxGetInstanceHandle();
wndcls.hIcon = LoadIcon(wndcls.hInstance, MAKEINTRESOURCE(IDI_MYICON));
wndcls.hCursor = LoadCursor(wndcls.hInstance, MAKEINTRESOURCE(IDC_ARROW));
wndcls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndcls.lpszMenuName = NULL;

// Specify your own class name for using FindWindow later
wndcls.lpszClassName = _T("MyNewClass");

// Register the new class and trace if it fails
if(!AfxRegisterClass(&wndcls))
{
   TRACE("Class Registration Failed\n");
}

要求

Header: afxwin.h

请参见

概念

MFC宏和Globals