home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SRC / DLGCLR.CP_ / DLGCLR.CP
Encoding:
Text File  |  1993-02-08  |  3.7 KB  |  136 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 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 Microsoft 
  7. // QuickHelp and/or WinHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11.  
  12. #include "stdafx.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 BASED_CODE THIS_FILE[] = __FILE__;
  21. #define new DEBUG_NEW
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Choose Color dialog
  26.  
  27. IMPLEMENT_DYNAMIC(CColorDialog, CDialog)
  28.  
  29. BEGIN_MESSAGE_MAP(CColorDialog, CDialog)
  30.     //{{AFX_MSG_MAP(CColorDialog)
  31.     ON_WM_CTLCOLOR()
  32.     //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34.  
  35. COLORREF AFXAPI_DATA CColorDialog::clrSavedCustom[16] = { RGB(255, 255, 255), 
  36.     RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255),
  37.     RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255),
  38.     RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255),
  39.     RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255),
  40.     RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255) };
  41.  
  42. CColorDialog::CColorDialog(COLORREF clrInit /* = 0 */,
  43.         DWORD dwFlags /* = 0 */, 
  44.         CWnd* pParentWnd /* = NULL */) : CDialog((UINT)0, pParentWnd)
  45. {
  46.     memset(&m_cc, 0, sizeof(m_cc));
  47.     m_nIDHelp = AFX_IDD_COLOR;
  48.  
  49.     m_cc.lStructSize = sizeof(m_cc);
  50.     m_cc.lpCustColors = (COLORREF FAR*)&clrSavedCustom;
  51.     m_cc.Flags = dwFlags | CC_ENABLEHOOK;
  52.     if (_AfxHelpEnabled())
  53.         m_cc.Flags |= CC_SHOWHELP;
  54.     m_cc.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
  55.  
  56.     if ((m_cc.rgbResult = clrInit) != 0)
  57.         m_cc.Flags |= CC_RGBINIT;
  58. }
  59.  
  60. int CColorDialog::DoModal()
  61. {
  62.     ASSERT_VALID(this);
  63.     ASSERT(m_cc.Flags & CC_ENABLEHOOK);
  64.     ASSERT(m_cc.lpfnHook != NULL); // can still be a user hook
  65.  
  66.     m_cc.hwndOwner = _AfxGetSafeOwner(m_pParentWnd);
  67.     _AfxHookWindowCreate(this);
  68.     BOOL bResult = ::ChooseColor(&m_cc);
  69.     _AfxUnhookWindowCreate();   // just in case
  70.     Detach();                   // just in case
  71.  
  72.     return bResult ? IDOK : IDCANCEL;
  73. }
  74.  
  75. BOOL CColorDialog::OnColorOK()
  76. {
  77.     ASSERT_VALID(this);
  78.     // Do not call Default() if you override
  79.     return FALSE;
  80. }
  81.  
  82. void CColorDialog::SetCurrentColor(COLORREF clr)
  83. {
  84.     ASSERT_VALID(this);
  85.     ASSERT(m_hWnd != NULL);
  86.  
  87.     SendMessage(_afxNMsgSETRGB, 0, (DWORD)clr);
  88. }
  89.  
  90. void CColorDialog::OnOK()
  91. {
  92.     // Common dialogs do not require ::EndDialog
  93.     ASSERT_VALID(this);
  94.  
  95.     Default();
  96. }
  97.  
  98. void CColorDialog::OnCancel()
  99. {
  100.     // Common dialogs do not require ::EndDialog
  101.     ASSERT_VALID(this);
  102.     Default();
  103. }
  104.  
  105. // The color tracker in the COMMDLG.DLL can't handle grey backgrounds,
  106. //  so we force the default with this override.
  107.  
  108. HBRUSH CColorDialog::OnCtlColor(CDC*, CWnd*, UINT)
  109. {
  110.     return (HBRUSH)Default();
  111. }
  112.  
  113. ////////////////////////////////////////////////////////////////////////////
  114. // CColorDialog diagnostics
  115.  
  116. #ifdef _DEBUG
  117. void CColorDialog::Dump(CDumpContext& dc) const
  118. {
  119.     ASSERT_VALID(this);
  120.     CDialog::Dump(dc);
  121.     
  122.     AFX_DUMP1(dc, "\nm_cc.hwndOwner = ", (UINT)m_cc.hwndOwner);
  123.     AFX_DUMP1(dc, "\nm_cc.rgbResult = ", (LPVOID)m_cc.rgbResult);
  124.     AFX_DUMP1(dc, "\nm_cc.Flags = ", (LPVOID)m_cc.Flags);
  125.     AFX_DUMP0(dc, "\nm_cc.lpCustColors ");
  126.     for (int iClr = 0; iClr < 16; iClr++)
  127.         AFX_DUMP1(dc, "\n\t", (LPVOID)m_cc.lpCustColors[iClr]);
  128.     if (m_cc.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
  129.         AFX_DUMP0(dc, "\nhook function set to standard MFC hook function");
  130.     else
  131.         AFX_DUMP0(dc, "\nhook function set to non-standard hook function");
  132. }
  133. #endif //_DEBUG
  134.  
  135. ////////////////////////////////////////////////////////////////////////////
  136.