home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / dialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  3.0 KB  |  82 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : dialog.cpp                                                             //
  10. //  Description: KDialog class                                                       //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define WIN32_EXTRA_LEAN
  16. #define WIN32_LEAN_AND_MEAN
  17.  
  18. #include <windows.h>
  19. #include <assert.h>
  20. #include <tchar.h>
  21. #include <prsht.h>
  22.  
  23. #include "dialog.h"
  24.  
  25.  
  26. BOOL CALLBACK KDialog::DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  27. {
  28.     KDialog * pDialog;
  29.         
  30.     if ( uMsg==WM_INITDIALOG )
  31.     {
  32.         PROPSHEETPAGE       * pPSP = (PROPSHEETPAGE *) lParam;
  33.         _DialogCreateRecord * pDCR = (_DialogCreateRecord *) lParam;
  34.  
  35.         // check for property sheet page, PROPSHEETPAGE struct should be passed
  36.         if ( ! IsBadReadPtr(pPSP, sizeof(PROPSHEETPAGE)) && (pPSP->dwSize == sizeof(PROPSHEETPAGE)) )
  37.         {
  38.             pDialog = (KDialog *) pPSP->lParam;
  39.  
  40.             assert( ! IsBadReadPtr(pDialog, sizeof(KDialog)) );
  41.             SetWindowLong(hWnd, GWL_USERDATA, (LONG) pDialog);
  42.         }
  43.         // check fir our dialog box creation call, _DialogCreateRecord struct should be passed
  44.         else if ( ! IsBadReadPtr(pDCR, sizeof(_DialogCreateRecord)) && (pDCR->marker==CDIALOG_MARKER) )
  45.         {
  46.             pDialog = pDCR->pDialog;
  47.  
  48.             assert( ! IsBadReadPtr(pDialog, sizeof(KDialog)) );
  49.             SetWindowLong(hWnd, GWL_USERDATA, (LONG) pDialog);
  50.         }
  51.         else
  52.             assert(false);
  53.     }       
  54.     else
  55.     {
  56.         // For messages sent after WM_INITDIALOG, pDialog should point to a KDialog instance.
  57.         // But there are 2 messages known to be sent before it: WM_SETFONT, WM_NOTIFYFORMAT. WM_QUERYUISTATE
  58.         // Our implementation can't pass it to the right KDialog::DlgProc.
  59.  
  60. #ifndef WM_QUERYUISTATE
  61. #define WM_QUERYUISTATE 0x129
  62. #endif
  63.  
  64.         switch ( uMsg )
  65.         {
  66.             case WM_SETFONT:
  67.             case WM_NOTIFYFORMAT:
  68.             case WM_QUERYUISTATE:
  69.             case 131:
  70.                 return FALSE;
  71.         }
  72.  
  73.         pDialog = (KDialog *) GetWindowLong(hWnd, GWL_USERDATA);
  74.  
  75.         assert( ! IsBadReadPtr(pDialog, sizeof(KDialog)) );
  76.     }
  77.  
  78.     if ( pDialog )
  79.         return pDialog->DlgProc(hWnd, uMsg, wParam, lParam); // dispatch to KDialog virtual function
  80.     else
  81.         return FALSE;
  82. }