This example shows a typical initialization function for a window. The function first registers the window class, then calls WinCreateStdWindow to create a standard window and returns immediately if the function fails. Otherwise, it continues on to do other initialization processing. Note: The FCF_STANDARD constant can only be used if you have all the resources in defines. If you use this constant without an accelerator table for example, the function will fail.

#define INCL_WINFRAMEMGR        /* Window Frame Functions       */
#include <os2.h>
#define IDM_RESOURCE 1
HAB   hab;              /* Anchor-block handle                  */
CHAR szClassName[] = "Generic"; /* window class name            */
HWND hwndClient;        /* handle to the client                 */
HWND hwndFrame;         /* handle to the frame                  */
PFNWP GenericWndProc;
BOOL GenericInit()
{
    ULONG flStyle;

    flStyle = FCF_STANDARD;
    if (!WinRegisterClass(hab, szClassName, GenericWndProc, 0L, 0))
        return (FALSE);

    hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
        0L,                     /* frame-window style            */
        &flStyle,               /* window style                  */
        szClassName,            /* class name                    */
        "Generic Application",  /* window title                  */
        0L,                     /* default client style          */
        NULLHANDLE,             /* resource in executable file   */
        IDM_RESOURCE,           /* resource id                   */
        &hwndClient);           /* receives client window handle */

    if (!hwndFrame)
        return (FALSE);
    else {
        .
        . /* other initialization code */
        .


[Back] [Next]