home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / DLGCOMM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  4.2 KB  |  157 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12. #include <dlgs.h>
  13.  
  14. #ifdef AFX_AUX_SEG
  15. #pragma code_seg(AFX_AUX_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. #define new DEBUG_NEW
  24.  
  25. static const UINT nMsgLBSELCHANGE = ::RegisterWindowMessage(LBSELCHSTRING);
  26. static const UINT nMsgSHAREVI = ::RegisterWindowMessage(SHAREVISTRING);
  27. static const UINT nMsgFILEOK = ::RegisterWindowMessage(FILEOKSTRING);
  28. static const UINT nMsgCOLOROK = ::RegisterWindowMessage(COLOROKSTRING);
  29. static const UINT nMsgHELP = ::RegisterWindowMessage(HELPMSGSTRING);
  30. const UINT _afxNMsgSETRGB = ::RegisterWindowMessage(SETRGBSTRING);
  31.  
  32. BEGIN_MESSAGE_MAP(CCommonDialog, CDialog)
  33.     //{{AFX_MSG_MAP(CCommonDialog)
  34.     ON_WM_HELPINFO()
  35.     //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37.  
  38. UINT CALLBACK
  39. _AfxCommDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  40. {
  41.     if (hWnd == NULL)
  42.         return 0;
  43.  
  44.     _AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
  45.     if (pThreadState->m_pAlternateWndInit != NULL)
  46.     {
  47.         ASSERT_KINDOF(CFileDialog,pThreadState->m_pAlternateWndInit);
  48.         pThreadState->m_pAlternateWndInit->SubclassWindow(hWnd);
  49.         pThreadState->m_pAlternateWndInit = NULL;
  50.     }
  51.     ASSERT(pThreadState->m_pAlternateWndInit == NULL);
  52.  
  53.     if (message == WM_INITDIALOG)
  54.         return (UINT)AfxDlgProc(hWnd, message, wParam, lParam);
  55.  
  56.     if (message == nMsgHELP ||
  57.        (message == WM_COMMAND && LOWORD(wParam) == pshHelp))
  58.     {
  59.         // just translate the message into the AFX standard help command.
  60.         SendMessage(hWnd, WM_COMMAND, ID_HELP, 0);
  61.         return 1;
  62.     }
  63.  
  64.     if (message < 0xC000)
  65.     {
  66.         // not a ::RegisterWindowMessage message
  67.         return 0;
  68.     }
  69.  
  70.     // assume it is already wired up to a permanent one
  71.     CDialog* pDlg = (CDialog*)CWnd::FromHandlePermanent(hWnd);
  72.     ASSERT(pDlg != NULL);
  73.     ASSERT_KINDOF(CDialog, pDlg);
  74.  
  75.     if (pDlg->IsKindOf(RUNTIME_CLASS(CFileDialog)))
  76.     {
  77.         // If we're exploring then we are not interested in the Registered messages
  78.         if (((CFileDialog*)pDlg)->m_ofn.Flags & OFN_EXPLORER)
  79.             return 0;
  80.     }
  81.  
  82.     // RegisterWindowMessage - does not copy to lastState buffer, so
  83.     // CWnd::GetCurrentMessage and CWnd::Default will NOT work
  84.     // while in these handlers
  85.  
  86.     // Dispatch special commdlg messages through our virtual callbacks
  87.     if (message == nMsgSHAREVI)
  88.     {
  89.         ASSERT_KINDOF(CFileDialog, pDlg);
  90.         return ((CFileDialog*)pDlg)->OnShareViolation((LPCTSTR)lParam);
  91.     }
  92.     else if (message == nMsgFILEOK)
  93.     {
  94.         ASSERT_KINDOF(CFileDialog, pDlg);
  95.  
  96.         if (afxData.bWin4)
  97.             ((CFileDialog*)pDlg)->m_pofnTemp = (OPENFILENAME*)lParam;
  98.  
  99.         BOOL bResult = ((CFileDialog*)pDlg)->OnFileNameOK();
  100.  
  101.         ((CFileDialog*)pDlg)->m_pofnTemp = NULL;
  102.  
  103.         return bResult;
  104.     }
  105.     else if (message == nMsgLBSELCHANGE)
  106.     {
  107.         ASSERT_KINDOF(CFileDialog, pDlg);
  108.         ((CFileDialog*)pDlg)->OnLBSelChangedNotify(wParam, LOWORD(lParam),
  109.                 HIWORD(lParam));
  110.         return 0;
  111.     }
  112.     else if (message == nMsgCOLOROK)
  113.     {
  114.         ASSERT_KINDOF(CColorDialog, pDlg);
  115.         return ((CColorDialog*)pDlg)->OnColorOK();
  116.     }
  117.     else if (message == _afxNMsgSETRGB)
  118.     {
  119.         // nothing to do here, since this is a SendMessage
  120.         return 0;
  121.     }
  122.     return 0;
  123. }
  124.  
  125. ////////////////////////////////////////////////////////////////////////////
  126. // CCommonDialog - common dialog helper class
  127.  
  128. void CCommonDialog::OnOK()
  129. {
  130.     ASSERT_VALID(this);
  131.  
  132.     if (!UpdateData(TRUE))
  133.     {
  134.         TRACE0("UpdateData failed during dialog termination.\n");
  135.         // the UpdateData routine will set focus to correct item
  136.         return;
  137.     }
  138.  
  139.     // Common dialogs do not require ::EndDialog
  140.     Default();
  141. }
  142.  
  143. void CCommonDialog::OnCancel()
  144. {
  145.     ASSERT_VALID(this);
  146.  
  147.     // Common dialogs do not require ::EndDialog
  148.     Default();
  149. }
  150.  
  151. BOOL CCommonDialog::OnHelpInfo(HELPINFO*)
  152. {
  153.     return Default();
  154. }
  155.  
  156. ////////////////////////////////////////////////////////////////////////////
  157.