dlgclr.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 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. #include "stdafx.h"
  11. #ifdef AFX_AUX_SEG
  12. #pragma code_seg(AFX_AUX_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. #define new DEBUG_NEW
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Choose Color dialog
  21. class _AFX_COLOR_STATE : public CNoTrackObject
  22. {
  23. public:
  24. // custom colors are held here and saved between calls
  25. COLORREF m_crSavedCustom[16];
  26. _AFX_COLOR_STATE();
  27. };
  28. _AFX_COLOR_STATE::_AFX_COLOR_STATE()
  29. {
  30. // custom colors are initialized to white
  31. for (int i = 0; i < _countof(m_crSavedCustom); i++)
  32. m_crSavedCustom[i] = RGB(255, 255, 255);
  33. }
  34. #ifndef _AFX_NO_GRAYDLG_SUPPORT
  35. BEGIN_MESSAGE_MAP(CColorDialog, CCommonDialog)
  36. //{{AFX_MSG_MAP(CColorDialog)
  37. ON_WM_CTLCOLOR()
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. #endif //!_AFX_NO_GRAYDLG_SUPPORT
  41. EXTERN_PROCESS_LOCAL(_AFX_COLOR_STATE, _afxClrState)
  42. CColorDialog::CColorDialog(COLORREF clrInit, DWORD dwFlags,
  43. CWnd* pParentWnd) : CCommonDialog(pParentWnd)
  44. {
  45. memset(&m_cc, 0, sizeof(m_cc));
  46. m_nIDHelp = AFX_IDD_COLOR;
  47. m_cc.lStructSize = sizeof(m_cc);
  48. m_cc.lpCustColors = GetSavedCustomColors();
  49. m_cc.Flags = dwFlags | CC_ENABLEHOOK;
  50. if (!afxData.bWin4 && AfxHelpEnabled())
  51. m_cc.Flags |= CC_SHOWHELP;
  52. m_cc.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
  53. if ((m_cc.rgbResult = clrInit) != 0)
  54. m_cc.Flags |= CC_RGBINIT;
  55. }
  56. int CColorDialog::DoModal()
  57. {
  58. ASSERT_VALID(this);
  59. ASSERT(m_cc.Flags & CC_ENABLEHOOK);
  60. ASSERT(m_cc.lpfnHook != NULL); // can still be a user hook
  61. m_cc.hwndOwner = PreModal();
  62. int nResult = ::ChooseColor(&m_cc);
  63. PostModal();
  64. return nResult ? nResult : IDCANCEL;
  65. }
  66. BOOL CColorDialog::OnColorOK()
  67. {
  68. ASSERT_VALID(this);
  69. // Do not call Default() if you override
  70. return FALSE;
  71. }
  72. void CColorDialog::SetCurrentColor(COLORREF clr)
  73. {
  74. ASSERT_VALID(this);
  75. ASSERT(m_hWnd != NULL);
  76. SendMessage(_afxMsgSETRGB, 0, (DWORD)clr);
  77. }
  78. COLORREF* PASCAL CColorDialog::GetSavedCustomColors()
  79. {
  80. return &_afxClrState->m_crSavedCustom[0];
  81. }
  82. // The color tracker in the COMMDLG.DLL can't handle gray backgrounds,
  83. // so we force the default with this override.
  84. #ifndef _AFX_NO_GRAYDLG_SUPPORT
  85. HBRUSH CColorDialog::OnCtlColor(CDC*, CWnd*, UINT)
  86. {
  87. return (HBRUSH)Default();
  88. }
  89. #endif //!_AFX_NO_GRAYDLG_SUPPORT
  90. ////////////////////////////////////////////////////////////////////////////
  91. // CColorDialog diagnostics
  92. #ifdef _DEBUG
  93. void CColorDialog::Dump(CDumpContext& dc) const
  94. {
  95. CDialog::Dump(dc);
  96. dc << "m_cc.hwndOwner = " << (UINT)m_cc.hwndOwner;
  97. dc << "\nm_cc.rgbResult = " << (LPVOID)m_cc.rgbResult;
  98. dc << "\nm_cc.Flags = " << (LPVOID)m_cc.Flags;
  99. dc << "\nm_cc.lpCustColors ";
  100. for (int iClr = 0; iClr < 16; iClr++)
  101. dc << "\n\t" << (LPVOID)m_cc.lpCustColors[iClr];
  102. if (m_cc.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
  103. dc << "\nhook function set to standard MFC hook function";
  104. else
  105. dc << "\nhook function set to non-standard hook function";
  106. dc << "\n";
  107. }
  108. #endif //_DEBUG
  109. #ifdef AFX_INIT_SEG
  110. #pragma code_seg(AFX_INIT_SEG)
  111. #endif
  112. IMPLEMENT_DYNAMIC(CColorDialog, CDialog)
  113. #pragma warning(disable: 4074)
  114. #pragma init_seg(lib)
  115. PROCESS_LOCAL(_AFX_COLOR_STATE, _afxClrState)
  116. ////////////////////////////////////////////////////////////////////////////