FlatComboDlg.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:9k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // FlatComboDlg.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "FlatCombo.h"
  22. #include "FlatComboDlg.h"
  23. #include "AboutDlg.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CFlatComboDlg dialog
  31. CFlatComboDlg::CFlatComboDlg(CWnd* pParent /*=NULL*/)
  32. : CXTResizeDialog(CFlatComboDlg::IDD, pParent)
  33. {
  34. //{{AFX_DATA_INIT(CFlatComboDlg)
  35. m_bAutoComplete = FALSE;
  36. m_bDisable1 = FALSE;
  37. m_bDisable2 = FALSE;
  38. m_nTheme = 2;
  39. //}}AFX_DATA_INIT
  40. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  41. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  42. }
  43. void CFlatComboDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CXTResizeDialog::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CFlatComboDlg)
  47. DDX_Control(pDX, IDOK, m_btnOk);
  48. DDX_Control(pDX, IDCANCEL, m_btnCancel);
  49. DDX_Control(pDX, IDC_FLAT_EDIT, m_wndFlatEdit);
  50. DDX_Control(pDX, IDC_GBOX_LIST, m_gboxList);
  51. DDX_Control(pDX, IDC_GBOX_DOWN, m_gboxDown);
  52. DDX_Control(pDX, IDC_GBOX_APPEAR, m_gboxAppear);
  53. DDX_Control(pDX, IDC_DROPLIST_TXT_CLR, m_cpText2);
  54. DDX_Control(pDX, IDC_DROPLIST_BAK_CLR, m_cpBack2);
  55. DDX_Control(pDX, IDC_DROPDOWN_TXT_CLR, m_cpText1);
  56. DDX_Control(pDX, IDC_DROPDOWN_BAK_CLR, m_cpBack1);
  57. DDX_Control(pDX, IDC_DROPDOWN_COMBO, m_wndFlatCombo1);
  58. DDX_Control(pDX, IDC_DROPLIST_COMBO, m_wndFlatCombo2);
  59. DDX_Check(pDX, IDC_DROPDOWN_AUTOCOMP, m_bAutoComplete);
  60. DDX_Check(pDX, IDC_DROPDOWN_DISABLE, m_bDisable1);
  61. DDX_Check(pDX, IDC_DROPLIST_DISABLE, m_bDisable2);
  62. DDX_Radio(pDX, IDC_RADIO_THEME, m_nTheme);
  63. //}}AFX_DATA_MAP
  64. }
  65. BEGIN_MESSAGE_MAP(CFlatComboDlg, CXTResizeDialog)
  66. //{{AFX_MSG_MAP(CFlatComboDlg)
  67. ON_WM_SYSCOMMAND()
  68. ON_WM_PAINT()
  69. ON_WM_QUERYDRAGICON()
  70. ON_BN_CLICKED(IDC_DROPLIST_DISABLE, OnDroplistDisable)
  71. ON_BN_CLICKED(IDC_DROPDOWN_DISABLE, OnDropdownDisable)
  72. ON_BN_CLICKED(IDC_DROPDOWN_AUTOCOMP, OnDropdownAutocomp)
  73. ON_CPN_XT_SELENDOK(IDC_DROPLIST_TXT_CLR, OnSelEndOKDLTxtClr)
  74. ON_CPN_XT_SELENDOK(IDC_DROPLIST_BAK_CLR, OnSelEndOKDLBakClr)
  75. ON_CPN_XT_SELENDOK(IDC_DROPDOWN_TXT_CLR, OnSelEndOKDDTxtClr)
  76. ON_CPN_XT_SELENDOK(IDC_DROPDOWN_BAK_CLR, OnSelEndOKDDBakClr)
  77. ON_BN_CLICKED(IDC_RADIO_THEME, OnThemeChanged)
  78. ON_BN_CLICKED(IDC_RADIO_THEME_FLAT, OnThemeChanged)
  79. ON_BN_CLICKED(IDC_RADIO_THEME_OFFICEXP, OnThemeChanged)
  80. ON_BN_CLICKED(IDC_RADIO_THEME_OFFICE2003, OnThemeChanged)
  81. ON_WM_CTLCOLOR()
  82. ON_WM_DESTROY()
  83. //}}AFX_MSG_MAP
  84. END_MESSAGE_MAP()
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CFlatComboDlg message handlers
  87. BOOL CFlatComboDlg::OnInitDialog()
  88. {
  89. CXTResizeDialog::OnInitDialog();
  90. // Add "About..." menu item to system menu.
  91. // IDM_ABOUTBOX must be in the system command range.
  92. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  93. ASSERT(IDM_ABOUTBOX < 0xF000);
  94. CMenu* pSysMenu = GetSystemMenu(FALSE);
  95. if (pSysMenu != NULL)
  96. {
  97. CString strAboutMenu;
  98. strAboutMenu.LoadString(IDS_ABOUTBOX);
  99. if (!strAboutMenu.IsEmpty())
  100. {
  101. pSysMenu->AppendMenu(MF_SEPARATOR);
  102. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  103. }
  104. }
  105. // Set the icon for this dialog.  The framework does this automatically
  106. //  when the application's main window is not a dialog
  107. SetIcon(m_hIcon, TRUE);         // Set big icon
  108. SetIcon(m_hIcon, FALSE);        // Set small icon
  109. // Set control resizing.
  110. SetResize(IDC_GBOX_LIST, SZ_TOP_LEFT, SZ_TOP_RIGHT);
  111. SetResize(IDC_DROPLIST_COMBO, SZ_TOP_LEFT, SZ_TOP_RIGHT);
  112. SetResize(IDC_GBOX_DOWN, SZ_TOP_LEFT, SZ_TOP_RIGHT);
  113. SetResize(IDC_DROPDOWN_COMBO, SZ_TOP_LEFT, SZ_TOP_RIGHT);
  114. SetResize(IDC_GBOX_EDIT, SZ_TOP_LEFT, SZ_TOP_RIGHT);
  115. SetResize(IDC_GBOX_APPEAR, SZ_TOP_LEFT, SZ_TOP_RIGHT);
  116. SetResize(IDOK, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  117. SetResize(IDCANCEL, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  118. // prevent vertical resizing.
  119. SetFlag(xtResizeNoVertical);
  120. // Load window placement
  121. LoadPlacement(_T("CFlatComboDlg2"));
  122. // set each combo's index.
  123. m_wndFlatCombo1.SetCurSel(0);
  124. m_wndFlatCombo2.SetCurSel(1);
  125. // enable auto completion based on boolean.
  126. m_wndFlatCombo1.EnableAutoCompletion( m_bAutoComplete );
  127. // set the text color controls based on current combo color.
  128. m_cpText2.SetColor( m_wndFlatCombo2.GetTextColor() );
  129. m_cpBack2.SetColor( m_wndFlatCombo2.GetBackColor() );
  130. m_cpText1.SetColor( m_wndFlatCombo1.GetTextColor() );
  131. m_cpBack1.SetColor( m_wndFlatCombo1.GetBackColor() );
  132. OnThemeChanged();
  133. return TRUE;  // return TRUE  unless you set the focus to a control
  134. }
  135. void CFlatComboDlg::OnDestroy()
  136. {
  137. // Save window placement
  138. SavePlacement(_T("CFlatComboDlg2"));
  139. CXTResizeDialog::OnDestroy();
  140. }
  141. void CFlatComboDlg::OnSysCommand(UINT nID, LPARAM lParam)
  142. {
  143. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  144. {
  145. CAboutDlg dlgAbout;
  146. dlgAbout.DoModal();
  147. }
  148. else
  149. {
  150. CXTResizeDialog::OnSysCommand(nID, lParam);
  151. }
  152. }
  153. // If you add a minimize button to your dialog, you will need the code below
  154. //  to draw the icon.  For MFC applications using the document/view model,
  155. //  this is automatically done for you by the framework.
  156. void CFlatComboDlg::OnPaint()
  157. {
  158. if (IsIconic())
  159. {
  160. CPaintDC dc(this); // device context for painting
  161. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  162. // Center icon in client rectangle
  163. int cxIcon = GetSystemMetrics(SM_CXICON);
  164. int cyIcon = GetSystemMetrics(SM_CYICON);
  165. CRect rect;
  166. GetClientRect(&rect);
  167. int x = (rect.Width() - cxIcon + 1) / 2;
  168. int y = (rect.Height() - cyIcon + 1) / 2;
  169. // Draw the icon
  170. dc.DrawIcon(x, y, m_hIcon);
  171. }
  172. else
  173. {
  174. CXTResizeDialog::OnPaint();
  175. }
  176. }
  177. // The system calls this to obtain the cursor to display while the user drags
  178. //  the minimized window.
  179. HCURSOR CFlatComboDlg::OnQueryDragIcon()
  180. {
  181. return (HCURSOR) m_hIcon;
  182. }
  183. void CFlatComboDlg::OnSelEndOKDLTxtClr()
  184. {
  185. m_wndFlatCombo2.SetTextColor(m_cpText2.GetColor());
  186. m_wndFlatCombo2.Invalidate();
  187. }
  188. void CFlatComboDlg::OnSelEndOKDLBakClr()
  189. {
  190. m_wndFlatCombo2.SetBackColor(m_cpBack2.GetColor());
  191. m_wndFlatCombo2.Invalidate();
  192. }
  193. void CFlatComboDlg::OnSelEndOKDDTxtClr()
  194. {
  195. m_wndFlatCombo1.SetTextColor(m_cpText1.GetColor());
  196. m_wndFlatCombo1.Invalidate();
  197. }
  198. void CFlatComboDlg::OnSelEndOKDDBakClr()
  199. {
  200. m_wndFlatCombo1.SetBackColor(m_cpBack1.GetColor());
  201. m_wndFlatCombo1.Invalidate();
  202. }
  203. void CFlatComboDlg::OnDroplistDisable()
  204. {
  205. UpdateData();
  206. m_wndFlatCombo2.EnableWindow( !m_bDisable2 );
  207. }
  208. void CFlatComboDlg::OnDropdownDisable()
  209. {
  210. UpdateData();
  211. m_wndFlatCombo1.EnableWindow( !m_bDisable1 );
  212. }
  213. void CFlatComboDlg::OnDropdownAutocomp()
  214. {
  215. UpdateData();
  216. m_wndFlatCombo1.EnableAutoCompletion( m_bAutoComplete );
  217. }
  218. HBRUSH CFlatComboDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  219. {
  220. HBRUSH hbr = CXTResizeDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  221. // set the combo boxes text and background colors...
  222. int nItem = pWnd->GetDlgCtrlID();
  223. switch (nItem)
  224. {
  225. case IDC_DROPLIST_COMBO:
  226. case IDC_DROPDOWN_COMBO:
  227. if( pWnd->IsWindowEnabled( ))
  228. {
  229. pDC->SetBkColor  (((CFlatComboBox*)pWnd)->GetBackColor());
  230. pDC->SetTextColor(((CFlatComboBox*)pWnd)->GetTextColor());
  231. }
  232. break;
  233. }
  234. return hbr;
  235. }
  236. void CFlatComboDlg::OnThemeChanged()
  237. {
  238. UpdateData(TRUE);
  239. m_wndFlatCombo1.DisableFlatLook(m_nTheme == 0);
  240. m_wndFlatCombo2.DisableFlatLook(m_nTheme == 0);
  241. m_wndFlatEdit.DisableFlatLook(m_nTheme == 0);
  242. m_btnOk.SetXButtonStyle(m_nTheme == 0? BS_XT_WINXP_COMPAT: m_nTheme == 1? BS_XT_FLAT: 0);
  243. m_btnCancel.SetXButtonStyle(m_nTheme == 0? BS_XT_WINXP_COMPAT: m_nTheme == 1? BS_XT_FLAT: 0);
  244. switch (m_nTheme)
  245. {
  246. case 0:
  247. case 1:
  248. XTThemeManager()->SetTheme(xtThemeDefault);
  249. break;
  250. case 2:
  251. XTThemeManager()->SetTheme(xtThemeOfficeXP);
  252. break;
  253. case 3:
  254. XTThemeManager()->SetTheme(xtThemeOffice2003);
  255. break;
  256. }
  257. RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);
  258. }