Share via


Registering the Window Class

Every window must have a window class. A window class defines the attributes of a window, such as its style, its icon, its cursor, the name of the menu, and the name of the window procedure.

The first step is to fill in a WNDCLASS structure with class information. Next, you pass the structures to the RegisterClass function. The Generic application registers the GenericAppClass window class as follows.

   WNDCLASS wc;

   if( !hPrevInstance )
   {
      wc.lpszClassName = TEXT("GenericAppClass");
      wc.lpfnWndProc = MainWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
      wc.lpszMenuName = TEXT("GenericAppMenu");
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );
   }

For more information on the menu, see The Menu. For more information on the window procedure, see The Window Procedure.

See Also

Source Code

 

 

Build date: 3/25/2010