AfxRegisterClass

Utilizzare questa funzione per registrare le classi della finestra in una DLL che utilizza MFC.

BOOL AFXAPI AfxRegisterClass(
   WNDCLASS* lpWndClass 
);

Parametri

  • lpWndClass
    Puntatore a una struttura di WNDCLASS che contiene informazioni sulla classe della finestra da registrare.Per ulteriori informazioni sulla struttura, vedere Windows SDK.

Valore restituito

TRUE se la classe correttamente è registrata; in caso contrario FALSE.

Note

Se si utilizza questa funzione, la classe viene automaticamente annullata la registrazione quando la DLL viene scaricato.

Nelle compilazioni di non DLL, l'identificatore di AfxRegisterClass viene definito come macro che esegue il mapping alla funzione Windows RegisterClass, poiché le classi registrate in un'applicazione vengono automaticamente si annulla la registrazione.Se si utilizza AfxRegisterClass anziché RegisterClass, il codice può essere utilizzato senza modifica sia in un'applicazione che in una DLL.

Esempio

// 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");
}

Requisiti

Header: afxwin.h

Vedere anche

Concetti

Macro MFC e Globals