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

对话框与窗口

开发平台:

Visual C++

  1. // ListBoxSampleView.cpp : implementation of the CListBoxSampleView class
  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 "ListBoxSample.h"
  22. #include "ListBoxSampleDoc.h"
  23. #include "ListBoxSampleView.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CListBoxSampleView
  31. IMPLEMENT_DYNCREATE(CListBoxSampleView, CEditView)
  32. BEGIN_MESSAGE_MAP(CListBoxSampleView, CEditView)
  33. //{{AFX_MSG_MAP(CListBoxSampleView)
  34. // NOTE - the ClassWizard will add and remove mapping macros here.
  35. //    DO NOT EDIT what you see in these blocks of generated code!
  36. //}}AFX_MSG_MAP
  37. // Standard printing commands
  38. ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
  39. ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
  40. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
  41. ON_XTP_EXECUTE(ID_EDIT_UNDO, OnEditUndo)
  42. ON_NOTIFY(XTP_LBN_SELCHANGE, ID_EDIT_UNDO, OnListBoxControlSelChange)
  43. ON_NOTIFY(XTP_LBN_POPUP, ID_EDIT_UNDO, OnListBoxControlPoup)
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CListBoxSampleView construction/destruction
  47. CListBoxSampleView::CListBoxSampleView()
  48. {
  49. // TODO: add construction code here
  50. }
  51. CListBoxSampleView::~CListBoxSampleView()
  52. {
  53. }
  54. BOOL CListBoxSampleView::PreCreateWindow(CREATESTRUCT& cs)
  55. {
  56. // TODO: Modify the Window class or styles here by modifying
  57. //  the CREATESTRUCT cs
  58. BOOL bPreCreated = CEditView::PreCreateWindow(cs);
  59. cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);   // Enable word-wrapping
  60. return bPreCreated;
  61. }
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CListBoxSampleView drawing
  64. void CListBoxSampleView::OnDraw(CDC* /*pDC*/)
  65. {
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CListBoxSampleView printing
  69. BOOL CListBoxSampleView::OnPreparePrinting(CPrintInfo* pInfo)
  70. {
  71. // default CEditView preparation
  72. return CEditView::OnPreparePrinting(pInfo);
  73. }
  74. void CListBoxSampleView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  75. {
  76. // Default CEditView begin printing.
  77. CEditView::OnBeginPrinting(pDC, pInfo);
  78. }
  79. void CListBoxSampleView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
  80. {
  81. // Default CEditView end printing
  82. CEditView::OnEndPrinting(pDC, pInfo);
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CListBoxSampleView diagnostics
  86. #ifdef _DEBUG
  87. void CListBoxSampleView::AssertValid() const
  88. {
  89. CEditView::AssertValid();
  90. }
  91. void CListBoxSampleView::Dump(CDumpContext& dc) const
  92. {
  93. CEditView::Dump(dc);
  94. }
  95. CListBoxSampleDoc* CListBoxSampleView::GetDocument() // non-debug version is inline
  96. {
  97. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CListBoxSampleDoc)));
  98. return (CListBoxSampleDoc*)m_pDocument;
  99. }
  100. #endif //_DEBUG
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CListBoxSampleView message handlers
  103. void CListBoxSampleView::OnEditUndo(NMHDR* pNMHDR, LRESULT* pResult)
  104. {
  105. if (((NMXTPCONTROL*)pNMHDR)->pControl->GetType() == xtpControlSplitButtonPopup)
  106. {
  107. AfxMessageBox(_T("Undo last command"));
  108. *pResult = 1; // Handled;
  109. }
  110. CXTPControlListBox* pControlListBox = DYNAMIC_DOWNCAST(CXTPControlListBox, ((NMXTPCONTROL*)pNMHDR)->pControl);
  111. if (pControlListBox)
  112. {
  113. CString str;
  114. str.Format(_T("Undo last %i actions"), pControlListBox->GetListCtrl()->GetSelCount());
  115. AfxMessageBox(str);
  116. *pResult = 1; // Handled;
  117. }
  118. }
  119. CXTPControlStatic* CListBoxSampleView::FindInfoControl(CXTPControlListBox* pControlListBox)
  120. {
  121. CXTPCommandBar* pCommandBar = pControlListBox->GetParent();
  122. for (int i = 0; i < pCommandBar->GetControls()->GetCount(); i++)
  123. {
  124. CXTPControlStatic* pControlStatic = DYNAMIC_DOWNCAST(CXTPControlStatic, pCommandBar->GetControl(i));
  125. if (pControlStatic && pControlStatic->GetID() == pControlListBox->GetID())
  126. {
  127. return pControlStatic;
  128. }
  129. }
  130. return NULL;
  131. }
  132. void CListBoxSampleView::OnListBoxControlSelChange(NMHDR* pNMHDR, LRESULT* pRes)
  133. {
  134. ASSERT(pNMHDR != NULL);
  135. ASSERT(pRes != NULL);
  136. CXTPControlListBox* pControlListBox = DYNAMIC_DOWNCAST(CXTPControlListBox, ((NMXTPCONTROL*)pNMHDR)->pControl);
  137. if (pControlListBox)
  138. {
  139. CXTPControlStatic* pInfo = FindInfoControl(pControlListBox);
  140. if (pInfo)
  141. {
  142. CString str;
  143. str.Format(_T("Undo %i Actions"), pControlListBox->GetListCtrl()->GetSelCount());
  144. pInfo->SetCaption(str);
  145. pInfo->DelayRedrawParent();
  146. }
  147. *pRes = 1;
  148. }
  149. }
  150. void CListBoxSampleView::OnListBoxControlPoup(NMHDR* pNMHDR, LRESULT* pRes)
  151. {
  152. ASSERT(pNMHDR != NULL);
  153. ASSERT(pRes != NULL);
  154. CXTPControlListBox* pControlListBox = DYNAMIC_DOWNCAST(CXTPControlListBox, ((NMXTPCONTROL*)pNMHDR)->pControl);
  155. if (pControlListBox)
  156. {
  157. CListBox* pListBox = pControlListBox->GetListCtrl();
  158. pListBox->ResetContent();
  159. int nCount = RAND_S() % 20 + 3;
  160. for (int i = 0; i < nCount; i++)
  161. {
  162. CString str;
  163. str.Format(_T("Undo String %i"), i + 1);
  164. pListBox->AddString(str);
  165. }
  166. CXTPControlStatic* pInfo = FindInfoControl(pControlListBox);
  167. if (pInfo)
  168. {
  169. CString str;
  170. pInfo->SetCaption(_T("Undo 0 Actions"));
  171. pInfo->DelayRedrawParent();
  172. }
  173. *pRes = 1;
  174. }
  175. }