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

对话框与窗口

开发平台:

Visual C++

  1. // ButtonDlg.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 "Button.h"
  22. #include "ButtonPage.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. // CButtonPage dialog
  31. CButtonPage::CButtonPage()
  32. : CXTResizePropertyPage(CButtonPage::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CButtonPage)
  35. m_nTheme = 5;
  36. m_bFlatStyle = FALSE;
  37. m_bUseVisualStyle = FALSE;
  38. m_bEnable = TRUE;
  39. m_bAlphaIcons = FALSE;
  40. m_bToggleButtons = FALSE;
  41. m_bShowFocus = TRUE;
  42. m_nRelation = 1;
  43. m_nPushButtonStyle = 0;
  44. m_nImageAlignment = 2;
  45. m_nTextAlignment = 2;
  46. //}}AFX_DATA_INIT
  47. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  48. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  49. }
  50. void CButtonPage::DoDataExchange(CDataExchange* pDX)
  51. {
  52. CXTResizePropertyPage::DoDataExchange(pDX);
  53. //{{AFX_DATA_MAP(CButtonPage)
  54. DDX_Radio(pDX, IDC_RADIO_CLASSIC, m_nTheme);
  55. DDX_Check(pDX, IDC_CHECK_FLATSTYLE, m_bFlatStyle);
  56. DDX_Check(pDX, IDC_CHECK_WINXP_THEMES, m_bUseVisualStyle);
  57. DDX_Check(pDX, IDC_CHECK_ENABLED, m_bEnable);
  58. DDX_Check(pDX, IDC_CHECK_ALPHA, m_bAlphaIcons);
  59. DDX_Check(pDX, IDC_CHECK_TOGGLE, m_bToggleButtons);
  60. DDX_Check(pDX, IDC_CHECK_FOCUS, m_bShowFocus);
  61. DDX_CBIndex(pDX, IDC_COMBO_RELATION, m_nRelation);
  62. DDX_CBIndex(pDX, IDC_COMBO_STYLE, m_nPushButtonStyle);
  63. DDX_Control(pDX, IDC_BUTTON_RUN, m_btnRun);
  64. DDX_Control(pDX, IDC_BUTTON_SETTINGS, m_btnSettings);
  65. DDX_Control(pDX, IDC_BUTTON_HELP, m_btnHelp);
  66. DDX_Control(pDX, IDC_BUTTON_FIND, m_btnFind);
  67. DDX_Control(pDX, IDC_CHECK_STATE1, m_btnState1);
  68. DDX_Control(pDX, IDC_CHECK_STATE2, m_btnState2);
  69. DDX_Control(pDX, IDC_RADIO_OPTION1, m_btnOption1);
  70. DDX_Control(pDX, IDC_RADIO_OPTION2, m_btnOption2);
  71. DDX_Control(pDX, IDC_GBOX_REGULAR, m_frmRegular);
  72. DDX_Control(pDX, IDC_GBOX_TWOROWS, m_frmTwoRows);
  73. DDX_Control(pDX, IDC_GBOX_CHECKBOXES, m_frmCheckboxes);
  74. DDX_Control(pDX, IDC_GBOX_RADIO, m_frmRadio);
  75. DDX_Control(pDX, IDC_GBOX_JUSTIFICATION, m_frmJustification);
  76. DDX_CBIndex(pDX, IDC_COMBO_IMAGEALIGNMENT, m_nImageAlignment);
  77. DDX_CBIndex(pDX, IDC_COMBO_TEXTALIGNMENT, m_nTextAlignment);
  78. //}}AFX_DATA_MAP
  79. }
  80. BEGIN_MESSAGE_MAP(CButtonPage, CXTResizePropertyPage)
  81. //{{AFX_MSG_MAP(CButtonPage)
  82. ON_WM_SYSCOMMAND()
  83. ON_WM_PAINT()
  84. ON_WM_DESTROY()
  85. ON_WM_QUERYDRAGICON()
  86. ON_BN_CLICKED(IDC_RADIO_CLASSIC, OnRadTheme)
  87. ON_BN_CLICKED(IDC_CHECK_FLATSTYLE, OnCheckFlatstyle)
  88. ON_BN_CLICKED(IDC_CHECK_WINXP_THEMES, OnCheckWinxpThemes)
  89. ON_BN_CLICKED(IDC_CHECK_ENABLED, OnCheckEnabled)
  90. ON_BN_CLICKED(IDC_CHECK_ALPHA, OnCheckAlpha)
  91. ON_BN_CLICKED(IDC_CHECK_TOGGLE, OnCheckToggle)
  92. ON_BN_CLICKED(IDC_CHECK_FOCUS, OnCheckFocus)
  93. ON_CBN_SELCHANGE(IDC_COMBO_RELATION, OnSelchangeComboRelation)
  94. ON_CBN_SELCHANGE(IDC_COMBO_STYLE, OnSelchangeComboStyle)
  95. ON_BN_CLICKED(IDC_RADIO_FLAT, OnRadTheme)
  96. ON_BN_CLICKED(IDC_RADIO_OFFICE2000, OnRadTheme)
  97. ON_BN_CLICKED(IDC_RADIO_OFFICE2003, OnRadTheme)
  98. ON_BN_CLICKED(IDC_RADIO_OFFICE2007, OnRadTheme)
  99. ON_BN_CLICKED(IDC_RADIO_OFFICEXP, OnRadTheme)
  100. ON_BN_CLICKED(IDC_RADIO_ULTRAFLAT, OnRadTheme)
  101. ON_CBN_SELCHANGE(IDC_COMBO_IMAGEALIGNMENT, OnSelchangeComboImagealignment)
  102. ON_CBN_SELCHANGE(IDC_COMBO_TEXTALIGNMENT, OnSelchangeComboTextalignment)
  103. //}}AFX_MSG_MAP
  104. ON_CONTROL_RANGE(BN_CLICKED, IDC_BUTTON_SETTINGS, IDC_BUTTON_RUN, OnButtonClicked)
  105. ON_CONTROL_RANGE(CBN_DROPDOWN, IDC_BUTTON_SETTINGS, IDC_BUTTON_RUN, OnButtonDropDown)
  106. END_MESSAGE_MAP()
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CButtonPage message handlers
  109. BOOL CButtonPage::OnInitDialog()
  110. {
  111. CXTResizePropertyPage::OnInitDialog();
  112. // Add "About..." menu item to system menu.
  113. // IDM_ABOUTBOX must be in the system command range.
  114. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  115. ASSERT(IDM_ABOUTBOX < 0xF000);
  116. CMenu* pSysMenu = GetSystemMenu(FALSE);
  117. if (pSysMenu != NULL)
  118. {
  119. CString strAboutMenu;
  120. strAboutMenu.LoadString(IDS_ABOUTBOX);
  121. if (!strAboutMenu.IsEmpty())
  122. {
  123. pSysMenu->AppendMenu(MF_SEPARATOR);
  124. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  125. }
  126. }
  127. // Set the icon for this dialog.  The framework does this automatically
  128. //  when the application's main window is not a dialog
  129. SetIcon(m_hIcon, TRUE);         // Set big icon
  130. SetIcon(m_hIcon, FALSE);        // Set small icon
  131. /*
  132. // Set control resizing.
  133. // Load window placement
  134. LoadPlacement(_T("CButtonPage"));
  135. //------------------------------------
  136. // TODO: Add extra initialization here
  137. //------------------------------------
  138. m_bitmap.LoadBitmap(IDB_IMAGELIST);
  139. m_imageList.Create(24, 24, ILC_COLOR24|ILC_MASK, 4, 1);
  140. m_imageList.Add(&m_bitmap, RGB(0,255,0));
  141. UpdateIcons(FALSE);
  142. m_btnOK.SetTheme(xtThemeDefault);
  143. m_btnOK.SetBitmap(CSize(16, 16), IDB_OK);
  144. m_btnOK.SetXButtonStyle(BS_XT_WINXP_COMPAT);
  145. OnRadOffice2003();
  146. UpdateXTStyle();*/
  147. m_frmCheckboxes.SetBorderStyle(xtpGroupBoxSingleLine);
  148. m_frmRadio.SetBorderStyle(xtpGroupBoxSingleLine);
  149. m_frmJustification.SetBorderStyle(xtpGroupBoxSingleLine);
  150. int i;
  151. for (i = IDC_GBOX_REGULAR; i <= IDC_COMBO_STYLE; i++)
  152. SetResize(i, SZ_TOP_LEFT, CXTResizePoint((float)(1.0/3.0), 0));
  153. for (i = IDC_GBOX_CHECKBOXES; i <= IDC_COMBO_RELATION; i++)
  154. SetResize(i, CXTResizePoint((float)(1.0/3.0), 0), CXTResizePoint((float)(2.0/3.0), 0));
  155. for (i = IDC_GBOX_THEME; i <= IDC_CHECK_ALPHA; i++)
  156. SetResize(i, CXTResizePoint((float)(2.0/3.0), 0), SZ_TOP_RIGHT);
  157. m_bitmap.LoadBitmap(IDB_IMAGELIST);
  158. m_imageList.Create(24, 24, ILC_COLOR24|ILC_MASK, 4, 1);
  159. m_imageList.Add(&m_bitmap, RGB(0,255,0));
  160. UpdateIcons(FALSE);
  161. OnRadTheme();
  162. OnCheckWinxpThemes();
  163. return TRUE;  // return TRUE  unless you set the focus to a control
  164. }
  165. void CButtonPage::OnDestroy()
  166. {
  167. // Save window placement
  168. SavePlacement(_T("CButtonPage"));
  169. CXTResizePropertyPage::OnDestroy();
  170. }
  171. void CButtonPage::OnSysCommand(UINT nID, LPARAM lParam)
  172. {
  173. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  174. {
  175. CAboutDlg dlgAbout;
  176. dlgAbout.DoModal();
  177. }
  178. else
  179. {
  180. CXTResizePropertyPage::OnSysCommand(nID, lParam);
  181. }
  182. }
  183. // If you add a minimize button to your dialog, you will need the code below
  184. //  to draw the icon.  For MFC applications using the document/view model,
  185. //  this is automatically done for you by the framework.
  186. void CButtonPage::OnPaint()
  187. {
  188. if (IsIconic())
  189. {
  190. CPaintDC dc(this); // device context for painting
  191. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  192. // Center icon in client rectangle
  193. int cxIcon = GetSystemMetrics(SM_CXICON);
  194. int cyIcon = GetSystemMetrics(SM_CYICON);
  195. CRect rect;
  196. GetClientRect(&rect);
  197. int x = (rect.Width() - cxIcon + 1) / 2;
  198. int y = (rect.Height() - cyIcon + 1) / 2;
  199. // Draw the icon
  200. dc.DrawIcon(x, y, m_hIcon);
  201. }
  202. else
  203. {
  204. CXTResizePropertyPage::OnPaint();
  205. }
  206. }
  207. // The system calls this to obtain the cursor to display while the user drags
  208. //  the minimized window.
  209. HCURSOR CButtonPage::OnQueryDragIcon()
  210. {
  211. return (HCURSOR) m_hIcon;
  212. }
  213. void CButtonPage::OnRadTheme() 
  214. {
  215. UpdateData();
  216. m_btnRun.SetTheme((XTPButtonTheme)m_nTheme);
  217. m_btnFind.SetTheme((XTPButtonTheme)m_nTheme);
  218. m_btnSettings.SetTheme((XTPButtonTheme)m_nTheme);
  219. m_btnHelp.SetTheme((XTPButtonTheme)m_nTheme);
  220. m_btnState1.SetTheme((XTPButtonTheme)m_nTheme);
  221. m_btnState2.SetTheme((XTPButtonTheme)m_nTheme);
  222. m_btnOption1.SetTheme((XTPButtonTheme)m_nTheme);
  223. m_btnOption2.SetTheme((XTPButtonTheme)m_nTheme);
  224. m_frmRegular.SetTheme((XTPButtonTheme)m_nTheme);
  225. m_frmTwoRows.SetTheme((XTPButtonTheme)m_nTheme);
  226. m_frmCheckboxes.SetTheme((XTPButtonTheme)m_nTheme);
  227. m_frmRadio.SetTheme((XTPButtonTheme)m_nTheme);
  228. m_frmJustification.SetTheme((XTPButtonTheme)m_nTheme);
  229. }
  230. void CButtonPage::UpdateIcons(BOOL bAlpha)
  231. {
  232. if (!bAlpha)
  233. {
  234. HICON hIcon = m_imageList.ExtractIcon(0);
  235. m_btnSettings.SetIcon(CSize(24,24), hIcon);
  236. DestroyIcon(hIcon);
  237. hIcon = m_imageList.ExtractIcon(1); 
  238. HICON hIconHot = m_imageList.ExtractIcon(2);
  239. m_btnFind.SetIcon(CSize(24,24), hIcon, hIconHot);
  240. DestroyIcon(hIcon); DestroyIcon(hIconHot);
  241. hIcon = m_imageList.ExtractIcon(3); 
  242. m_btnHelp.SetIcon(CSize(24,24), hIcon);
  243. DestroyIcon(hIcon);
  244. hIcon = m_imageList.ExtractIcon(4); 
  245. m_btnRun.SetIcon(CSize(24,24),hIcon);
  246. DestroyIcon(hIcon);
  247. else
  248. {
  249. m_btnSettings.SetBitmap(0, IDB_ALPHA_SETTINGS);
  250. m_btnFind.SetBitmap(0, IDB_ALPHA_FIND);
  251. m_btnHelp.SetBitmap(0, IDB_ALPHA_HELP);
  252. m_btnRun.SetBitmap(0, IDB_ALPHA_RUN);
  253. }
  254. }
  255. void CButtonPage::OnCheckFlatstyle() 
  256. {
  257. UpdateData();
  258. m_btnSettings.SetFlatStyle(m_bFlatStyle);
  259. m_btnFind.SetFlatStyle(m_bFlatStyle);
  260. m_btnHelp.SetFlatStyle(m_bFlatStyle);
  261. m_btnRun.SetFlatStyle(m_bFlatStyle);
  262. }
  263. void CButtonPage::OnCheckWinxpThemes() 
  264. {
  265. UpdateData();
  266. m_btnSettings.SetUseVisualStyle(m_bUseVisualStyle);
  267. m_btnFind.SetUseVisualStyle(m_bUseVisualStyle);
  268. m_btnHelp.SetUseVisualStyle(m_bUseVisualStyle);
  269. m_btnRun.SetUseVisualStyle(m_bUseVisualStyle);
  270. m_btnState1.SetUseVisualStyle(m_bUseVisualStyle);
  271. m_btnState2.SetUseVisualStyle(m_bUseVisualStyle);
  272. m_btnOption1.SetUseVisualStyle(m_bUseVisualStyle);
  273. m_btnOption2.SetUseVisualStyle(m_bUseVisualStyle);
  274. m_frmRegular.SetUseVisualStyle(m_bUseVisualStyle);
  275. m_frmTwoRows.SetUseVisualStyle(m_bUseVisualStyle);
  276. m_frmCheckboxes.SetUseVisualStyle(m_bUseVisualStyle);
  277. m_frmRadio.SetUseVisualStyle(m_bUseVisualStyle);
  278. RedrawWindow(0, 0, RDW_ALLCHILDREN|RDW_INVALIDATE|RDW_ERASE);
  279. }
  280. void CButtonPage::OnCheckEnabled() 
  281. {
  282. UpdateData();
  283. m_btnSettings.EnableWindow(m_bEnable);
  284. m_btnFind.EnableWindow(m_bEnable);
  285. m_btnHelp.EnableWindow(m_bEnable);
  286. m_btnRun.EnableWindow(m_bEnable);
  287. m_btnState1.EnableWindow(m_bEnable);
  288. m_btnState2.EnableWindow(m_bEnable);
  289. m_btnOption1.EnableWindow(m_bEnable);
  290. m_btnOption2.EnableWindow(m_bEnable);
  291. }
  292. void CButtonPage::OnCheckAlpha() 
  293. {
  294. UpdateData();
  295. UpdateIcons(m_bAlphaIcons);
  296. }
  297. void CButtonPage::OnCheckToggle() 
  298. {
  299. UpdateData();
  300. if (!m_bToggleButtons)
  301. {
  302. m_btnSettings.SetChecked(FALSE);
  303. m_btnFind.SetChecked(FALSE);
  304. m_btnHelp.SetChecked(FALSE);
  305. m_btnRun.SetChecked(FALSE);
  306. }
  307. }
  308. void CButtonPage::OnButtonClicked(UINT nID)
  309. {
  310. CXTPButton* pButton = DYNAMIC_DOWNCAST(CXTPButton, GetDlgItem(nID));
  311. ASSERT(pButton);
  312. if (m_bToggleButtons)
  313. {
  314. pButton->SetChecked(!pButton->GetChecked());
  315. }
  316. }
  317. void CButtonPage::OnButtonDropDown(UINT nID)
  318. {
  319. // loading a user resource.
  320. CMenu menu;
  321. menu.LoadMenu(IDR_MENU_DROPDOWN);
  322. CMenu* pPopup = menu.GetSubMenu(0);
  323. ASSERT(pPopup != NULL);
  324. CXTPButton* pButton = DYNAMIC_DOWNCAST(CXTPButton, GetDlgItem(nID));
  325. ASSERT(pButton);
  326. DWORD dwStyle = pButton->GetPushButtonStyle();
  327. ASSERT(pButton->IsDropDownStyle());
  328. CXTPWindowRect rect(pButton);
  329. int nCmd = TrackPopupMenu(pPopup->GetSafeHmenu(), TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL |TPM_RETURNCMD,
  330. dwStyle == xtpButtonDropDownRight ? rect.right : rect.left, dwStyle == xtpButtonDropDownRight ? rect.top : rect.bottom, 0, m_hWnd, 0);
  331. if (nCmd > 0)
  332. {
  333. }
  334. }
  335. void CButtonPage::OnCheckFocus() 
  336. {
  337. UpdateData();
  338. m_btnSettings.SetShowFocus(m_bShowFocus);
  339. m_btnFind.SetShowFocus(m_bShowFocus);
  340. m_btnHelp.SetShowFocus(m_bShowFocus);
  341. m_btnRun.SetShowFocus(m_bShowFocus);
  342. m_btnState1.SetShowFocus(m_bShowFocus);
  343. m_btnState2.SetShowFocus(m_bShowFocus);
  344. m_btnOption1.SetShowFocus(m_bShowFocus);
  345. m_btnOption2.SetShowFocus(m_bShowFocus);
  346. }
  347. void CButtonPage::OnSelchangeComboRelation() 
  348. {
  349. UpdateData();
  350. m_btnHelp.SetTextImageRelation((XTPButtonTextImageRelation)m_nRelation);
  351. m_btnRun.SetTextImageRelation((XTPButtonTextImageRelation)m_nRelation);
  352. if (m_nRelation != xtpButtonTextAboveImage && m_nRelation != xtpButtonImageAboveText)
  353. {
  354. m_btnSettings.SetTextImageRelation((XTPButtonTextImageRelation)m_nRelation);
  355. m_btnFind.SetTextImageRelation((XTPButtonTextImageRelation)m_nRelation);
  356. }
  357. }
  358. void CButtonPage::OnSelchangeComboStyle() 
  359. {
  360. UpdateData();
  361. m_btnHelp.SetPushButtonStyle((XTPPushButtonStyle)m_nPushButtonStyle);
  362. m_btnRun.SetPushButtonStyle((XTPPushButtonStyle)m_nPushButtonStyle);
  363. m_btnSettings.SetPushButtonStyle((XTPPushButtonStyle)m_nPushButtonStyle);
  364. m_btnFind.SetPushButtonStyle((XTPPushButtonStyle)m_nPushButtonStyle);
  365. }
  366. void CButtonPage::OnSelchangeComboTextalignment() 
  367. {
  368. UpdateData();
  369. int nVert = m_nTextAlignment >= 6 ? BS_BOTTOM : m_nTextAlignment >= 3 ? BS_TOP : BS_VCENTER;
  370. int nHorz = m_nTextAlignment % 3 == 0 ? BS_LEFT : m_nTextAlignment % 3 == 1 ? BS_RIGHT : BS_CENTER;
  371. m_btnRun.SetTextAlignment(nVert | nHorz);
  372. m_btnHelp.SetTextAlignment(nVert | nHorz);
  373. m_btnSettings.SetTextAlignment(nVert | nHorz);
  374. m_btnFind.SetTextAlignment(nVert | nHorz);
  375. }
  376. void CButtonPage::OnSelchangeComboImagealignment() 
  377. {
  378. UpdateData();
  379. int nVert = m_nImageAlignment >= 6 ? BS_BOTTOM : m_nImageAlignment >= 3 ? BS_TOP : BS_VCENTER;
  380. int nHorz = m_nImageAlignment % 3 == 0 ? BS_LEFT : m_nImageAlignment % 3 == 1 ? BS_RIGHT : BS_CENTER;
  381. m_btnRun.SetImageAlignment(nVert | nHorz);
  382. m_btnHelp.SetImageAlignment(nVert | nHorz);
  383. m_btnSettings.SetImageAlignment(nVert | nHorz);
  384. m_btnFind.SetImageAlignment(nVert | nHorz);
  385. }