MainFrm.cpp
上传用户:jorden
上传日期:2022-08-09
资源大小:83k
文件大小:6k
源码类别:

TreeView控件

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "explorer.h"
  5. #include "MainFrm.h"
  6. #include "LeftView.h"
  7. #include "explorerView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMainFrame
  15. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  16. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  17. //{{AFX_MSG_MAP(CMainFrame)
  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_CREATE()
  21. //}}AFX_MSG_MAP
  22. ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles)
  23. ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle)
  24. END_MESSAGE_MAP()
  25. static UINT indicators[] =
  26. {
  27. ID_SEPARATOR,           // status line indicator
  28. ID_INDICATOR_CAPS,
  29. ID_INDICATOR_NUM,
  30. ID_INDICATOR_SCRL,
  31. };
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CMainFrame construction/destruction
  34. CMainFrame::CMainFrame()
  35. {
  36. // TODO: add member initialization code here
  37. }
  38. CMainFrame::~CMainFrame()
  39. {
  40. }
  41. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  42. {
  43. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  44. return -1;
  45. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  46. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  47. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  48. {
  49. TRACE0("Failed to create toolbarn");
  50. return -1;      // fail to create
  51. }
  52. if (!m_wndStatusBar.Create(this) ||
  53. !m_wndStatusBar.SetIndicators(indicators,
  54.   sizeof(indicators)/sizeof(UINT)))
  55. {
  56. TRACE0("Failed to create status barn");
  57. return -1;      // fail to create
  58. }
  59. // TODO: Delete these three lines if you don't want the toolbar to
  60. //  be dockable
  61. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  62. EnableDocking(CBRS_ALIGN_ANY);
  63. DockControlBar(&m_wndToolBar);
  64. return 0;
  65. }
  66. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
  67. CCreateContext* pContext)
  68. {
  69. // create splitter window
  70. if (!m_wndSplitter.CreateStatic(this, 1, 2))
  71. return FALSE;
  72. if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(100, 100), pContext) ||
  73. !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CExplorerView), CSize(100, 100), pContext))
  74. {
  75. m_wndSplitter.DestroyWindow();
  76. return FALSE;
  77. }
  78. m_wndSplitter.SetColumnInfo(0, 200, 100);
  79. return TRUE;
  80. }
  81. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  82. {
  83. if( !CFrameWnd::PreCreateWindow(cs) )
  84. return FALSE;
  85. // TODO: Modify the Window class or styles here by modifying
  86. //  the CREATESTRUCT cs
  87. return TRUE;
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CMainFrame diagnostics
  91. #ifdef _DEBUG
  92. void CMainFrame::AssertValid() const
  93. {
  94. CFrameWnd::AssertValid();
  95. }
  96. void CMainFrame::Dump(CDumpContext& dc) const
  97. {
  98. CFrameWnd::Dump(dc);
  99. }
  100. #endif //_DEBUG
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CMainFrame message handlers
  103. CExplorerView* CMainFrame::GetRightPane()
  104. {
  105. // CWnd* pWnd = m_wndSplitter.GetPane(0, 1);
  106. // CExplorerView* pView = DYNAMIC_DOWNCAST(CExplorerView, pWnd);
  107. CExplorerView* pView=(CExplorerView*)m_wndSplitter.GetPane(0, 1);
  108. return pView;
  109. }
  110. void CMainFrame::OnUpdateViewStyles(CCmdUI* pCmdUI)
  111. {
  112. // TODO: customize or extend this code to handle choices on the
  113. // View menu.
  114. CExplorerView* pView = GetRightPane(); 
  115. // if the right-hand pane hasn't been created or isn't a view,
  116. // disable commands in our range
  117. if (pView == NULL)
  118. pCmdUI->Enable(FALSE);
  119. else
  120. {
  121. DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK;
  122. // if the command is ID_VIEW_LINEUP, only enable command
  123. // when we're in LVS_ICON or LVS_SMALLICON mode
  124. if (pCmdUI->m_nID == ID_VIEW_LINEUP)
  125. {
  126. if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON)
  127. pCmdUI->Enable();
  128. else
  129. pCmdUI->Enable(FALSE);
  130. }
  131. else
  132. {
  133. // otherwise, use dots to reflect the style of the view
  134. pCmdUI->Enable();
  135. BOOL bChecked = FALSE;
  136. switch (pCmdUI->m_nID)
  137. {
  138. case ID_VIEW_DETAILS:
  139. bChecked = (dwStyle == LVS_REPORT);
  140. break;
  141. case ID_VIEW_SMALLICON:
  142. bChecked = (dwStyle == LVS_SMALLICON);
  143. break;
  144. case ID_VIEW_LARGEICON:
  145. bChecked = (dwStyle == LVS_ICON);
  146. break;
  147. case ID_VIEW_LIST:
  148. bChecked = (dwStyle == LVS_LIST);
  149. break;
  150. default:
  151. bChecked = FALSE;
  152. break;
  153. }
  154. pCmdUI->SetRadio(bChecked ? 1 : 0);
  155. }
  156. }
  157. }
  158. void CMainFrame::OnViewStyle(UINT nCommandID)
  159. {
  160. // TODO: customize or extend this code to handle choices on the
  161. // View menu.
  162. CExplorerView* pView = GetRightPane();
  163. // if the right-hand pane has been created and is a CExplorerView,
  164. // process the menu commands...
  165. if (pView != NULL)
  166. {
  167. DWORD dwStyle = -1;
  168. switch (nCommandID)
  169. {
  170. case ID_VIEW_LINEUP:
  171. {
  172. // ask the list control to snap to grid
  173. CListCtrl& refListCtrl = pView->GetListCtrl();
  174. refListCtrl.Arrange(LVA_SNAPTOGRID);
  175. }
  176. break;
  177. // other commands change the style on the list control
  178. case ID_VIEW_DETAILS:
  179. dwStyle = LVS_REPORT;
  180. break;
  181. case ID_VIEW_SMALLICON:
  182. dwStyle = LVS_SMALLICON;
  183. break;
  184. case ID_VIEW_LARGEICON:
  185. dwStyle = LVS_ICON;
  186. break;
  187. case ID_VIEW_LIST:
  188. dwStyle = LVS_LIST;
  189. break;
  190. }
  191. // change the style; window will repaint automatically
  192. if (dwStyle != -1)
  193. pView->ModifyStyle(LVS_TYPEMASK, dwStyle);
  194. }
  195. }