Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
6.7 KiB

  1. // NCMetricsDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "mditest.h"
  5. #include "NCMetricsDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CNCMetricsDlg dialog
  13. CNCMetricsDlg::CNCMetricsDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CNCMetricsDlg::IDD, pParent),
  15. _fDlgInit(FALSE),
  16. _fChanged(FALSE)
  17. {
  18. ZeroMemory( &_ncm, sizeof(_ncm) );
  19. _ncm.cbSize = sizeof(_ncm);
  20. //{{AFX_DATA_INIT(CNCMetricsDlg)
  21. //}}AFX_DATA_INIT
  22. }
  23. void CNCMetricsDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CNCMetricsDlg)
  27. // NOTE: the ClassWizard will add DDX and DDV calls here
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CNCMetricsDlg, CDialog)
  31. //{{AFX_MSG_MAP(CNCMetricsDlg)
  32. ON_EN_CHANGE(IDC_BORDERWIDTH, OnChanged)
  33. ON_BN_CLICKED(IDC_CAPTIONFONT, OnCaptionfont)
  34. ON_BN_CLICKED(IDC_CAPTIONFONT2, OnSmallCaptionFont)
  35. ON_BN_CLICKED(IDC_APPLY, OnApply)
  36. ON_EN_CHANGE(IDC_MENUWIDTH, OnChanged)
  37. ON_EN_CHANGE(IDC_MENUHEIGHT, OnChanged)
  38. ON_EN_CHANGE(IDC_SCROLLBARWIDTH, OnChanged)
  39. ON_EN_CHANGE(IDC_SCROLLBARHEIGHT, OnChanged)
  40. ON_EN_CHANGE(IDC_CAPTIONWIDTH, OnChanged)
  41. ON_EN_CHANGE(IDC_CAPTIONHEIGHT, OnChanged)
  42. ON_EN_CHANGE(IDC_CAPTIONWIDTH2, OnChanged)
  43. ON_EN_CHANGE(IDC_CAPTIONHEIGHT2, OnChanged)
  44. ON_EN_CHANGE(IDC_CAPTIONFONTDESCR, OnChanged)
  45. ON_EN_CHANGE(IDC_CAPTIONFONTDESCR2, OnChanged)
  46. ON_BN_CLICKED(IDOK, OnOk)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CNCMetricsDlg message handlers
  51. BOOL CNCMetricsDlg::OnInitDialog()
  52. {
  53. CDialog::OnInitDialog();
  54. _GetSPI( TRUE, TRUE );
  55. _fDlgInit = TRUE;
  56. _UpdateControls();
  57. return TRUE; // return TRUE unless you set the focus to a control
  58. // EXCEPTION: OCX Property Pages should return FALSE
  59. }
  60. void CNCMetricsDlg::_UpdateControls()
  61. {
  62. ::EnableWindow( ::GetDlgItem( m_hWnd, IDC_APPLY ), _fChanged );
  63. }
  64. void CNCMetricsDlg::_GetSPI( BOOL fAcquire, BOOL fDlgSetValues )
  65. {
  66. BOOL fSpi = fAcquire ? SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, &_ncm, 0 ) : TRUE;
  67. if( fDlgSetValues )
  68. {
  69. SetDlgItemInt(IDC_BORDERWIDTH, _ncm.iBorderWidth );
  70. SetDlgItemInt(IDC_SCROLLBARWIDTH, _ncm.iScrollWidth );
  71. SetDlgItemInt(IDC_SCROLLBARHEIGHT, _ncm.iScrollHeight );
  72. SetDlgItemInt(IDC_MENUWIDTH, _ncm.iMenuWidth );
  73. SetDlgItemInt(IDC_MENUHEIGHT, _ncm.iMenuHeight );
  74. SetDlgItemInt(IDC_CAPTIONWIDTH, _ncm.iCaptionWidth );
  75. SetDlgItemInt(IDC_CAPTIONHEIGHT, _ncm.iCaptionHeight );
  76. SetDlgItemInt(IDC_SMCAPTIONWIDTH, _ncm.iSmCaptionWidth );
  77. SetDlgItemInt(IDC_SMCAPTIONHEIGHT, _ncm.iSmCaptionHeight );
  78. int cyFont;
  79. TCHAR szFontDescr[128];
  80. HDC hdc = ::GetDC(NULL);
  81. cyFont = -MulDiv(_ncm.lfCaptionFont.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY));
  82. wsprintf( szFontDescr, TEXT("%s, %dpt"), _ncm.lfCaptionFont.lfFaceName, cyFont );
  83. SetDlgItemText(IDC_CAPTIONFONTDESCR, szFontDescr);
  84. cyFont = -MulDiv(_ncm.lfSmCaptionFont.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY));
  85. wsprintf( szFontDescr, TEXT("%s, %dpt"), _ncm.lfSmCaptionFont.lfFaceName, cyFont );
  86. SetDlgItemText(IDC_CAPTIONFONTDESCR2, szFontDescr);
  87. ::ReleaseDC(NULL, hdc);
  88. _UpdateControls();
  89. }
  90. }
  91. void CNCMetricsDlg::_SetSPI( BOOL fAssign, BOOL fDlgSetValues )
  92. {
  93. BOOL fGet = FALSE;
  94. if( fDlgSetValues )
  95. {
  96. _ncm.iBorderWidth = GetDlgItemInt(IDC_BORDERWIDTH);
  97. _ncm.iScrollWidth = GetDlgItemInt(IDC_SCROLLBARWIDTH);
  98. _ncm.iScrollHeight = GetDlgItemInt(IDC_SCROLLBARHEIGHT);
  99. _ncm.iMenuWidth = GetDlgItemInt(IDC_MENUWIDTH);
  100. _ncm.iMenuHeight = GetDlgItemInt(IDC_MENUHEIGHT);
  101. _ncm.iCaptionWidth = GetDlgItemInt(IDC_CAPTIONWIDTH);
  102. _ncm.iCaptionHeight = GetDlgItemInt(IDC_CAPTIONHEIGHT);
  103. _ncm.iSmCaptionWidth = GetDlgItemInt(IDC_SMCAPTIONWIDTH);
  104. _ncm.iSmCaptionHeight = GetDlgItemInt(IDC_SMCAPTIONHEIGHT );
  105. }
  106. if( fAssign )
  107. {
  108. SystemParametersInfo( SPI_SETNONCLIENTMETRICS, 0, &_ncm,
  109. SPIF_SENDCHANGE | SPIF_UPDATEINIFILE );
  110. _fChanged = FALSE;
  111. }
  112. }
  113. void CNCMetricsDlg::OnChanged()
  114. {
  115. _fChanged = _fDlgInit;
  116. _UpdateControls();
  117. }
  118. //-----------------------------------------------------------------------------------//
  119. BOOL QueryCaptionFont( HWND hwndParent, LOGFONT* plf )
  120. {
  121. LOGFONT lf = *plf;
  122. DWORD dwErr = 0;
  123. CHOOSEFONT cf;
  124. ZeroMemory( &cf, sizeof(cf) );
  125. cf.lStructSize = sizeof(cf);
  126. cf.hwndOwner = hwndParent;
  127. cf.lpLogFont = &lf;
  128. cf.iPointSize = 0;
  129. cf.Flags = CF_INITTOLOGFONTSTRUCT|CF_EFFECTS|CF_FORCEFONTEXIST|CF_SCREENFONTS;
  130. cf.lCustData;
  131. cf.lpfnHook;
  132. cf.lpszStyle;
  133. cf.nFontType;
  134. if( ChooseFont( &cf ) )
  135. {
  136. *plf = lf;
  137. return TRUE;
  138. }
  139. else
  140. {
  141. dwErr = CommDlgExtendedError();
  142. }
  143. return FALSE;
  144. }
  145. //-----------------------------------------------------------------------------------//
  146. void CNCMetricsDlg::OnCaptionfont()
  147. {
  148. if( QueryCaptionFont( m_hWnd, &_ncm.lfCaptionFont ) )
  149. {
  150. _GetSPI(FALSE, TRUE);
  151. _fChanged = TRUE;
  152. _UpdateControls();
  153. }
  154. }
  155. //-----------------------------------------------------------------------------------//
  156. void CNCMetricsDlg::OnSmallCaptionFont()
  157. {
  158. if( QueryCaptionFont( m_hWnd, &_ncm.lfSmCaptionFont ) )
  159. {
  160. _GetSPI(FALSE, TRUE);
  161. _fChanged = TRUE;
  162. _UpdateControls();
  163. }
  164. }
  165. //-----------------------------------------------------------------------------------//
  166. void CNCMetricsDlg::OnApply()
  167. {
  168. _SetSPI( TRUE, TRUE );
  169. }
  170. //-----------------------------------------------------------------------------------//
  171. void CNCMetricsDlg::OnOk()
  172. {
  173. _SetSPI( TRUE, TRUE );
  174. CDialog::OnOK();
  175. }
  176. /////////////////////////////////////////////////////////////////////////////
  177. // CThinFrameDlg dialog
  178. CThinFrameDlg::CThinFrameDlg(CWnd* pParent /*=NULL*/)
  179. : CDialog(CThinFrameDlg::IDD, pParent)
  180. {
  181. //{{AFX_DATA_INIT(CThinFrameDlg)
  182. // NOTE: the ClassWizard will add member initialization here
  183. //}}AFX_DATA_INIT
  184. }
  185. void CThinFrameDlg::DoDataExchange(CDataExchange* pDX)
  186. {
  187. CDialog::DoDataExchange(pDX);
  188. //{{AFX_DATA_MAP(CThinFrameDlg)
  189. // NOTE: the ClassWizard will add DDX and DDV calls here
  190. //}}AFX_DATA_MAP
  191. }
  192. BEGIN_MESSAGE_MAP(CThinFrameDlg, CDialog)
  193. //{{AFX_MSG_MAP(CThinFrameDlg)
  194. // NOTE: the ClassWizard will add message map macros here
  195. //}}AFX_MSG_MAP
  196. END_MESSAGE_MAP()
  197. /////////////////////////////////////////////////////////////////////////////
  198. // CThinFrameDlg message handlers