Window Creation

A window is created by Presentation Manager in response to the application issuing a WinCreateStdWindow() function call or a WinCreateWindow() call; an example of the WinCreateWindow() call is given in Figure "Sample Application Main Routine (Part 2) - Window Creation".

The first statement in the example specifies the attributes of the frame window, which are contained in the data variable fcdata.flCreateFlags. These values determine the control windows that are created with the frame window (FCF_SYSMENU, FCF_MINMAX etc), and also indicate to Presentation Manager that it should select the position of the window on the desktop (FCF_SHELLPOSITION).

The window is then created in two steps; firstly the frame window is created, with the desktop as its parent, and then the client window is created with the frame window as its parent. The frame window belongs to the system-defined window class WC_FRAME, whereas the client window belongs to an application-defined window class WCP_MAIN, which is assumed to have already been defined to Presentation Manager using a WinRegisterClass() call.

If it is necessary to pass initialization information to a window upon its creation, this may be achieved using the CtlData parameter in the WinCreateWindow() function. This parameter is a 32-bit pointer, which may reference an application-defined data structure. This pointer is passed to the window as the first parameter of the WM_CREATE message. The window may, during its processing of this message, extract the pointer from the message parameter and use it to access the data structure. See Figure "Sample Application Main Routine (Part 2) - Window Creation" for an example of this technique.

When an application requests that Presentation Manager creates a window of a particular class, a message of the system-defined class WM_CREATE is sent to the window procedure associated with that class. The window procedure may capture this message by including a case for it, and perform any processing such as opening files or databases, allocating memory objects and setting instance data to initial default values.

In coding the method for this message class, the first statement should be a call to WinDefWindowProc(), which will enable Presentation Manager to perform default processing and complete the initialization of the window (such as allocating a window handle) before the application-specific processing is carried out. If the default processing is not completed first, the window handle and any window words may not be allocated before the application makes function calls that reference them, thus causing these calls to fail.

Where instance data or resource handles will be used by the window, and must be maintained beyond the processing of a single message, a data structure should be defined to contain these items. Memory for the data structure should be requested from the operating system, and a pointer to the memory object stored in the window words, as part of the WM_CREATE processing. See Instance Data and Window Words for further information.


[Back: Using Windows]
[Next: Window Processing]