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

对话框与窗口

开发平台:

Visual C++

  1. // DialogSampleDlg.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 "DialogSample.h"
  22. #include "DialogSampleDlg.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. // CDialogSampleDlg dialog
  31. CDialogSampleDlg::CDialogSampleDlg(CWnd* pParent /*=NULL*/)
  32. : CDialogSampleDlgBase(CDialogSampleDlg::IDD, pParent)
  33. {
  34. //{{AFX_DATA_INIT(CDialogSampleDlg)
  35. // NOTE: the ClassWizard will add member initialization here
  36. //}}AFX_DATA_INIT
  37. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  38. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  39. m_rcBorders.SetRectEmpty();
  40. m_bInRepositionControls = FALSE;
  41. m_bInitDone = FALSE;
  42. }
  43. void CDialogSampleDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CDialogSampleDlgBase::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CDialogSampleDlg)
  47. // NOTE: the ClassWizard will add DDX and DDV calls here
  48. //}}AFX_DATA_MAP
  49. }
  50. BEGIN_MESSAGE_MAP(CDialogSampleDlg, CDialogSampleDlgBase)
  51. //{{AFX_MSG_MAP(CDialogSampleDlg)
  52. ON_WM_SYSCOMMAND()
  53. ON_WM_PAINT()
  54. ON_WM_QUERYDRAGICON()
  55. ON_WM_DESTROY()
  56. ON_COMMAND(ID_APP_ABOUT, OnHelpAbout)
  57. ON_COMMAND(ID_FILE_EXIT, OnFileExit)
  58. ON_COMMAND(ID_FILE_NEW, OnEmptyCommand)
  59. ON_COMMAND(ID_FILE_OPEN, OnEmptyCommand)
  60. ON_WM_SIZE()
  61. //}}AFX_MSG_MAP
  62. ON_COMMAND_RANGE(ID_BUTTON_PLAY, ID_BUTTON_BACKWARD, OnEmptyCommandRange)
  63. ON_COMMAND_RANGE(ID_THEME_OFFICE2000, ID_THEME_WHIDBEY, OnTheme)
  64. ON_UPDATE_COMMAND_UI_RANGE(ID_THEME_OFFICE2000, ID_THEME_WHIDBEY, OnUpdateTheme)
  65. ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
  66. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  67. ON_UPDATE_COMMAND_UI(ID_INDICATOR_CAPS, OnUpdateKeyIndicator)
  68. ON_UPDATE_COMMAND_UI(ID_INDICATOR_NUM, OnUpdateKeyIndicator)
  69. ON_UPDATE_COMMAND_UI(ID_INDICATOR_SCRL, OnUpdateKeyIndicator)
  70. ON_MESSAGE(WM_POPMESSAGESTRING, OnSetMessageString)
  71. ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString)
  72. END_MESSAGE_MAP()
  73. static UINT indicators[] =
  74. {
  75. ID_SEPARATOR,           // status line indicator
  76. ID_INDICATOR_CAPS,
  77. ID_INDICATOR_NUM,
  78. ID_INDICATOR_SCRL,
  79. };
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CDialogSampleDlg message handlers
  82. BOOL CDialogSampleDlg::OnInitDialog()
  83. {
  84. SetFlag(xtResizeNoSizeIcon);
  85. CDialogSampleDlgBase::OnInitDialog();
  86. // Add "About..." menu item to system menu.
  87. // IDM_ABOUTBOX must be in the system command range.
  88. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  89. ASSERT(IDM_ABOUTBOX < 0xF000);
  90. CMenu* pSysMenu = GetSystemMenu(FALSE);
  91. if (pSysMenu != NULL)
  92. {
  93. CString strAboutMenu;
  94. strAboutMenu.LoadString(IDS_ABOUTBOX);
  95. if (!strAboutMenu.IsEmpty())
  96. {
  97. pSysMenu->AppendMenu(MF_SEPARATOR);
  98. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  99. }
  100. }
  101. // Set the icon for this dialog.  The framework does this automatically
  102. //  when the application's main window is not a dialog
  103. SetIcon(m_hIcon, TRUE);         // Set big icon
  104. SetIcon(m_hIcon, FALSE);        // Set small icon
  105. if (!m_wndStatusBar.Create(this) ||
  106. !m_wndStatusBar.SetIndicators(indicators,
  107. sizeof(indicators)/sizeof(UINT)))
  108. {
  109. TRACE0("Failed to create status barn");
  110. return -1;      // fail to create
  111. }
  112. m_wndStatusBar.SetPaneInfo(0, ID_SEPARATOR, SBPS_STRETCH, 100);
  113. VERIFY(InitCommandBars());
  114. OnTheme(ID_THEME_WHIDBEY);
  115. CXTPCommandBars* pCommandBars = GetCommandBars();
  116. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MENU);
  117. CXTPToolBar* pToolBar = pCommandBars->Add(_T("Standard"), xtpBarTop);
  118. pToolBar->LoadToolBar(IDR_TOOLBAR);
  119. ((CXTPControlButton*)pToolBar->GetControls()->FindControl(xtpControlButton, ID_BUTTON_PLAY, TRUE, FALSE))->SetStyle(xtpButtonIconAndCaption);
  120. ((CXTPControlButton*)pToolBar->GetControls()->FindControl(xtpControlButton, ID_BUTTON_STOP, TRUE, FALSE))->SetStyle(xtpButtonIconAndCaption);
  121. ((CXTPControlButton*)pToolBar->GetControls()->FindControl(xtpControlButton, ID_BUTTON_PAUSE, TRUE, FALSE))->SetStyle(xtpButtonIconAndCaption);
  122. pToolBar->GetControls()->CreateOriginalControls();
  123. XTPImageManager()->SetIcons(IDR_MAINFRAME);
  124. pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  125. pCommandBars->GetToolTipContext()->SetStyle(xtpToolTipOffice);
  126. pCommandBars->GetShortcutManager()->SetAccelerators(IDR_ACCELERATOR);
  127. LoadCommandBars(_T("CommandBars"));
  128. SetResize(IDC_SLIDER1,         SZ_BOTTOM_LEFT, SZ_BOTTOM_RIGHT );
  129. SetResize(IDC_STATIC_POSITION, SZ_TOP_LEFT, CXTResizePoint( 0.3f, 1) );
  130. SetResize(IDC_STATIC_RECT,     CXTResizePoint( 0.3f, 0), CXTResizePoint( 0.6f, 1) );
  131. SetResize(IDC_STATIC_LENGTH,   CXTResizePoint( 0.6f, 0), CXTResizePoint( 1, 1) );
  132. m_bInitDone = TRUE;
  133. RepositionControls();
  134. m_szMin = m_szWindow;
  135. AutoLoadPlacement(_T("Placement"));
  136. return TRUE;  // return TRUE  unless you set the focus to a control
  137. }
  138. void CDialogSampleDlg::RepositionControls()
  139. {
  140. if (m_bInRepositionControls || !m_bInitDone)
  141. return;
  142. CRect rcClientStart;
  143. CRect rcClientNow;
  144. GetClientRect(rcClientStart);
  145. if ((GetStyle() & WS_MINIMIZE) || (rcClientStart.IsRectEmpty()))
  146. return;
  147. m_bInRepositionControls = TRUE;
  148. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
  149. CRect rcBorders(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top,  rcClientStart.right - rcClientNow.right, 
  150. rcClientStart.bottom - rcClientNow.bottom);
  151. if (rcBorders != m_rcBorders)
  152. {
  153. CPoint ptOffset(rcBorders.left - m_rcBorders.left, rcBorders.top - m_rcBorders.top);
  154. CSize szOffset(rcBorders.left + rcBorders.right - m_rcBorders.left - m_rcBorders.right,
  155. rcBorders.top + rcBorders.bottom - m_rcBorders.top - m_rcBorders.bottom);
  156. CRect rcWindow;
  157. GetWindowRect(rcWindow);
  158. rcWindow.BottomRight() += szOffset;
  159. Offset(ptOffset);
  160. m_szWindow += szOffset;
  161. m_szMin += szOffset;
  162. MoveWindow(rcWindow, TRUE);
  163. }
  164. m_rcBorders = rcBorders;
  165. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
  166. m_bInRepositionControls = FALSE;
  167. }
  168. void CDialogSampleDlg::OnDestroy()
  169. {
  170. SaveCommandBars(_T("CommandBars"));
  171. CDialogSampleDlgBase::OnDestroy();
  172. }
  173. void CDialogSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
  174. {
  175. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  176. {
  177. CAboutDlg dlgAbout;
  178. dlgAbout.DoModal();
  179. }
  180. else
  181. {
  182. CDialogSampleDlgBase::OnSysCommand(nID, lParam);
  183. }
  184. }
  185. // If you add a minimize button to your dialog, you will need the code below
  186. //  to draw the icon.  For MFC applications using the document/view model,
  187. //  this is automatically done for you by the framework.
  188. void CDialogSampleDlg::OnPaint()
  189. {
  190. if (IsIconic())
  191. {
  192. CPaintDC dc(this); // device context for painting
  193. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  194. // Center icon in client rectangle
  195. int cxIcon = GetSystemMetrics(SM_CXICON);
  196. int cyIcon = GetSystemMetrics(SM_CYICON);
  197. CRect rect;
  198. GetClientRect(&rect);
  199. int x = (rect.Width() - cxIcon + 1) / 2;
  200. int y = (rect.Height() - cyIcon + 1) / 2;
  201. // Draw the icon
  202. dc.DrawIcon(x, y, m_hIcon);
  203. }
  204. else
  205. {
  206. CDialogSampleDlgBase::OnPaint();
  207. }
  208. }
  209. // The system calls this to obtain the cursor to display while the user drags
  210. //  the minimized window.
  211. HCURSOR CDialogSampleDlg::OnQueryDragIcon()
  212. {
  213. return (HCURSOR) m_hIcon;
  214. }
  215. LRESULT CDialogSampleDlg::OnKickIdle(WPARAM, LPARAM)
  216. {
  217. if (GetCommandBars()) GetCommandBars()->UpdateCommandBars();
  218. if (m_wndStatusBar.GetSafeHwnd()) m_wndStatusBar.SendMessage(WM_IDLEUPDATECMDUI, TRUE);
  219. return 0;
  220. }
  221. BOOL CDialogSampleDlg::PreTranslateMessage(MSG* pMsg)
  222. {
  223. return CDialogSampleDlgBase::PreTranslateMessage(pMsg);
  224. }
  225. void CDialogSampleDlg::OnHelpAbout()
  226. {
  227. CAboutDlg dlgAbout;
  228. dlgAbout.DoModal();
  229. }
  230. void CDialogSampleDlg::OnEmptyCommandRange(UINT)
  231. {
  232. }
  233. void CDialogSampleDlg::OnEmptyCommand()
  234. {
  235. }
  236. void CDialogSampleDlg::OnTheme(UINT nTheme)
  237. {
  238. m_eTheme = (XTPPaintTheme)(nTheme - ID_THEME_OFFICE2000);
  239. CXTPPaintManager::SetTheme(m_eTheme);
  240. RedrawWindow(0, 0, RDW_ALLCHILDREN|RDW_INVALIDATE);
  241. }
  242. void CDialogSampleDlg::OnUpdateTheme(CCmdUI* pCmdUI)
  243. {
  244. pCmdUI->SetCheck(m_eTheme == (XTPPaintTheme)(pCmdUI->m_nID - ID_THEME_OFFICE2000)? TRUE: FALSE);
  245. }
  246. void CDialogSampleDlg::OnFileExit()
  247. {
  248. OnCancel();
  249. }
  250. void CDialogSampleDlg::OnSize(UINT nType, int cx, int cy) 
  251. {
  252. CDialogSampleDlgBase::OnSize(nType, cx, cy);
  253. RepositionControls();
  254. }
  255. void CDialogSampleDlg::OnCustomize()
  256. {
  257. CXTPCustomizeSheet cs(GetCommandBars());
  258. CXTPCustomizeKeyboardPage pageKeyboard(&cs);
  259. cs.AddPage(&pageKeyboard);
  260. pageKeyboard.AddCategories(IDR_MENU);
  261. CXTPCustomizeOptionsPage pageOptions(&cs);
  262. cs.AddPage(&pageOptions);
  263. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  264. pCommands->AddCategories(IDR_MENU);
  265. pCommands->InsertAllCommandsCategory();
  266. pCommands->InsertBuiltInMenus(IDR_MENU);
  267. pCommands->InsertNewMenuCategory();
  268. cs.DoModal();
  269. }
  270. /////////////////////////////////////////////////////////////////////////////
  271. // Support for standard status bar
  272. void CDialogSampleDlg::OnUpdateKeyIndicator(CCmdUI* pCmdUI)
  273. {
  274. UINT nVK;
  275. UINT flag = 0x0001;
  276. switch (pCmdUI->m_nID)
  277. {
  278. case ID_INDICATOR_CAPS:
  279. nVK = VK_CAPITAL;
  280. break;
  281. case ID_INDICATOR_NUM:
  282. nVK = VK_NUMLOCK;
  283. break;
  284. case ID_INDICATOR_SCRL:
  285. nVK = VK_SCROLL;
  286. break;
  287. default:
  288. TRACE1("Warning: OnUpdateKeyIndicator - unknown indicator 0x%04X.n",
  289. pCmdUI->m_nID);
  290. pCmdUI->ContinueRouting();
  291. return; // not for us
  292. }
  293. pCmdUI->Enable(::GetKeyState(nVK) & flag);
  294. // enable static text based on toggled key state
  295. ASSERT(pCmdUI->m_bEnableChanged);
  296. }
  297. void CDialogSampleDlg::GetMessageString(UINT nID, CString& rMessage) const
  298. {
  299. // load appropriate string
  300. LPTSTR lpsz = rMessage.GetBuffer(255);
  301. if (AfxLoadString(nID, lpsz) != 0)
  302. {
  303. // first newline terminates actual string
  304. lpsz = _tcschr(lpsz, _T('n'));
  305. if (lpsz != NULL)
  306. *lpsz = '';
  307. }
  308. else
  309. {
  310. // not found
  311. TRACE1("Warning: no message line prompt for ID 0x%04X.n", nID);
  312. }
  313. rMessage.ReleaseBuffer();
  314. }
  315. LRESULT CDialogSampleDlg::OnSetMessageString(WPARAM wParam, LPARAM lParam)
  316. {
  317. LPCTSTR lpsz = NULL;
  318. CString strMessage;
  319. // set the message bar text
  320. if (lParam != 0)
  321. {
  322. ASSERT(wParam == 0);    // can't have both an ID and a string
  323. lpsz = (LPCTSTR)lParam; // set an explicit string
  324. }
  325. else if (wParam != 0)
  326. {
  327. // get message associated with the ID indicated by wParam
  328. GetMessageString((UINT)wParam, strMessage);
  329. lpsz = strMessage;
  330. }
  331. m_wndStatusBar.SetWindowText(lpsz);
  332. return 0;
  333. }