home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / advframe / tstdlg / dialog.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  3.6 KB  |  125 lines

  1. //************************************************************
  2. // Advanced Frame - Dialog Window Example
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //************************************************************
  8. #include <ibase.hpp>
  9. #ifdef IC_PM
  10.   #define INCL_WIN
  11.   #include <os2.h>
  12. #else
  13.   #include <windows.h>
  14. #endif
  15.  
  16. #include "dialog.hpp"
  17. #include "dlghndlr.hpp"
  18.  
  19. #include <ithread.hpp>
  20.  
  21. DialogWindow::DialogWindow( const IResourceId& resId,
  22.                             IWindow*           owner,
  23.                             IWinProc*          dlgProc,
  24.                             void*              pCreateParms )
  25.   : IFrameWindow( deferCreation )
  26.   {
  27.   this->loadDialog( resId, owner, dlgProc, pCreateParms );
  28.   }
  29.  
  30. struct DialogParms {
  31.   DialogHandler
  32.    &dlgHandler;
  33.   void
  34.    *pCreateParms;
  35. };
  36.  
  37. #ifdef IC_PM
  38.  
  39. static void * _System dialogProc( unsigned long  hwnd,
  40.                                   unsigned long  eventId,
  41.                                   void          *parm1,
  42.                                   void          *parm2 )
  43.   {
  44.   if ( eventId == WM_INITDLG )
  45.     {
  46.     DialogParms
  47.      *p = (DialogParms*)parm2;
  48.     DialogInitEvent
  49.       initEvent( IEvent( hwnd,
  50.                          eventId,
  51.                          parm1,
  52.                          p->pCreateParms ) );
  53.     // Dispatch handler and check result.
  54.     if ( p->dlgHandler.initialize( initEvent ) )
  55.       // Do not pass the event on; the result is in the event.
  56.       return initEvent.result();
  57.     else
  58.       // Pass the event to the default dialog procedure.
  59.       return WinDefDlgProc( hwnd,
  60.                             eventId,
  61.                             parm1,
  62.                             p->pCreateParms );
  63.     }
  64.   else
  65.     return WinDefDlgProc( hwnd, eventId, parm1, parm2 );
  66.   }
  67.  
  68. #else
  69.  
  70. static void* CALLBACK dialogProc( void*          hwnd,
  71.                                   unsigned long  eventId,
  72.                                   void*          parm1,
  73.                                   void*          parm2 )
  74.   {
  75.   if ( eventId == WM_INITDIALOG )
  76.     {
  77.     DialogParms
  78.      *p = (DialogParms*)parm2;
  79.     DialogInitEvent
  80.       initEvent( IEvent( hwnd,
  81.                          eventId,
  82.                          parm1,
  83.                          p->pCreateParms ) );
  84.     // Dispatch handler and check result.
  85.     if ( p->dlgHandler.initialize( initEvent ) )
  86.       // Do not pass event on; the result is in the event.
  87.       return initEvent.result();
  88.     }
  89.   // Return 0 because the message is not processed.
  90.   return 0;
  91.   }
  92.  
  93. #endif
  94.  
  95. DialogWindow::DialogWindow( const IResourceId& resId,
  96.                             IWindow*           owner,
  97.                             DialogHandler&     dlgHandler,
  98.                             void*              pCreateParms )
  99.   : IFrameWindow( deferCreation )
  100.   {
  101.   DialogParms
  102.     parms = { dlgHandler, pCreateParms };
  103.   this->loadDialog( resId, owner, dialogProc, &parms );
  104.   this->addHandler( &dlgHandler );
  105.   }
  106.  
  107. void DialogWindow::loadDialog( const IResourceId& resId,
  108.                                IWindow*           owner,
  109.                                IWinProc*          dlgProc,
  110.                                void*              pCreateParms )
  111.   {
  112.   IThread::current().initializeGUI();
  113.  
  114.   const IResourceLibrary
  115.    &resLib = resId.resourceLibrary();
  116.   IWindowHandle
  117.     dlg = resLib.loadDialog( resId.id(),
  118.                              0,
  119.                              owner,
  120.                              dlgProc,
  121.                              pCreateParms );
  122.   start( dlg );
  123.   }
  124.  
  125.