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

对话框与窗口

开发平台:

Visual C++

  1. // ActionsSampleView.cpp : implementation of the CActionsSampleView class
  2. //
  3. #include "stdafx.h"
  4. #include "ActionsSample.h"
  5. #include "ActionsSampleDoc.h"
  6. #include "CntrItem.h"
  7. #include "ActionsSampleView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CActionsSampleView
  15. IMPLEMENT_DYNCREATE(CActionsSampleView, CRichEditView)
  16. BEGIN_MESSAGE_MAP(CActionsSampleView, CRichEditView)
  17. //{{AFX_MSG_MAP(CActionsSampleView)
  18. // NOTE - the ClassWizard will add and remove mapping macros here.
  19. //    DO NOT EDIT what you see in these blocks of generated code!
  20. ON_WM_DESTROY()
  21. //}}AFX_MSG_MAP
  22. // Standard printing commands
  23. ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
  25. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
  26. ON_NOTIFY_REFLECT(EN_SELCHANGE, OnSelChange)
  27. ON_COMMAND(ID_CHAR_BOLD, OnCharBold)
  28. ON_COMMAND(ID_CHAR_ITALIC, OnCharItalic)
  29. ON_COMMAND(ID_CHAR_UNDERLINE, OnCharUnderline)
  30. ON_COMMAND(ID_PARA_CENTER, CRichEditView::OnParaCenter)
  31. ON_UPDATE_COMMAND_UI(ID_PARA_CENTER, CRichEditView::OnUpdateParaCenter)
  32. ON_COMMAND(ID_PARA_LEFT, CRichEditView::OnParaLeft)
  33. ON_UPDATE_COMMAND_UI(ID_PARA_LEFT, CRichEditView::OnUpdateParaLeft)
  34. ON_COMMAND(ID_PARA_RIGHT, CRichEditView::OnParaRight)
  35. ON_UPDATE_COMMAND_UI(ID_PARA_RIGHT, CRichEditView::OnUpdateParaRight)
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CActionsSampleView construction/destruction
  39. CActionsSampleView::CActionsSampleView()
  40. {
  41. // TODO: add construction code here
  42. }
  43. CActionsSampleView::~CActionsSampleView()
  44. {
  45. }
  46. BOOL CActionsSampleView::PreCreateWindow(CREATESTRUCT& cs)
  47. {
  48. // TODO: Modify the Window class or styles here by modifying
  49. //  the CREATESTRUCT cs
  50. return CRichEditView::PreCreateWindow(cs);
  51. }
  52. void CActionsSampleView::OnInitialUpdate()
  53. {
  54. CRichEditView::OnInitialUpdate();
  55. USES_CONVERSION;
  56. // Set the printing margins (720 twips = 1/2 inch).
  57. SetMargins(CRect(720, 720, 720, 720));
  58. CHARFORMAT cf;
  59. ZeroMemory(&cf, sizeof(CHARFORMAT));
  60. CString strDefFont = _T("Tahoma");
  61. cf.cbSize = sizeof(CHARFORMAT);
  62. cf.dwMask = CFM_BOLD |CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_SIZE |
  63. CFM_COLOR | CFM_OFFSET | CFM_PROTECTED | CFM_FACE;
  64. cf.dwEffects = CFE_AUTOCOLOR;
  65. cf.yHeight = 200; //10pt
  66. cf.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  67. #if (_RICHEDIT_VER >= 0x0200)
  68. lstrcpyn(cf.szFaceName, strDefFont, LF_FACESIZE);
  69. #else
  70. lstrcpynA(cf.szFaceName, T2A((LPTSTR) (LPCTSTR) strDefFont), LF_FACESIZE);
  71. #endif
  72. GetRichEditCtrl().SetDefaultCharFormat(cf);
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CActionsSampleView printing
  76. BOOL CActionsSampleView::OnPreparePrinting(CPrintInfo* pInfo)
  77. {
  78. // default preparation
  79. return DoPreparePrinting(pInfo);
  80. }
  81. void CActionsSampleView::OnDestroy()
  82. {
  83.    CRichEditView::OnDestroy();
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CActionsSampleView diagnostics
  87. #ifdef _DEBUG
  88. void CActionsSampleView::AssertValid() const
  89. {
  90. CRichEditView::AssertValid();
  91. }
  92. void CActionsSampleView::Dump(CDumpContext& dc) const
  93. {
  94. CRichEditView::Dump(dc);
  95. }
  96. CActionsSampleDoc* CActionsSampleView::GetDocument() // non-debug version is inline
  97. {
  98. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CActionsSampleDoc)));
  99. return (CActionsSampleDoc*)m_pDocument;
  100. }
  101. #endif //_DEBUG
  102. /////////////////////////////////////////////////////////////////////////////
  103. // CActionsSampleView message handlers
  104. void CActionsSampleView::OnCharBold()
  105. {
  106. CRichEditView::OnCharBold();
  107. UpdateActionsState();
  108. }
  109. void CActionsSampleView::OnCharItalic()
  110. {
  111. CRichEditView::OnCharItalic();
  112. UpdateActionsState();
  113. }
  114. void CActionsSampleView::OnCharUnderline()
  115. {
  116. CRichEditView::OnCharUnderline();
  117. UpdateActionsState();
  118. }
  119. void CActionsSampleView::OnSelChange(NMHDR* pNMHDR, LRESULT* pResult)
  120. {
  121. CRichEditView::OnSelChange(pNMHDR, pResult);
  122. UpdateActionsState();
  123. }
  124. void CActionsSampleView::UpdateActionsState()
  125. {
  126. CHARFORMAT& cfm = GetCharFormatSelection();
  127. CXTPCommandBars* pCommandBars = ((CXTPFrameWnd*)GetParentFrame())->GetCommandBars();
  128. pCommandBars->GetActions()->FindAction(ID_CHAR_BOLD)->SetChecked(
  129. (cfm.dwMask & CFM_BOLD ? (cfm.dwEffects & CFE_BOLD ? 1 : 0) : 2));
  130. pCommandBars->GetActions()->FindAction(ID_CHAR_ITALIC)->SetChecked(
  131. (cfm.dwMask & CFM_ITALIC ? (cfm.dwEffects & CFE_ITALIC ? 1 : 0) : 2));
  132. pCommandBars->GetActions()->FindAction(ID_CHAR_UNDERLINE)->SetChecked(
  133. (cfm.dwMask & CFM_UNDERLINE ? (cfm.dwEffects & CFE_UNDERLINE ? 1 : 0) : 2));
  134. }