ChildView.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:8k
源码类别:

界面编程

开发平台:

Visual C++

  1. // ChildView.cpp : implementation of the CChildView class
  2. //
  3. #include "stdafx.h"
  4. #include "MDI.h"
  5. #include "ChildView.h"
  6. #if !defined(__EXT_MEMORY_DC_H)
  7. #include <../Src/ExtMemoryDC.h>
  8. #endif
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CChildView
  16. CChildView::CChildView()
  17. : m_bSyncingValues( false )
  18. , m_bColorControlsVisible( false )
  19. {
  20. }
  21. CChildView::~CChildView()
  22. {
  23. }
  24. BEGIN_MESSAGE_MAP(CChildView,CWnd )
  25. //{{AFX_MSG_MAP(CChildView)
  26. ON_WM_PAINT()
  27. ON_WM_ERASEBKGND()
  28. ON_WM_CREATE()
  29. ON_COMMAND(ID_VIEW_COLOR_CONTROLS, OnViewColorControls)
  30. ON_UPDATE_COMMAND_UI(ID_VIEW_COLOR_CONTROLS, OnUpdateViewColorControls)
  31. //}}AFX_MSG_MAP
  32. ON_REGISTERED_MESSAGE(CExtColorCtrl::g_nMsgColorChanged,OnColorChanged)
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CChildView message handlers
  36. BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
  37. {
  38. if( ! CWnd::PreCreateWindow( cs ) )
  39. return FALSE;
  40. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  41. cs.style &= ~WS_BORDER;
  42. cs.dwExStyle &= ~(WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME);
  43. cs.lpszClass =
  44. AfxRegisterWndClass(
  45. CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
  46. ::LoadCursor( NULL, IDC_ARROW ),
  47. HBRUSH(COLOR_WINDOW+1),
  48. NULL
  49. );
  50. return TRUE;
  51. }
  52. void CChildView::OnPaint() 
  53. {
  54. CRect rcClient;
  55. GetClientRect( &rcClient );
  56. CPaintDC dcPaint( this );
  57. CExtPaintManager::stat_ExcludeChildAreas(
  58. dcPaint.GetSafeHdc(),
  59. GetSafeHwnd()
  60. );
  61. CExtMemoryDC dc( &dcPaint, &rcClient );
  62. g_PaintManager->PaintDocumentClientAreaBkgnd( dc, this );
  63. CGdiObject * pOld0, * pOld1;
  64. CExtWndShadow _shadow1, _shadow2, _shadow3, _shadow4;
  65. WORD _PatternBits0[8],_PatternBits1[8];
  66. for( INT iPatternLine=0; iPatternLine < 8; iPatternLine++ )
  67. {
  68. _PatternBits0[iPatternLine] =
  69. ( iPatternLine & 1 )
  70. ? WORD(0xFFFF)
  71. : WORD( ~ ( 5<<iPatternLine ) )
  72. ;
  73. _PatternBits1[iPatternLine] =
  74. ( iPatternLine & 1 )
  75. ? WORD(0xFFFF)
  76. : WORD( ~ ( 1<<(8-iPatternLine) ) )
  77. ;
  78. }
  79. CBitmap bmpPattern0,bmpPattern1;
  80. CBrush brPattern0,brPattern1;
  81. VERIFY( bmpPattern0.CreateBitmap(8,8,1,1,_PatternBits0) );
  82. VERIFY( bmpPattern1.CreateBitmap(8,8,1,1,_PatternBits1) );
  83. VERIFY( brPattern0.CreatePatternBrush(&bmpPattern0) );
  84. VERIFY( brPattern1.CreatePatternBrush(&bmpPattern1) );
  85. CRect rcPattern0(10,10,180,150), rcPattern1(40,30,80,200);
  86. dc.FillRect(rcPattern0,&brPattern0);
  87. _shadow1.Paint(
  88. NULL,
  89. dc, rcPattern0, CRect(0,0,0,0), CRect(0,0,0,0),
  90. CExtWndShadow::DEF_SHADOW_SIZE,
  91. CExtWndShadow::DEF_BRIGHTNESS_MIN, CExtWndShadow::DEF_BRIGHTNESS_MAX,
  92. false
  93. );
  94. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  95. pOld1 = dc.SelectStockObject( BLACK_PEN );
  96. dc.Rectangle( rcPattern0 );
  97. if( pOld0 != NULL )
  98. dc.SelectObject( pOld0 );
  99. if( pOld1 != NULL )
  100. dc.SelectObject( pOld1 );
  101. dc.FillRect(rcPattern1,&brPattern1);
  102. _shadow2.Paint(
  103. NULL,
  104. dc, rcPattern1, CRect(0,0,0,0), CRect(0,0,0,0),
  105. CExtWndShadow::DEF_SHADOW_SIZE,
  106. CExtWndShadow::DEF_BRIGHTNESS_MIN, CExtWndShadow::DEF_BRIGHTNESS_MAX,
  107. false
  108. );
  109. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  110. pOld1 = dc.SelectStockObject( BLACK_PEN );
  111. dc.Rectangle( rcPattern1 );
  112. if( pOld0 != NULL )
  113. dc.SelectObject( pOld0 );
  114. if( pOld1 != NULL )
  115. dc.SelectObject( pOld1 );
  116. CRect rc0(20,50,160,80);
  117. CRect rc1(160,50,210,80);
  118. CRect rc2(rc0.left,rc0.top,rc1.right,rc1.bottom);
  119. COLORREF clrLeft = RGB(0,255,0);
  120. COLORREF clrMiddle = RGB(255,255,0);
  121. COLORREF clrRight = RGB(255,0,0);
  122. CExtPaintManager::stat_PaintGradientRect(
  123. dc, rc0, clrLeft, clrMiddle );
  124. CExtPaintManager::stat_PaintGradientRect(
  125. dc, rc1, clrMiddle,clrRight );
  126. _shadow3.Paint(
  127. NULL,
  128. dc, rc2, CRect(0,0,0,0), CRect(0,0,0,0),
  129. CExtWndShadow::DEF_SHADOW_SIZE,
  130. CExtWndShadow::DEF_BRIGHTNESS_MIN, CExtWndShadow::DEF_BRIGHTNESS_MAX,
  131. false
  132. );
  133. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  134. pOld1 = dc.SelectStockObject( BLACK_PEN );
  135. dc.Rectangle(rc2);
  136. if( pOld0 != NULL )
  137. dc.SelectObject( pOld0 );
  138. if( pOld1 != NULL )
  139. dc.SelectObject( pOld1 );
  140. CRect rc3(120,40,150,80);
  141. CRect rc4(120,80,150,160);
  142. CRect rc5(rc3.left,rc3.top,rc4.right,rc4.bottom);
  143. COLORREF clrUpper = RGB(255,0,255);
  144. COLORREF clrMiddleV = RGB(255,255,255);
  145. COLORREF clrLower = RGB(0,0,255);
  146. CExtPaintManager::stat_PaintGradientRect(
  147. dc, rc3, clrMiddleV, clrUpper, TRUE );
  148. CExtPaintManager::stat_PaintGradientRect(
  149. dc, rc4, clrLower, clrMiddleV, TRUE );
  150. _shadow4.Paint(
  151. NULL,
  152. dc, rc5, CRect(0,0,0,0), CRect(0,0,0,0),
  153. CExtWndShadow::DEF_SHADOW_SIZE,
  154. CExtWndShadow::DEF_BRIGHTNESS_MIN, CExtWndShadow::DEF_BRIGHTNESS_MAX,
  155. false
  156. );
  157. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  158. pOld1 = dc.SelectStockObject( BLACK_PEN );
  159. dc.Rectangle(rc5);
  160. if( pOld0 != NULL )
  161. dc.SelectObject( pOld0 );
  162. if( pOld1 != NULL )
  163. dc.SelectObject( pOld1 );
  164. }
  165. BOOL CChildView::OnEraseBkgnd(CDC* pDC) 
  166. {
  167. pDC;
  168. return TRUE;
  169. }
  170. int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  171. {
  172. if( CWnd ::OnCreate(lpCreateStruct) == -1 )
  173. return -1;
  174. VERIFY(
  175. m_wndColorCtrlCubeRGB_R.Create(
  176. _T("BUTTON"),
  177. _T(""),
  178. WS_CHILD,
  179. CRect(10,210,230,410),
  180. this,
  181. 0x200
  182. )
  183. );
  184. m_wndColorCtrlCubeRGB_R = CExtColorCtrl::MODE_XYZ_R;
  185. VERIFY(
  186. m_wndColorCtrlCubeRGB_G.Create(
  187. _T("BUTTON"),
  188. _T(""),
  189. WS_CHILD,
  190. CRect(240,210,460,410),
  191. this,
  192. 0x201
  193. )
  194. );
  195. m_wndColorCtrlCubeRGB_G = CExtColorCtrl::MODE_XYZ_G;
  196. VERIFY(
  197. m_wndColorCtrlCubeRGB_B.Create(
  198. _T("BUTTON"),
  199. _T(""),
  200. WS_CHILD,
  201. CRect(470,210,690,410),
  202. this,
  203. 0x202
  204. )
  205. );
  206. m_wndColorCtrlCubeRGB_B = CExtColorCtrl::MODE_XYZ_B;
  207. VERIFY(
  208. m_wndColorCtrlHSL_BH.Create(
  209. _T("BUTTON"),
  210. _T(""),
  211. WS_CHILD,
  212. CRect(470,10,690,200),
  213. this,
  214. 0x203
  215. )
  216. );
  217. m_wndColorCtrlHSL_BH = CExtColorCtrl::MODE_HSL_BASIC_HUE;
  218. VERIFY(
  219. m_wndColorCtrlHSL_Panel.Create(
  220. _T("BUTTON"),
  221. _T(""),
  222. WS_CHILD,
  223. CRect(240,10,460,200),
  224. this,
  225. 0x204
  226. )
  227. );
  228. m_wndColorCtrlHSL_Panel = CExtColorCtrl::MODE_HSL_PANEL;
  229. COLORREF clrInit = RGB(196,128,64);
  230. m_wndColorCtrlCubeRGB_R.SetupColor(clrInit,false);
  231. m_wndColorCtrlCubeRGB_G.SetupColor(clrInit,false);
  232. m_wndColorCtrlHSL_BH.SetupColor(clrInit,false);
  233. m_wndColorCtrlHSL_Panel.SetupColor(clrInit,false);
  234. m_wndColorCtrlCubeRGB_B.SetupColor(clrInit,false);
  235. return 0;
  236. }
  237. LRESULT CChildView::OnColorChanged(WPARAM wParam,LPARAM lParam)
  238. {
  239. if( m_bSyncingValues )
  240. return 0;
  241. m_bSyncingValues = true;
  242. CExtColorCtrl::selection_colors_t * pClrs =
  243. (CExtColorCtrl::selection_colors_t *)lParam;
  244. ASSERT( pClrs != NULL );
  245. COLORREF clrNew = pClrs->m_clrNew;
  246. HWND hWndColorCtrlFrom = (HWND)wParam;
  247. ASSERT( ::IsWindow(hWndColorCtrlFrom) );
  248. if( hWndColorCtrlFrom != m_wndColorCtrlCubeRGB_R.GetSafeHwnd() )
  249. m_wndColorCtrlCubeRGB_R.SetupColor(clrNew,false);
  250. if( hWndColorCtrlFrom != m_wndColorCtrlCubeRGB_G.GetSafeHwnd() )
  251. m_wndColorCtrlCubeRGB_G.SetupColor(clrNew,false);
  252. if( hWndColorCtrlFrom != m_wndColorCtrlHSL_BH.GetSafeHwnd() )
  253. m_wndColorCtrlHSL_BH.SetupColor(clrNew,false);
  254. if( hWndColorCtrlFrom != m_wndColorCtrlHSL_Panel.GetSafeHwnd() )
  255. m_wndColorCtrlHSL_Panel.SetupColor(clrNew,false);
  256. if( hWndColorCtrlFrom != m_wndColorCtrlCubeRGB_B.GetSafeHwnd() )
  257. m_wndColorCtrlCubeRGB_B.SetupColor(clrNew,false);
  258. m_bSyncingValues = false;
  259. return 0;
  260. }
  261. void CChildView::OnViewColorControls() 
  262. {
  263. m_bColorControlsVisible = !m_bColorControlsVisible;
  264. m_wndColorCtrlCubeRGB_R.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  265. m_wndColorCtrlCubeRGB_G.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  266. m_wndColorCtrlHSL_BH.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  267. m_wndColorCtrlHSL_Panel.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  268. m_wndColorCtrlCubeRGB_B.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  269. }
  270. void CChildView::OnUpdateViewColorControls(CCmdUI* pCmdUI) 
  271. {
  272. pCmdUI->SetCheck(
  273. m_bColorControlsVisible ? 1 : 0
  274. );
  275. }