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 "MDI_InnerOuterBars.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. ON_COMMAND(ID_CHILD_BILD, OnChildBuild)
  32. ON_COMMAND(ID_CHILD_COMPILE, OnChildCompile)
  33. ON_COMMAND(ID_CHILD_DEBUG, OnChildDebug)
  34. ON_COMMAND(ID_CHILD_REBUILD, OnChildRebuild)
  35. ON_COMMAND(ID_CHILD_STOP_BUILD, OnChildStopBuild)
  36. ON_COMMAND(ID_CHILD_STOP_DBG, OnChildStopDbg)
  37. //}}AFX_MSG_MAP
  38. ON_REGISTERED_MESSAGE(CExtColorCtrl::g_nMsgColorChanged,OnColorChanged)
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CChildView message handlers
  42. BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
  43. {
  44. if( ! CWnd::PreCreateWindow( cs ) )
  45. return FALSE;
  46. cs.dwExStyle &= ~(WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME);
  47. cs.style &= ~WS_BORDER;
  48. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  49. cs.lpszClass =
  50. AfxRegisterWndClass(
  51. CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
  52. ::LoadCursor(NULL, IDC_ARROW),
  53. HBRUSH(NULL),
  54. NULL
  55. );
  56. return TRUE;
  57. }
  58. void CChildView::OnPaint() 
  59. {
  60. CRect rcClient;
  61. GetClientRect( &rcClient );
  62. CPaintDC dcPaint( this );
  63. CExtPaintManager::stat_ExcludeChildAreas(
  64. dcPaint.GetSafeHdc(),
  65. GetSafeHwnd()
  66. );
  67. CExtMemoryDC dc( &dcPaint, &rcClient );
  68. g_PaintManager->PaintDocumentClientAreaBkgnd( dc, this );
  69. CGdiObject * pOld0, * pOld1;
  70. CExtWndShadow _shadow1, _shadow2, _shadow3, _shadow4;
  71. WORD _PatternBits0[8],_PatternBits1[8];
  72. for( INT iPatternLine=0; iPatternLine < 8; iPatternLine++ )
  73. {
  74. _PatternBits0[iPatternLine] =
  75. ( iPatternLine & 1 )
  76. ? WORD(0xFFFF)
  77. : WORD( ~ ( 5<<iPatternLine ) )
  78. ;
  79. _PatternBits1[iPatternLine] =
  80. ( iPatternLine & 1 )
  81. ? WORD(0xFFFF)
  82. : WORD( ~ ( 1<<(8-iPatternLine) ) )
  83. ;
  84. }
  85. CBitmap bmpPattern0,bmpPattern1;
  86. CBrush brPattern0,brPattern1;
  87. VERIFY( bmpPattern0.CreateBitmap(8,8,1,1,_PatternBits0) );
  88. VERIFY( bmpPattern1.CreateBitmap(8,8,1,1,_PatternBits1) );
  89. VERIFY( brPattern0.CreatePatternBrush(&bmpPattern0) );
  90. VERIFY( brPattern1.CreatePatternBrush(&bmpPattern1) );
  91. CRect rcPattern0(10,10,180,150), rcPattern1(40,30,80,200);
  92. dc.FillRect(rcPattern0,&brPattern0);
  93. _shadow1.Paint(
  94. NULL,
  95. dc, rcPattern0, CRect(0,0,0,0), CRect(0,0,0,0),
  96. CExtWndShadow::DEF_SHADOW_SIZE,
  97. CExtWndShadow::DEF_BRIGHTNESS_MIN, CExtWndShadow::DEF_BRIGHTNESS_MAX,
  98. false
  99. );
  100. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  101. pOld1 = dc.SelectStockObject( BLACK_PEN );
  102. dc.Rectangle( rcPattern0 );
  103. if( pOld0 != NULL )
  104. dc.SelectObject( pOld0 );
  105. if( pOld1 != NULL )
  106. dc.SelectObject( pOld1 );
  107. dc.FillRect(rcPattern1,&brPattern1);
  108. _shadow2.Paint(
  109. NULL,
  110. dc, rcPattern1, CRect(0,0,0,0), CRect(0,0,0,0),
  111. CExtWndShadow::DEF_SHADOW_SIZE,
  112. CExtWndShadow::DEF_BRIGHTNESS_MIN, CExtWndShadow::DEF_BRIGHTNESS_MAX,
  113. false
  114. );
  115. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  116. pOld1 = dc.SelectStockObject( BLACK_PEN );
  117. dc.Rectangle( rcPattern1 );
  118. if( pOld0 != NULL )
  119. dc.SelectObject( pOld0 );
  120. if( pOld1 != NULL )
  121. dc.SelectObject( pOld1 );
  122. CRect rc0(20,50,160,80);
  123. CRect rc1(160,50,210,80);
  124. CRect rc2(rc0.left,rc0.top,rc1.right,rc1.bottom);
  125. COLORREF clrLeft = RGB(0,255,0);
  126. COLORREF clrMiddle = RGB(255,255,0);
  127. COLORREF clrRight = RGB(255,0,0);
  128. CExtPaintManager::stat_PaintGradientRect(
  129. dc, rc0, clrLeft, clrMiddle );
  130. CExtPaintManager::stat_PaintGradientRect(
  131. dc, rc1, clrMiddle,clrRight );
  132. _shadow3.Paint(
  133. NULL,
  134. dc, rc2, CRect(0,0,0,0), CRect(0,0,0,0),
  135. CExtWndShadow::DEF_SHADOW_SIZE,
  136. CExtWndShadow::DEF_BRIGHTNESS_MIN, CExtWndShadow::DEF_BRIGHTNESS_MAX,
  137. false
  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, rc5, CRect(0,0,0,0), CRect(0,0,0,0),
  159. CExtWndShadow::DEF_SHADOW_SIZE,
  160. CExtWndShadow::DEF_BRIGHTNESS_MIN, CExtWndShadow::DEF_BRIGHTNESS_MAX,
  161. false
  162. );
  163. pOld0 = dc.SelectStockObject( NULL_BRUSH );
  164. pOld1 = dc.SelectStockObject( BLACK_PEN );
  165. dc.Rectangle(rc5);
  166. if( pOld0 != NULL )
  167. dc.SelectObject( pOld0 );
  168. if( pOld1 != NULL )
  169. dc.SelectObject( pOld1 );
  170. }
  171. BOOL CChildView::OnEraseBkgnd(CDC* pDC) 
  172. {
  173. pDC;
  174. return TRUE;
  175. }
  176. int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  177. {
  178. if (CWnd ::OnCreate(lpCreateStruct) == -1)
  179. return -1;
  180. VERIFY(
  181. m_wndColorCtrlCubeRGB_R.Create(
  182. _T("BUTTON"),
  183. _T(""),
  184. WS_CHILD,
  185. CRect(10,210,230,410),
  186. this,
  187. 0x200
  188. )
  189. );
  190. m_wndColorCtrlCubeRGB_R = CExtColorCtrl::MODE_XYZ_R;
  191. VERIFY(
  192. m_wndColorCtrlCubeRGB_G.Create(
  193. _T("BUTTON"),
  194. _T(""),
  195. WS_CHILD,
  196. CRect(240,210,460,410),
  197. this,
  198. 0x201
  199. )
  200. );
  201. m_wndColorCtrlCubeRGB_G = CExtColorCtrl::MODE_XYZ_G;
  202. VERIFY(
  203. m_wndColorCtrlCubeRGB_B.Create(
  204. _T("BUTTON"),
  205. _T(""),
  206. WS_CHILD,
  207. CRect(470,210,690,410),
  208. this,
  209. 0x202
  210. )
  211. );
  212. m_wndColorCtrlCubeRGB_B = CExtColorCtrl::MODE_XYZ_B;
  213. VERIFY(
  214. m_wndColorCtrlHSL_BH.Create(
  215. _T("BUTTON"),
  216. _T(""),
  217. WS_CHILD,
  218. CRect(470,10,690,200),
  219. this,
  220. 0x203
  221. )
  222. );
  223. m_wndColorCtrlHSL_BH = CExtColorCtrl::MODE_HSL_BASIC_HUE;
  224. VERIFY(
  225. m_wndColorCtrlHSL_Panel.Create(
  226. _T("BUTTON"),
  227. _T(""),
  228. WS_CHILD,
  229. CRect(240,10,460,200),
  230. this,
  231. 0x204
  232. )
  233. );
  234. m_wndColorCtrlHSL_Panel = CExtColorCtrl::MODE_HSL_PANEL;
  235. COLORREF clrInit = RGB(196,128,64);
  236. m_wndColorCtrlCubeRGB_R.SetupColor(clrInit,false);
  237. m_wndColorCtrlCubeRGB_G.SetupColor(clrInit,false);
  238. m_wndColorCtrlHSL_BH.SetupColor(clrInit,false);
  239. m_wndColorCtrlHSL_Panel.SetupColor(clrInit,false);
  240. m_wndColorCtrlCubeRGB_B.SetupColor(clrInit,false);
  241. return 0;
  242. }
  243. LRESULT CChildView::OnColorChanged(WPARAM wParam,LPARAM lParam)
  244. {
  245. if( m_bSyncingValues )
  246. return 0;
  247. m_bSyncingValues = true;
  248. CExtColorCtrl::selection_colors_t * pClrs =
  249. (CExtColorCtrl::selection_colors_t *)lParam;
  250. ASSERT( pClrs != NULL );
  251. COLORREF clrNew = pClrs->m_clrNew;
  252. HWND hWndColorCtrlFrom = (HWND)wParam;
  253. ASSERT( ::IsWindow(hWndColorCtrlFrom) );
  254. if( hWndColorCtrlFrom != m_wndColorCtrlCubeRGB_R.GetSafeHwnd() )
  255. m_wndColorCtrlCubeRGB_R.SetupColor(clrNew,false);
  256. if( hWndColorCtrlFrom != m_wndColorCtrlCubeRGB_G.GetSafeHwnd() )
  257. m_wndColorCtrlCubeRGB_G.SetupColor(clrNew,false);
  258. if( hWndColorCtrlFrom != m_wndColorCtrlHSL_BH.GetSafeHwnd() )
  259. m_wndColorCtrlHSL_BH.SetupColor(clrNew,false);
  260. if( hWndColorCtrlFrom != m_wndColorCtrlHSL_Panel.GetSafeHwnd() )
  261. m_wndColorCtrlHSL_Panel.SetupColor(clrNew,false);
  262. if( hWndColorCtrlFrom != m_wndColorCtrlCubeRGB_B.GetSafeHwnd() )
  263. m_wndColorCtrlCubeRGB_B.SetupColor(clrNew,false);
  264. m_bSyncingValues = false;
  265. return 0;
  266. }
  267. void CChildView::OnViewColorControls() 
  268. {
  269. m_bColorControlsVisible = !m_bColorControlsVisible;
  270. m_wndColorCtrlCubeRGB_R.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  271. m_wndColorCtrlCubeRGB_G.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  272. m_wndColorCtrlHSL_BH.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  273. m_wndColorCtrlHSL_Panel.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  274. m_wndColorCtrlCubeRGB_B.ShowWindow( m_bColorControlsVisible ? SW_SHOW : SW_HIDE );
  275. }
  276. void CChildView::OnUpdateViewColorControls(CCmdUI* pCmdUI) 
  277. {
  278. pCmdUI->SetCheck(
  279. m_bColorControlsVisible ? 1 : 0
  280. );
  281. }
  282. void CChildView::OnChildBuild() 
  283. {
  284. AfxMessageBox(
  285. _T("CChildView::OnChildBuild()")
  286. );
  287. }
  288. void CChildView::OnChildCompile() 
  289. {
  290. AfxMessageBox(
  291. _T("CChildView::OnChildCompile()")
  292. );
  293. }
  294. void CChildView::OnChildDebug() 
  295. {
  296. AfxMessageBox(
  297. _T("CChildView::OnChildDebug()")
  298. );
  299. }
  300. void CChildView::OnChildRebuild() 
  301. {
  302. AfxMessageBox(
  303. _T("CChildView::OnChildRebuild()")
  304. );
  305. }
  306. void CChildView::OnChildStopBuild() 
  307. {
  308. AfxMessageBox(
  309. _T("CChildView::OnChildStopBuild()")
  310. );
  311. }
  312. void CChildView::OnChildStopDbg() 
  313. {
  314. AfxMessageBox(
  315. _T("CChildView::OnChildStopDbg()")
  316. );
  317. }