MainFrm.cpp
上传用户:lychee1067
上传日期:2018-01-09
资源大小:5390k
文件大小:8k
源码类别:

图形图像处理

开发平台:

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 "DirTreeView.h"
  7. #include "DirListView.h"
  8. #include "ExploreView.h"
  9. #include "struct.h"
  10. #include "DummyDoc.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CMainFrame
  18. extern CONFIG g_Config;
  19. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  20. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  21. //{{AFX_MSG_MAP(CMainFrame)
  22. ON_WM_CREATE()
  23. ON_WM_DESTROY()
  24. ON_WM_SIZE()
  25. //}}AFX_MSG_MAP
  26. ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles)
  27. ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle)
  28. END_MESSAGE_MAP()
  29. static UINT indicators[] =
  30. {
  31. ID_SEPARATOR,           // status line indicator
  32. ID_INDICATOR_CAPS,
  33. ID_INDICATOR_NUM,
  34. ID_INDICATOR_SCRL,
  35. };
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CMainFrame construction/destruction
  38. CMainFrame::CMainFrame()
  39. {
  40. // TODO: add member initialization code here
  41. }
  42. CMainFrame::~CMainFrame()
  43. {
  44. }
  45. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  46. {
  47. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  48. return -1;
  49. LoadSystemImageLists();
  50. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  51. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  52. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  53. {
  54. TRACE0("Failed to create toolbarn");
  55. return -1;      // fail to create
  56. }
  57. if (!m_wndStatusBar.Create(this) ||
  58. !m_wndStatusBar.SetIndicators(indicators,
  59.   sizeof(indicators)/sizeof(UINT)))
  60. {
  61. TRACE0("Failed to create status barn");
  62. return -1;      // fail to create
  63. }
  64. // TODO: Delete these three lines if you don't want the toolbar to
  65. //  be dockable
  66. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  67. EnableDocking(CBRS_ALIGN_ANY);
  68. DockControlBar(&m_wndToolBar);
  69. return 0;
  70. }
  71. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
  72. CCreateContext* pContext)
  73. {
  74. CDummyDoc *pDummyDoc =
  75. (CDummyDoc *) RUNTIME_CLASS
  76. (CDummyDoc)->CreateObject();
  77. CCreateContext Context;
  78. Context.m_pNewViewClass = RUNTIME_CLASS(CDirTreeView);
  79. Context.m_pCurrentDoc = pDummyDoc;
  80. if (g_Config.rcWindow.right)
  81. MoveWindow (g_Config.rcWindow, FALSE);
  82. // create splitter window
  83. if (!m_wndSplitter.CreateStatic(this, 1, 2))
  84. return FALSE;
  85. if (!m_wndEditSplit.CreateStatic(
  86. &m_wndSplitter,   // parent window is first splitter
  87. 2, 1,   // new splitter is 1 row, 2 cols
  88. WS_CHILD | WS_VISIBLE | WS_BORDER, // WS_BORDER is
  89. // needed
  90. m_wndSplitter.IdFromRowCol(0, 1)
  91.    ))
  92. {
  93. TRACE0("Failed to create nested splittern");
  94. return FALSE;
  95. }
  96. int nTreeWidth = g_Config.rcTreePane.right - g_Config.rcTreePane.left;
  97. int nListHeight = g_Config.rcListPane.bottom - g_Config.rcListPane.top;
  98. if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CDirTreeView), CSize(nTreeWidth, nTreeWidth), &Context))
  99. {
  100. m_wndSplitter.DestroyWindow();
  101. m_wndEditSplit.DestroyWindow();
  102. return FALSE;
  103. }
  104. Context.m_pNewViewClass = RUNTIME_CLASS(CDirListView);
  105. if (!m_wndEditSplit.CreateView(0, 0, RUNTIME_CLASS(CDirListView), CSize(nListHeight, nListHeight), &Context))
  106. {
  107. m_wndSplitter.DestroyWindow();
  108. m_wndEditSplit.DestroyWindow();
  109. return FALSE;
  110. }
  111. if (!m_wndEditSplit.CreateView(1, 0, RUNTIME_CLASS(CExploreView), CSize(100, 100), pContext))
  112. {
  113. m_wndSplitter.DestroyWindow();
  114. m_wndEditSplit.DestroyWindow();
  115. return FALSE;
  116. }
  117. m_pTreeView = (CDirTreeView *) m_wndSplitter.GetPane (0, 0);
  118. m_pListView = (CDirListView *) m_wndEditSplit.GetPane (0, 0);
  119. m_pEditView = (CExploreView *) m_wndEditSplit.GetPane (1, 0);
  120. SetActiveView (m_pEditView);
  121. GetWindowRect (g_Config.rcWindow);
  122. m_pTreeView->GetWindowRect (g_Config.rcTreePane);
  123. ScreenToClient (g_Config.rcTreePane);
  124. m_pListView->GetWindowRect (g_Config.rcListPane);
  125. ScreenToClient (g_Config.rcListPane);
  126. g_Config.cmdShow = SW_SHOWNORMAL;
  127. return TRUE;
  128. }
  129. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  130. {
  131. // cs.style &= ~FWS_ADDTOTITLE;
  132. if( !CFrameWnd::PreCreateWindow(cs) )
  133. return FALSE;
  134. // TODO: Modify the Window class or styles here by modifying
  135. //  the CREATESTRUCT cs
  136. return TRUE;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CMainFrame diagnostics
  140. #ifdef _DEBUG
  141. void CMainFrame::AssertValid() const
  142. {
  143. CFrameWnd::AssertValid();
  144. }
  145. void CMainFrame::Dump(CDumpContext& dc) const
  146. {
  147. CFrameWnd::Dump(dc);
  148. }
  149. #endif //_DEBUG
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CMainFrame message handlers
  152. void CMainFrame::OnUpdateViewStyles(CCmdUI* pCmdUI)
  153. {
  154. // TODO: customize or extend this code to handle choices on the
  155. // View menu.
  156. // CDirListView* pView = GetRightPane(); 
  157. CDirListView* pView = m_pListView; 
  158. // if the right-hand pane hasn't been created or isn't a view,
  159. // disable commands in our range
  160. if (pView == NULL)
  161. pCmdUI->Enable(FALSE);
  162. else
  163. {
  164. DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK;
  165. // if the command is ID_VIEW_LINEUP, only enable command
  166. // when we're in LVS_ICON or LVS_SMALLICON mode
  167. if (pCmdUI->m_nID == ID_VIEW_LINEUP)
  168. {
  169. if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON)
  170. pCmdUI->Enable();
  171. else
  172. pCmdUI->Enable(FALSE);
  173. }
  174. else
  175. {
  176. // otherwise, use dots to reflect the style of the view
  177. pCmdUI->Enable();
  178. BOOL bChecked = FALSE;
  179. switch (pCmdUI->m_nID)
  180. {
  181. case ID_VIEW_DETAILS:
  182. bChecked = (dwStyle == LVS_REPORT);
  183. break;
  184. case ID_VIEW_SMALLICON:
  185. bChecked = (dwStyle == LVS_SMALLICON);
  186. break;
  187. case ID_VIEW_LARGEICON:
  188. bChecked = (dwStyle == LVS_ICON);
  189. break;
  190. case ID_VIEW_LIST:
  191. bChecked = (dwStyle == LVS_LIST);
  192. break;
  193. default:
  194. bChecked = FALSE;
  195. break;
  196. }
  197. pCmdUI->SetRadio(bChecked ? 1 : 0);
  198. }
  199. }
  200. }
  201. void CMainFrame::OnViewStyle(UINT nCommandID)
  202. {
  203. // TODO: customize or extend this code to handle choices on the
  204. // View menu.
  205. CDirListView* pView = m_pListView;
  206. // if the right-hand pane has been created and is a CDirListView,
  207. // process the menu commands...
  208. if (pView != NULL)
  209. {
  210. DWORD dwStyle = -1;
  211. switch (nCommandID)
  212. {
  213. case ID_VIEW_LINEUP:
  214. {
  215. // ask the list control to snap to grid
  216. CListCtrl& refListCtrl = pView->GetListCtrl();
  217. refListCtrl.Arrange(LVA_SNAPTOGRID);
  218. }
  219. break;
  220. // other commands change the style on the list control
  221. case ID_VIEW_DETAILS:
  222. dwStyle = LVS_REPORT;
  223. break;
  224. case ID_VIEW_SMALLICON:
  225. dwStyle = LVS_SMALLICON;
  226. break;
  227. case ID_VIEW_LARGEICON:
  228. dwStyle = LVS_ICON;
  229. break;
  230. case ID_VIEW_LIST:
  231. dwStyle = LVS_LIST;
  232. break;
  233. }
  234. // change the style; window will repaint automatically
  235. if (dwStyle != -1)
  236. pView->ModifyStyle(LVS_TYPEMASK, dwStyle);
  237. }
  238. }
  239. void CMainFrame::LoadSystemImageLists()
  240. {
  241. if (m_LargeIcons.m_hImageList != NULL)
  242. m_LargeIcons.Detach ();
  243. SHFILEINFO sfiInfo;
  244. memset(&sfiInfo, 0, sizeof(SHFILEINFO));
  245. HIMAGELIST hIcons = (HIMAGELIST) (
  246. SHGetFileInfo (
  247. "C:\", 
  248. 0, 
  249. &sfiInfo,
  250. sizeof(sfiInfo), 
  251. SHGFI_SYSICONINDEX | SHGFI_LARGEICON)
  252. );
  253. m_LargeIcons.Attach (hIcons);
  254. if (m_SmallIcons.m_hImageList != NULL)
  255. m_SmallIcons.Detach ();
  256. hIcons = (HIMAGELIST) (
  257. SHGetFileInfo (
  258. "C:\", 
  259. 0, 
  260. &sfiInfo,
  261. sizeof(sfiInfo), 
  262. SHGFI_SYSICONINDEX | SHGFI_SMALLICON)
  263. );
  264. m_SmallIcons.Attach (hIcons);
  265. }
  266. CImageList *CMainFrame::GetImageList(UINT uiImageList)
  267. {
  268. switch (uiImageList)
  269. {
  270. case SHGFI_LARGEICON:
  271. if (m_LargeIcons.m_hImageList != NULL)
  272. return (&m_LargeIcons);
  273. break;
  274. case SHGFI_SMALLICON:
  275. if (m_SmallIcons.m_hImageList != NULL)
  276. return (&m_SmallIcons);
  277. break;
  278. default:
  279. break;
  280. }
  281. return (NULL);
  282. }
  283. void CMainFrame::OnDestroy() 
  284. {
  285. m_LargeIcons.Detach ();
  286. m_SmallIcons.Detach ();
  287. CFrameWnd::OnDestroy();
  288. }
  289. void CMainFrame::OnSize(UINT nType, int cx, int cy) 
  290. {
  291. CFrameWnd::OnSize(nType, cx, cy);
  292. GetWindowRect (g_Config.rcWindow);
  293. }