Previous: 6.3. Designing a Window Procedure To the Table of Contents Next: 6.5. Example of Win32 GUI Application
6.3. Designing a Window Procedure Table of Contents 6.5. Example of Win32 GUI Application

- 6.4. -
Table of Contents
6. Win32 Programming
6.4. Associating a Window Procedure with a Window Class


6.4. Associating a Window Procedure with a Window Class


One associates a window procedure with a window class when registering the class. You must fill a TWndClass structure (WIN32.HLP) with information about the class, and the lpfnWndProc member must specify the address of the window procedure. To register the class, pass the address of TWndClass structure to the RegisterClass function (WIN32.HLP). Once the window class is registered, the window procedure is automatically associated with each new window created with that class.

The following example shows how to associate the window procedure in the previous example with a window class:
var
  wc: TWndClass; 
begin
  // Register the main window class.
  with wc do begin
    style := CS_HREDRAW or CS_VREDRAW; 
    lpfnWndProc := @MainWndProc; 
    cbClsExtra := 0; 
    cbWndExtra := 0; 
    hInstance := System.hInstance; 
    hIcon := LoadIcon(THandle(NIL), IDI_APPLICATION);

    hCursor := LoadCursor(THandle(NIL), IDC_ARROW); 
    hbrBackground := GetStockObject(WHITE_BRUSH); 
    lpszMenuName :=  'MainMenu'; 
    lpszClassName := 'MainWindowClass'; 
  end; 

  if not RegisterClass(wc) then MyError; 

  // Process other messages.

end.






Previous: 6.3. Designing a Window Procedure To the Table of Contents Next: 6.5. Example of Win32 GUI Application
6.3. Designing a Window Procedure Table of Contents 6.5. Example of Win32 GUI Application

- 6.4. -