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

界面编程

开发平台:

Visual C++

  1. // ChildView.cpp : implementation of the CChildView class
  2. //
  3. #include "stdafx.h"
  4. #include "SDI.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_CLIPSIBLINGS|WS_CLIPCHILDREN;
  41. cs.dwExStyle &= ~(WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME);
  42. cs.style &= ~WS_BORDER;
  43. cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
  44. ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
  45. return TRUE;
  46. }
  47. void CChildView::OnPaint() 
  48. {
  49. CPaintDC dcPaint( this );
  50. CExtPaintManager::stat_ExcludeChildAreas(
  51. dcPaint.GetSafeHdc(),
  52. GetSafeHwnd()
  53. );
  54. CExtMemoryDC dc( &dcPaint );
  55. g_PaintManager->PaintDocumentClientAreaBkgnd( dc, this );
  56. CGdiObject * pOld0, * pOld1;
  57. CExtWndShadow _shadow1, _shadow2, _shadow3, _shadow4;
  58. WORD _PatternBits0[8],_PatternBits1[8];
  59. for( INT iPatternLine=0; iPatternLine < 8; iPatternLine++ )
  60. {
  61. _PatternBits0[iPatternLine] =
  62. ( iPatternLine & 1 )
  63. ? WORD(0xFFFF)
  64. : WORD( ~ ( 5<<iPatternLine ) )
  65. ;
  66. _PatternBits1[iPatternLine] =
  67. ( iPatternLine & 1 )
  68. ? WORD(0xFFFF)
  69. : WORD( ~ ( 1<<(8-iPatternLine) ) )
  70. ;
  71. }
  72. CBitmap bmpPattern0,bmpPattern1;
  73. CBrush brPattern0,brPattern1;
  74. VERIFY( bmpPattern0.CreateBitmap(8,8,1,1,_PatternBits0) );
  75. VERIFY( bmpPattern1.CreateBitmap(8,8,1,1,_PatternBits1) );
  76. VERIFY( brPattern0.CreatePatternBrush(&bmpPattern0) );
  77. VERIFY( brPattern1.CreatePatternBrush(&bmpPattern1) );
  78. CRect rcPattern0(10,10,180,150), rcPattern1(40,30,80,200);
  79. dc.FillRect(rcPattern0,&brPattern0);
  80. _shadow1.Paint(
  81. NULL,
  82. dc,
  83. rcPattern0,
  84. CRect(0,0,0,0),
  85. CRect(0,0,0,0),
  86. CExtWndShadow::DEF_SHADOW_SIZE,
  87. CExtWndShadow::DEF_BRIGHTNESS_MIN,
  88. CExtWndShadow::DEF_BRIGHTNESS_MAX,
  89. false
  90. );
  91. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  92. pOld1 = dc.SelectStockObject( BLACK_PEN );
  93. dc.Rectangle( rcPattern0 );
  94. if( pOld0 != NULL )
  95. dc.SelectObject( pOld0 );
  96. if( pOld1 != NULL )
  97. dc.SelectObject( pOld1 );
  98. dc.FillRect(rcPattern1,&brPattern1);
  99. _shadow2.Paint(
  100. NULL,
  101. dc,
  102. rcPattern1,
  103. CRect(0,0,0,0),
  104. CRect(0,0,0,0),
  105. CExtWndShadow::DEF_SHADOW_SIZE,
  106. CExtWndShadow::DEF_BRIGHTNESS_MIN,
  107. CExtWndShadow::DEF_BRIGHTNESS_MAX,
  108. false
  109. );
  110. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  111. pOld1 = dc.SelectStockObject( BLACK_PEN );
  112. dc.Rectangle( rcPattern1 );
  113. if( pOld0 != NULL )
  114. dc.SelectObject( pOld0 );
  115. if( pOld1 != NULL )
  116. dc.SelectObject( pOld1 );
  117. CRect rc0(20,50,160,80);
  118. CRect rc1(160,50,210,80);
  119. CRect rc2(rc0.left,rc0.top,rc1.right,rc1.bottom);
  120. COLORREF clrLeft = RGB(0,255,0);
  121. COLORREF clrMiddle = RGB(255,255,0);
  122. COLORREF clrRight = RGB(255,0,0);
  123. CExtPaintManager::stat_PaintGradientRect(
  124. dc, rc0, clrLeft, clrMiddle );
  125. CExtPaintManager::stat_PaintGradientRect(
  126. dc, rc1, clrMiddle,clrRight );
  127. _shadow3.Paint(
  128. NULL,
  129. dc,
  130. rc2,
  131. CRect(0,0,0,0),
  132. CRect(0,0,0,0),
  133. CExtWndShadow::DEF_SHADOW_SIZE,
  134. CExtWndShadow::DEF_BRIGHTNESS_MIN,
  135. CExtWndShadow::DEF_BRIGHTNESS_MAX,
  136. false,
  137. true
  138. );
  139. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  140. pOld1 = dc.SelectStockObject( BLACK_PEN );
  141. dc.Rectangle(rc2);
  142. if( pOld0 != NULL )
  143. dc.SelectObject( pOld0 );
  144. if( pOld1 != NULL )
  145. dc.SelectObject( pOld1 );
  146. CRect rc3(120,40,150,80);
  147. CRect rc4(120,80,150,160);
  148. CRect rc5(rc3.left,rc3.top,rc4.right,rc4.bottom);
  149. COLORREF clrUpper = RGB(255,0,255);
  150. COLORREF clrMiddleV = RGB(255,255,255);
  151. COLORREF clrLower = RGB(0,0,255);
  152. CExtPaintManager::stat_PaintGradientRect(
  153. dc, rc3, clrMiddleV, clrUpper, TRUE );
  154. CExtPaintManager::stat_PaintGradientRect(
  155. dc, rc4, clrLower, clrMiddleV, TRUE );
  156. _shadow4.Paint(
  157. NULL,
  158. dc,
  159. rc5,
  160. CRect(0,0,0,0),
  161. CRect(0,0,0,0),
  162. CExtWndShadow::DEF_SHADOW_SIZE,
  163. CExtWndShadow::DEF_BRIGHTNESS_MIN,
  164. CExtWndShadow::DEF_BRIGHTNESS_MAX,
  165. false
  166. );
  167. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  168. pOld1 = dc.SelectStockObject( BLACK_PEN );
  169. dc.Rectangle(rc5);
  170. if( pOld0 != NULL )
  171. dc.SelectObject( pOld0 );
  172. if( pOld1 != NULL )
  173. dc.SelectObject( pOld1 );
  174. }
  175. BOOL CChildView::OnEraseBkgnd(CDC* pDC) 
  176. {
  177. pDC;
  178. /*
  179. COMMENTED BLOCK: dragging controlbar unwanted redrawing test
  180. class FrienlyExtControlBar : public CExtControlBar
  181. {
  182. public:
  183. friend class CChildView;
  184. };
  185. CRect rcClient;
  186. GetClientRect( &rcClient );
  187. if( rcClient.IsRectEmpty() )
  188. return TRUE;
  189. if( !pDC->RectVisible(&rcClient) )
  190. return TRUE;
  191. COLORREF clr = RGB( 255, 0, 0 );
  192. if( FrienlyExtControlBar::g_bUpdatingDragState )
  193. clr = RGB( 0, 255, 0 );
  194. else if( FrienlyExtControlBar::_DraggingGetBar() != NULL )
  195. clr = RGB( 0, 0, 255 );
  196. pDC->FillSolidRect( &rcClient, clr );
  197. */
  198. return TRUE;
  199. }
  200. int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  201. {
  202. if (CWnd ::OnCreate(lpCreateStruct) == -1)
  203. return -1;
  204. VERIFY(
  205. m_wndColorCtrlCubeRGB.Create(
  206. _T("BUTTON"),
  207. _T(""),
  208. WS_CHILD,
  209. CRect(10,210,230,410),
  210. this,
  211. 0x200
  212. )
  213. );
  214. m_wndColorCtrlCubeRGB = CExtColorCtrl::MODE_RGB_CUBE;
  215. VERIFY(
  216. m_wndColorCtrlCubeCMY.Create(
  217. _T("BUTTON"),
  218. _T(""),
  219. WS_CHILD,
  220. CRect(240,210,460,410),
  221. this,
  222. 0x201
  223. )
  224. );
  225. m_wndColorCtrlCubeCMY = CExtColorCtrl::MODE_CMY_CUBE;
  226. VERIFY(
  227. m_wndColorCtrlHSL.Create(
  228. _T("BUTTON"),
  229. _T(""),
  230. WS_CHILD,
  231. CRect(240,10,460,200),
  232. this,
  233. 0x202
  234. )
  235. );
  236. m_wndColorCtrlHSL = CExtColorCtrl::MODE_HSL_PANEL;
  237. VERIFY(
  238. m_wndColorCtrlMixerRGB.Create(
  239. _T("BUTTON"),
  240. _T(""),
  241. WS_CHILD,
  242. CRect(470,210,690,410),
  243. this,
  244. 0x203
  245. )
  246. );
  247. m_wndColorCtrlMixerRGB = CExtColorCtrl::MODE_RGB_MIX;
  248. VERIFY(
  249. m_wndColorCtrlMixerCMY.Create(
  250. _T("BUTTON"),
  251. _T(""),
  252. WS_CHILD,
  253. CRect(470,10,690,200),
  254. this,
  255. 0x204
  256. )
  257. );
  258. m_wndColorCtrlMixerCMY = CExtColorCtrl::MODE_CMY_MIX;
  259. COLORREF clrInit = RGB(196,128,64);
  260. m_wndColorCtrlCubeRGB.SetupColor(clrInit,false);
  261. m_wndColorCtrlCubeCMY.SetupColor(clrInit,false);
  262. m_wndColorCtrlMixerRGB.SetupColor(clrInit,false);
  263. m_wndColorCtrlMixerCMY.SetupColor(clrInit,false);
  264. m_wndColorCtrlHSL.SetupColor(clrInit,false);
  265. return 0;
  266. }
  267. LRESULT CChildView::OnColorChanged(WPARAM wParam,LPARAM lParam)
  268. {
  269. if( m_bSyncingValues )
  270. return 0;
  271. m_bSyncingValues = true;
  272. CExtColorCtrl::selection_colors_t * pClrs =
  273. (CExtColorCtrl::selection_colors_t *)lParam;
  274. ASSERT( pClrs != NULL );
  275. COLORREF clrNew = pClrs->m_clrNew;
  276. HWND hWndColorCtrlFrom = (HWND)wParam;
  277. ASSERT( ::IsWindow(hWndColorCtrlFrom) );
  278. if( hWndColorCtrlFrom != m_wndColorCtrlCubeRGB.GetSafeHwnd() )
  279. m_wndColorCtrlCubeRGB.SetupColor(clrNew,false);
  280. if( hWndColorCtrlFrom != m_wndColorCtrlCubeCMY.GetSafeHwnd() )
  281. m_wndColorCtrlCubeCMY.SetupColor(clrNew,false);
  282. if( hWndColorCtrlFrom != m_wndColorCtrlMixerRGB.GetSafeHwnd() )
  283. m_wndColorCtrlMixerRGB.SetupColor(clrNew,false);
  284. if( hWndColorCtrlFrom != m_wndColorCtrlMixerCMY.GetSafeHwnd() )
  285. m_wndColorCtrlMixerCMY.SetupColor(clrNew,false);
  286. if( hWndColorCtrlFrom != m_wndColorCtrlHSL.GetSafeHwnd() )
  287. m_wndColorCtrlHSL.SetupColor(clrNew,false);
  288. m_bSyncingValues = false;
  289. return 0;
  290. }
  291. void CChildView::OnViewColorControls() 
  292. {
  293. m_bColorControlsVisible = ! m_bColorControlsVisible;
  294. m_wndColorCtrlCubeRGB.ShowWindow(  m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  295. m_wndColorCtrlCubeCMY.ShowWindow(  m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  296. m_wndColorCtrlMixerRGB.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  297. m_wndColorCtrlMixerCMY.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  298. m_wndColorCtrlHSL.ShowWindow(      m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  299. }
  300. void CChildView::OnUpdateViewColorControls(CCmdUI* pCmdUI) 
  301. {
  302. pCmdUI->SetCheck(
  303. m_bColorControlsVisible ? 1 : 0
  304. );
  305. }