Using Dialogs in System Object Model Objects

In the folder example, a dialog box is used to prompt the user for the folder's password, and for the user to enter the password. Creating and invoking the dialog is done in the normal way. However, invoking an object's methods from within a dialog procedure requires that the dialog procedure know the pointer to the object that invokes the method (that is, somSelf). This is done through the use of the pCreateParams parameter of the WinDialogBox() function. In this way, the pointer to somSelf is passed to the dialog procedure as follows:

   pCreateParams = (PVOID)somSelf;

The dialog procedure may then store the pointer in the reserved window word QWL_USER:

    case WM_INITDLG:
         WinSetWindowULong(hwndDlg,      /* Set window word           */
                           QWL_USER,     /* Offset of window word     */
                           (ULONG) mp2); /* Value to be stored        */
        break;

When an instance method must be invoked from the dialog procedure, the object pointer may easily be retrieved from the window words and used to invoke the method.

   {
      PWFolder *aPWF;                         /* Object pointer       */

      PWF_INFO pwfolderInfo;                  /* Folder info struct   */

      aPWF = (PWFolder *)WinQueryWindowULong( /* Get object pointer   */
                            hwndDlg,          /* Dialog box handle    */
                            QWL_USER);        /* Offset of win word   */

      _QueryInfo(                             /* Invoke method        */
                 aPWF,                        /* Object pointer       */
                 &pwfolderInfo);              /* Folder info struct   */
   }

In the above example, a WinQueryWindowULong() call is used to retrieve the object pointer from the window word, and store it in aPWF. This variable is then used as the first parameter when invoking the method _QueryInfo.

Note that the method name _QueryInfo is in fact fully defined as pwfolder_QueryInfo. However, as noted in C Implementation of an Object Class, the SOM Precompiler automatically generates a macro to define the abbreviated form of the function name, in order to avoid the necessity for the programmer to type the full name.


[Back: Presentation Manager Resources in a DLL]
[Next: Summary]