Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
AfxRegisterClass
TRY
Collapse the table of content
Expand the table of content

AfxRegisterClass

Use this function to register window classes in a DLL that uses MFC.

BOOL AFXAPI AfxRegisterClass(
   WNDCLASS* lpWndClass 
);

lpWndClass

Pointer to a WNDCLASS structure containing information about the window class to be registered. For more information on this structure, see the Windows SDK.

TRUE if the class is successfully registered; otherwise FALSE.

If you use this function, the class is automatically unregistered when the DLL is unloaded.

In non-DLL builds, the AfxRegisterClass identifier is defined as a macro that maps to the Windows function RegisterClass, since classes registered in an application are automatically unregistered. If you use AfxRegisterClass instead of RegisterClass, your code can be used without change both in an application and in a 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

Community Additions

ADD
Show:
© 2015 Microsoft