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 "FunnyBars.h"
  5. #include "ChildView.h"
  6. #include "MainFrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. static int CALLBACK stat_FontEnumProc(
  13. ENUMLOGFONTEX * lpelfe,
  14. NEWTEXTMETRICEX * lpntme, 
  15. int FontType,
  16. CComboBox * pCombo
  17. )
  18. {
  19. lpntme;
  20. FontType;
  21.     if( pCombo->FindStringExact(
  22. 0,
  23. lpelfe->elfLogFont.lfFaceName
  24. ) != CB_ERR
  25. )
  26.     return 1;
  27. pCombo->AddString( lpelfe->elfLogFont.lfFaceName );
  28.     return 1;
  29. }
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CChildView
  32. IMPLEMENT_DYNCREATE( CChildView, CFormView );
  33. CChildView::CChildView()
  34. : CExtNCSB < CExtWS < CExtAFV < CFormView > > > ( CChildView::IDD, ((CWnd *)NULL), true )
  35. , m_bInitializingControls( false )
  36. {
  37. ::memset( &m_lf, 0, sizeof(LOGFONT) );
  38. ASSERT( g_PaintManager->m_FontNormal.GetSafeHandle() != NULL );
  39. g_PaintManager->m_FontNormal.GetLogFont( &m_lf );
  40. }
  41. CChildView::~CChildView()
  42. {
  43. }
  44. void CChildView::DoDataExchange(CDataExchange* pDX)
  45. {
  46. CExtNCSB < CExtWS < CExtAFV < CFormView > > > :: DoDataExchange(pDX);
  47. //{{AFX_DATA_MAP( CChildView)
  48. DDX_Control(pDX, IDC_STATIC_FONT_WIDTH, m_wndLabelFontWidth);
  49. DDX_Control(pDX, IDC_STATIC_FONT_HEIGHT, m_wndLabelFontHeight);
  50. DDX_Control(pDX, IDC_STATIC_FONT_FACE_NAME, m_wndLabelFontFaceName);
  51. DDX_Control(pDX, IDC_GROUP_BOX_FONT, m_wndBoxFont);
  52. DDX_Control(pDX, IDC_GROUP_BOX_BRIGHTNESS, m_wndBoxBrightness);
  53. DDX_Control(pDX, IDC_SLIDER_HTBB, m_wndSliderHTBB);
  54. DDX_Control(pDX, IDC_EDIT_FONT_WIDTH, m_EditFontWidth);
  55. DDX_Control(pDX, IDC_EDIT_FONT_HEIGHT, m_EditFontHeight);
  56. DDX_Control(pDX, IDC_COMBO_FONT_FACE_NAME, m_ComboFontFaceName);
  57. DDX_Control(pDX, IDC_CHECK_FONT_UNDERLINE, m_BtnFontUnderline);
  58. DDX_Control(pDX, IDC_CHECK_FONT_STRIKEOUT, m_BtnFontStrikeout);
  59. DDX_Control(pDX, IDC_CHECK_FONT_ITALIC, m_BtnFontItalic);
  60. DDX_Control(pDX, IDC_CHECK_FONT_BOLD, m_BtnFontBold);
  61. //}}AFX_DATA_MAP
  62. }
  63. BEGIN_MESSAGE_MAP( CChildView, CFormView )
  64. //{{AFX_MSG_MAP(CChildView)
  65. ON_WM_HSCROLL()
  66. ON_WM_VSCROLL()
  67. ON_WM_SETTINGCHANGE()
  68. ON_WM_SYSCOLORCHANGE()
  69. ON_BN_CLICKED(IDC_CHECK_FONT_BOLD, OnCheckFontBold)
  70. ON_BN_CLICKED(IDC_CHECK_FONT_ITALIC, OnCheckFontItalic)
  71. ON_BN_CLICKED(IDC_CHECK_FONT_UNDERLINE, OnCheckFontUnderline)
  72. ON_BN_CLICKED(IDC_CHECK_FONT_STRIKEOUT, OnCheckFontStrikeout)
  73. ON_EN_CHANGE(IDC_EDIT_FONT_WIDTH, OnChangeEditFontWidth)
  74. ON_EN_CHANGE(IDC_EDIT_FONT_HEIGHT, OnChangeEditFontHeight)
  75. ON_CBN_SELCHANGE(IDC_COMBO_FONT_FACE_NAME, OnSelchangeComboFontFaceName)
  76. ON_WM_SIZE()
  77. //}}AFX_MSG_MAP
  78. ON_MESSAGE(WM_DISPLAYCHANGE, OnDisplayChange)
  79. END_MESSAGE_MAP()
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CChildView message handlers
  82. void CChildView::_UpdateHotBar( bool bForceEmptyIconCache )
  83. {
  84. int nPos = m_wndSliderHTBB.GetPos();
  85. ASSERT( -100 <= nPos && nPos <= 100 );
  86. double lfHotPercent = double(nPos) / 100.0;
  87. CMainFrame * pMainFrame =
  88. STATIC_DOWNCAST( CMainFrame, GetParentFrame() );
  89. int nCount = pMainFrame->m_wndToolBarTrueHot.GetButtonsCount();
  90. for( int i = 0; i < nCount; i++ )
  91. {
  92. CExtBarButton * pTBBxx =
  93. pMainFrame->m_wndToolBarTrueHot.GetButton( i );
  94. ASSERT_VALID( pTBBxx );
  95. CFunnyToolButton * pTBB =
  96. DYNAMIC_DOWNCAST( CFunnyToolButton, pTBBxx );
  97. if( pTBB == NULL )
  98. continue;
  99. ASSERT( !pTBB->IsSeparator() );
  100. pTBB->UpdateHotPercent( lfHotPercent, bForceEmptyIconCache );
  101. } // for( int i = 0; i < nCount; i++ )
  102. if( pMainFrame->m_wndToolBarTrueHot.IsVisible() )
  103. {
  104. pMainFrame->m_wndToolBarTrueHot.Invalidate();
  105. pMainFrame->m_wndToolBarTrueHot.UpdateWindow();
  106. }
  107. }
  108. void CChildView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  109. {
  110. if( pScrollBar->GetSafeHwnd() != NULL
  111. && pScrollBar->GetDlgCtrlID() == IDC_SLIDER_HTBB
  112. )
  113. {
  114. if( ! m_bInitializingControls )
  115. _UpdateHotBar( false );
  116. return;
  117. }
  118. CExtNCSB < CExtWS < CExtAFV < CFormView > > > :: OnHScroll( nSBCode, nPos, pScrollBar );
  119. RedrawWindow( NULL, NULL, RDW_INVALIDATE|RDW_ALLCHILDREN );
  120. if( m_wndSliderHTBB.GetSafeHwnd() != NULL )
  121. m_wndSliderHTBB.UpdateSliderWnd();
  122. }
  123. void CChildView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  124. {
  125. CExtNCSB < CExtWS < CExtAFV < CFormView > > > :: OnVScroll( nSBCode, nPos, pScrollBar );
  126. RedrawWindow( NULL, NULL, RDW_INVALIDATE|RDW_ALLCHILDREN );
  127. if( m_wndSliderHTBB.GetSafeHwnd() != NULL )
  128. m_wndSliderHTBB.UpdateSliderWnd();
  129. }
  130. void CChildView::OnInitialUpdate() 
  131. {
  132. CExtNCSB < CExtWS < CExtAFV < CFormView > > > :: OnInitialUpdate();
  133. ASSERT( !m_bInitializingControls );
  134. m_bInitializingControls = true;
  135. m_wndSliderHTBB.SetRange( -100, 100 );
  136. m_wndSliderHTBB.SetPageSize( 10 );
  137. m_wndSliderHTBB.SetPos( 25 );
  138. CWindowDC dc( this );
  139. LOGFONT logfont;
  140. logfont.lfCharSet = DEFAULT_CHARSET;
  141. logfont.lfFaceName[0] = '';
  142. logfont.lfPitchAndFamily = 0;
  143. ::EnumFontFamiliesEx(
  144. dc.m_hDC,
  145. &logfont,
  146. (FONTENUMPROC)stat_FontEnumProc,
  147. (LPARAM)&m_ComboFontFaceName,
  148. 0
  149. );
  150. int i = m_ComboFontFaceName.FindStringExact(
  151. 0,
  152. m_lf.lfFaceName
  153. );
  154. if( i >= 0 )
  155. m_ComboFontFaceName.SetCurSel( i );
  156. CString s;
  157. s.Format( _T("%ld"), m_lf.lfWidth );
  158. m_EditFontWidth.SetWindowText( s );
  159. s.Format( _T("%ld"), m_lf.lfHeight );
  160. m_EditFontHeight.SetWindowText( s );
  161. m_BtnFontBold.SetCheck(
  162. ( m_lf.lfWeight > 400 ) ? TRUE : FALSE
  163. );
  164. m_BtnFontItalic.SetCheck(
  165. m_lf.lfItalic ? TRUE : FALSE
  166. );
  167. m_BtnFontUnderline.SetCheck(
  168. m_lf.lfUnderline ? TRUE : FALSE
  169. );
  170. m_BtnFontStrikeout.SetCheck(
  171. m_lf.lfStrikeOut ? TRUE : FALSE
  172. );
  173. m_wndSliderHTBB.SetStyle( CExtSliderWnd::ES_PROFUIS );
  174. m_bInitializingControls = false;
  175. ShowSizeGrip( FALSE );
  176. }
  177. void CChildView::_ConrolsData_2_UiSettings()
  178. {
  179. ASSERT( !m_bInitializingControls );
  180. if( g_PaintManager->m_FontNormal.GetSafeHandle() != NULL )
  181. g_PaintManager->m_FontNormal.DeleteObject();
  182. CString s;
  183. m_ComboFontFaceName.GetWindowText( s );
  184. if( !s.IsEmpty() )
  185. __EXT_MFC_STRCPY( m_lf.lfFaceName, LF_FACESIZE, s );
  186. m_EditFontWidth.GetWindowText( s );
  187. if( !s.IsEmpty() )
  188. m_lf.lfWidth = _ttol( s );
  189. m_EditFontHeight.GetWindowText( s );
  190. if( !s.IsEmpty() )
  191. m_lf.lfHeight = _ttol( s );
  192. m_lf.lfWeight = m_BtnFontBold.GetCheck() ? 900 : 400;
  193. m_lf.lfItalic = (BYTE)(m_BtnFontItalic.GetCheck() ? TRUE : FALSE);
  194. m_lf.lfUnderline = (BYTE)(m_BtnFontUnderline.GetCheck() ? TRUE : FALSE);
  195. m_lf.lfStrikeOut = (BYTE)(m_BtnFontStrikeout.GetCheck() ? TRUE : FALSE);
  196. g_PaintManager->m_FontNormal.CreateFontIndirect( &m_lf );
  197. ASSERT( g_PaintManager->m_FontNormal.GetSafeHandle() != NULL );
  198. CMainFrame * pMainFrame =
  199. STATIC_DOWNCAST( CMainFrame, GetParentFrame() );
  200. pMainFrame->RecalcLayout();
  201. RedrawWindow(
  202. NULL,
  203. NULL,
  204. RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN
  205. );
  206. CExtControlBar::stat_RedrawFloatingFrames( pMainFrame );
  207. CExtControlBar::stat_RecalcBarMetrics( pMainFrame );
  208. m_wndSliderHTBB.UpdateSliderWnd();
  209. }
  210. void CChildView::OnSettingChange(UINT uFlags, LPCTSTR lpszSection) 
  211. {
  212. CExtNCSB < CExtWS < CExtAFV < CFormView > > > :: OnSettingChange(uFlags, lpszSection);
  213. _ConrolsData_2_UiSettings();
  214. }
  215. LRESULT CChildView::OnDisplayChange( WPARAM wParam, LPARAM lParam )
  216. {
  217. LRESULT lResult = CExtNCSB < CExtWS < CExtAFV < CFormView > > > :: OnDisplayChange( wParam, lParam );
  218. _ConrolsData_2_UiSettings();
  219. return lResult;
  220. }
  221. void CChildView::OnSysColorChange() 
  222. {
  223. CExtNCSB < CExtWS < CExtAFV < CFormView > > > :: OnSysColorChange();
  224. _ConrolsData_2_UiSettings();
  225. }
  226. void CChildView::OnCheckFontBold() 
  227. {
  228. if( !m_bInitializingControls )
  229. _ConrolsData_2_UiSettings();
  230. }
  231. void CChildView::OnCheckFontItalic() 
  232. {
  233. if( !m_bInitializingControls )
  234. _ConrolsData_2_UiSettings();
  235. }
  236. void CChildView::OnCheckFontUnderline() 
  237. {
  238. if( !m_bInitializingControls )
  239. _ConrolsData_2_UiSettings();
  240. }
  241. void CChildView::OnCheckFontStrikeout() 
  242. {
  243. if( !m_bInitializingControls )
  244. _ConrolsData_2_UiSettings();
  245. }
  246. void CChildView::OnChangeEditFontWidth() 
  247. {
  248. if( !m_bInitializingControls )
  249. _ConrolsData_2_UiSettings();
  250. }
  251. void CChildView::OnChangeEditFontHeight() 
  252. {
  253. if( !m_bInitializingControls )
  254. _ConrolsData_2_UiSettings();
  255. }
  256. void CChildView::OnSelchangeComboFontFaceName() 
  257. {
  258. if( !m_bInitializingControls )
  259. _ConrolsData_2_UiSettings();
  260. }
  261. void CChildView::OnSize(UINT nType, int cx, int cy) 
  262. {
  263. CExtNCSB < CExtWS < CExtAFV < CFormView > > > :: OnSize(nType, cx, cy);
  264. if( m_wndSliderHTBB.GetSafeHwnd() != NULL )
  265. m_wndSliderHTBB.UpdateSliderWnd();
  266. }