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

对话框与窗口

开发平台:

Visual C++

  1. // PreviewPane.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 "ResourceEditor.h"
  22. #include "PreviewPane.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CPreviewPane
  30. CPreviewPane::CPreviewPane()
  31. {
  32. m_pPreviewDialog = 0;
  33. }
  34. CPreviewPane::~CPreviewPane()
  35. {
  36. SAFE_DELETE(m_pPreviewDialog);
  37. }
  38. BEGIN_MESSAGE_MAP(CPreviewPane, CWnd)
  39. //{{AFX_MSG_MAP(CPreviewPane)
  40. ON_WM_CREATE()
  41. ON_WM_SIZE()
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CPreviewPane message handlers
  46. class CPreviewPaneDialog : public CDialog
  47. {
  48. public:
  49. CPreviewPaneDialog(LPCDLGTEMPLATE pTemplate, CWnd* pParent)
  50. {
  51. CreateIndirect(pTemplate, pParent);
  52. }
  53. virtual void OnCancel()
  54. {
  55. }
  56. virtual void OnOK()
  57. {
  58. }
  59. };
  60. void CPreviewPane::ClearPreview()
  61. {
  62. if (m_pPreviewDialog)
  63. {
  64. m_pPreviewDialog->DestroyWindow();
  65. }
  66. SAFE_DELETE(m_pPreviewDialog);
  67. m_wndMenuBar.GetControls()->RemoveAll();
  68. m_wndMenuBar.MoveWindow(0, 0, 0, 0);
  69. }
  70. void CPreviewPane::ShowDialog(LPCDLGTEMPLATE pTemplate)
  71. {
  72. ClearPreview();
  73. CWnd* pWnd = GetFocus();
  74. m_pPreviewDialog = new CPreviewPaneDialog(pTemplate, this);
  75. if (!m_pPreviewDialog->m_hWnd)
  76. return;
  77. m_pPreviewDialog->ModifyStyle(WS_POPUP, WS_CHILD);
  78. m_pPreviewDialog->SetParent(this);
  79. CXTPWindowRect rc(m_pPreviewDialog);
  80. m_pPreviewDialog->MoveWindow(0, 0, rc.Width(), rc.Height());
  81. m_pPreviewDialog->ShowWindow(SW_SHOWNA);
  82. if (pWnd && IsWindow(pWnd->GetSafeHwnd())) pWnd->SetFocus();
  83. }
  84. void CPreviewPane::ShowMenu(CMenu* pMenu, XTP_RESOURCEMANAGER_LANGINFO* pLangInfo)
  85. {
  86. ClearPreview();
  87. m_wndMenuBar.LoadMenu(pMenu, TRUE);
  88. LOGFONT lfIcon;
  89. VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIcon), &lfIcon, 0));
  90. lfIcon.lfCharSet = pLangInfo->nFontCharSet;
  91. m_wndMenuBar.GetPaintManager()->SetCommandBarsFontIndirect(&lfIcon);
  92. CXTPClientRect rc(this);
  93. CSize sz = m_wndMenuBar.CalcDockingLayout(rc.Width(), LM_STRETCH | LM_HORZDOCK | LM_HORZ | LM_COMMIT);
  94. m_wndMenuBar.MoveWindow(0, 0, sz.cx, sz.cy);
  95. m_wndMenuBar.Invalidate(FALSE);
  96. }
  97. int CPreviewPane::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  98. {
  99. if (CWnd::OnCreate(lpCreateStruct) == -1)
  100. return -1;
  101. CXTPPaintManager* pPaintManager = CXTPPaintManager::CreateTheme(xtpThemeOfficeXP);
  102. m_wndMenuBar.SetPaintManager(pPaintManager);
  103. m_wndMenuBar.CreateToolBar(WS_CHILD|WS_VISIBLE, this);
  104. return 0;
  105. }
  106. void CPreviewPane::OnSize(UINT nType, int cx, int cy) 
  107. {
  108. CWnd::OnSize(nType, cx, cy);
  109. if (m_wndMenuBar.GetControls()->GetCount() > 0)
  110. {
  111. CSize sz = m_wndMenuBar.CalcDockingLayout(cx, LM_STRETCH | LM_HORZDOCK | LM_HORZ | LM_COMMIT);
  112. m_wndMenuBar.MoveWindow(0, 0, sz.cx, sz.cy);
  113. m_wndMenuBar.Invalidate(FALSE);
  114. }
  115. else
  116. {
  117. m_wndMenuBar.MoveWindow(0, 0, 0, 0);
  118. }
  119. }