wpRestoreState - Example Code

In this example, wpRestoreState is overridden to restore data from the OS2.INI file.

SOM_Scope void   SOMLINK UserSetTitle(nbk *somSelf,
                                      PSZ pszNewTitle)
{
    nbkData *somThis = nbkGetData(somSelf);
    nbkMethodDebug("nbk","UserSetTitle");

   strcpy ( _title, pszNewTitle );
}
/*
 *    Override of  wpRestoreState method to restore our data
 *    from the OS2.INI file.
 */

SOM_Scope BOOL   SOMLINK wpRestoreState(nbk   *somSelf,
                                        ULONG ulReserved)

{
    BOOL fSuccess;
    ULONG ulCount;
    CHAR buf[40];

    nbkData *somThis = nbkGetData(somSelf);
    nbkMethodDebug("nbk","wpRestoreState");

    ulCount = 40;                              /* Length of data buffer */
    fSuccess = _wpRestoreData ( somSelf        /* Our pointer */
                      , (PSZ) "nbk"            /* Name of class */
                      , WPNBK_KEY              /* Key of data requested */
                      , (PBYTE) &buf           /* Where to put data */
                      , &ulCount   );          /* Length of data returned */

    if ( !fSuccess )
    {
        /* first time the object is being restored */

        /* initialize string to NULL */
        strcpy ( buf, "" );

        /* Save initial string to OS2.INI file */
        _wpSaveData ( somSelf                /* Pointer to ourself */
                    , (PSZ) "nbk"            /* Class name */
                    , WPNBK_KEY              /* Key of data */
                    , (PBYTE) buf            /* Pointer to data */
                    , 40 );                  /* Length of data to write */
    } /* endif */

    _UserSetTitle ( somSelf, buf );

    return (parent_wpRestoreState(somSelf,ulReserved));
}


[Back: wpRestoreState - Related Methods]
[Next: wpRestoreState - Topics]