MFC を使用する DLL にウィンドウ クラスを登録するために使用します。
BOOL AFXAPI AfxRegisterClass(
WNDCLASS* lpWndClass
);
パラメーター
- lpWndClass
登録するウィンドウ クラスに関する WNDCLASS の含む構造体の情報へのポインター。この構造体の詳細については、Windows SDK を参照してください。
戻り値
クラスが正常に登録された場合TRUE ; それ FALSE。
解説
この関数を使用した場合、クラスは自動的に DLL がアンロードされると登録を解除されます。
非 DLL のビルドでは、 AfxRegisterClass の ID はマクロとアプリケーションに登録されているクラスが自動的に登録を解除するため、ウィンドウ RegisterClass関数に割り当てます定義されます。RegisterClassの代わりに AfxRegisterClass を使用すると、コードはアプリケーションと 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");
}
必要条件
ヘッダー: afxwin.h