MainFrm.cpp
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:9k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "PFM.h"
  5. #include "MainFrm.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // COptions
  13. COptions::COptions()
  14. {
  15. if (!LoadOptions())
  16. GetDefaultSetting();
  17. }
  18. COptions::~COptions()
  19. {
  20. SaveOptions();
  21. }
  22. VOID COptions::GetDefaultSetting()
  23. {
  24. char buf[MAX_PATH];
  25. ::GetCurrentDirectory(MAX_PATH, buf);
  26. // [left] section
  27. m_strStartPathLeft = buf;
  28. m_nShowLeft = 1;
  29. m_nSortColLeft = 1; // start at 0, default is the second column
  30. m_nSortOrderLeft = 1;
  31. // [right] section
  32. m_strStartPathRight = buf;
  33. m_nShowRight = 1;
  34. m_nSortColRight = 1;
  35. m_nSortOrderRight = 1;
  36. // [colors] section
  37. m_nUseBackColorSelected = 0;
  38. m_crBackColorSelected = 0x00808000;
  39. m_crForeColorSelected = 0x000000FF;
  40. m_nUseBackColorFocused = 1;
  41. m_crBackColorFocused = 0x00808000;
  42. m_crForeColorFocused = 0x0000FFFF;
  43. m_crForeColorNormal = 0x00000000;
  44. }
  45. BOOL COptions::LoadOptions(LPCTSTR lpszPath/* = NULL*/)
  46. {
  47. CString strPath = lpszPath;
  48. if (!strPath.IsEmpty())
  49. strPath += strPath.Right(1)=="\"?"":"\";
  50. strPath += "PFM.ini";
  51. // [left] section
  52. char buf[MAX_PATH];
  53. ::GetPrivateProfileString("left", "path", "C:\", buf, MAX_PATH, strPath);
  54. m_strStartPathLeft = buf;
  55. m_nShowLeft = ::GetPrivateProfileInt("left", "show", 1, strPath);
  56. m_nSortColLeft = ::GetPrivateProfileInt("left", "SortColumn", 1, strPath);
  57. m_nSortOrderLeft = ::GetPrivateProfileInt("left", "SortOrder", 1, strPath);
  58. // [right]
  59. ::GetPrivateProfileString("right", "path", "C:\", buf, MAX_PATH, strPath);
  60. m_strStartPathRight = buf;
  61. m_nShowRight = ::GetPrivateProfileInt("right", "show", 1, strPath);
  62. m_nSortColRight = ::GetPrivateProfileInt("right", "SortColumn", 1, strPath);
  63. m_nSortOrderRight = ::GetPrivateProfileInt("right", "SortOrder", 1, strPath);
  64. // [colors]
  65. m_nUseBackColorSelected = ::GetPrivateProfileInt("colors", "SelectedUseBackColor", 0, strPath);
  66. m_crBackColorSelected = ::GetPrivateProfileInt("colors", "SelectedBackColor", 0x00808000, strPath);
  67. m_crForeColorSelected = ::GetPrivateProfileInt("colors", "SelectedForeColor", 0x000000FF, strPath);
  68. m_nUseBackColorFocused = ::GetPrivateProfileInt("colors", "FocusedUseBackColor", 1, strPath);
  69. m_crBackColorFocused = ::GetPrivateProfileInt("colors", "FocusedBackColor", 0x00808000, strPath);
  70. m_crForeColorFocused = ::GetPrivateProfileInt("colors", "FocusedForeColor", 0x0000FFFF, strPath);
  71. m_crForeColorNormal = ::GetPrivateProfileInt("colors", "NormalForeColor", 0x00000000, strPath);
  72. return TRUE;
  73. }
  74. BOOL COptions::SaveOptions(LPCTSTR lpszPath/* = NULL*/)
  75. {
  76. CString strPath = lpszPath;
  77. if (!strPath.IsEmpty())
  78. strPath += strPath.Right(1)=="\"?"":"\";
  79. strPath += "PFM.ini";
  80. CString strTmp;
  81. if (!WritePrivateProfileString("left", "path", m_strStartPathLeft, strPath))
  82. return FALSE;
  83. strTmp.Format("%d", m_nShowLeft);
  84. if (!WritePrivateProfileString("left", "show", strTmp, strPath))
  85. return FALSE;
  86. strTmp.Format("%d", m_nSortColLeft);
  87. if (!WritePrivateProfileString("left", "SortColumn", strTmp, strPath))
  88. return FALSE;
  89. strTmp.Format("%d", m_nSortOrderLeft);
  90. if (!WritePrivateProfileString("left", "SortOrder", strTmp, strPath))
  91. return FALSE;
  92. if (!WritePrivateProfileString("right", "path", m_strStartPathRight, strPath))
  93. return FALSE;
  94. strTmp.Format("%d", m_nShowRight);
  95. if (!WritePrivateProfileString("right", "show", strTmp, strPath))
  96. return FALSE;
  97. strTmp.Format("%d", m_nSortColRight);
  98. if (!WritePrivateProfileString("right", "SortColumn", strTmp, strPath))
  99. return FALSE;
  100. strTmp.Format("%d", m_nSortOrderRight);
  101. if (!WritePrivateProfileString("right", "SortOrder", strTmp, strPath))
  102. return FALSE;
  103. strTmp.Format("%d", m_nUseBackColorSelected);
  104. if (!WritePrivateProfileString("colors", "SelectedUseBackColor", strTmp, strPath))
  105. return FALSE;
  106. strTmp.Format("%d", m_crBackColorSelected);
  107. if (!WritePrivateProfileString("colors", "SelectedBackColor", strTmp, strPath))
  108. return FALSE;
  109. strTmp.Format("%d", m_crForeColorSelected);
  110. if (!WritePrivateProfileString("colors", "SelectedForeColor", strTmp, strPath))
  111. return FALSE;
  112. strTmp.Format("%d", m_nUseBackColorFocused);
  113. if (!WritePrivateProfileString("colors", "FocusedUseBackColor", strTmp, strPath))
  114. return FALSE;
  115. strTmp.Format("%d", m_crBackColorFocused);
  116. if (!WritePrivateProfileString("colors", "FocusedBackColor", strTmp, strPath))
  117. return FALSE;
  118. strTmp.Format("%d", m_crForeColorFocused);
  119. if (!WritePrivateProfileString("colors", "FocusedForeColor", strTmp, strPath))
  120. return FALSE;
  121. strTmp.Format("%d", m_crForeColorNormal);
  122. if (!WritePrivateProfileString("colors", "NormalForeColor", strTmp, strPath))
  123. return FALSE;
  124. return TRUE;
  125. }
  126. /////////////////////////////////////////////////////////////////////////////
  127. // CMainFrame
  128. IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
  129. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  130. //{{AFX_MSG_MAP(CMainFrame)
  131. ON_WM_CREATE()
  132. ON_WM_SETFOCUS()
  133. ON_WM_SIZE()
  134. //}}AFX_MSG_MAP
  135. // Global help commands
  136. ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
  137. ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
  138. ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
  139. ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
  140. END_MESSAGE_MAP()
  141. static UINT indicators[] =
  142. {
  143. ID_SEPARATOR,           // status line indicator
  144. ID_INDICATOR_CAPS,
  145. ID_INDICATOR_NUM,
  146. ID_INDICATOR_SCRL,
  147. };
  148. /////////////////////////////////////////////////////////////////////////////
  149. // CMainFrame construction/destruction
  150. CMainFrame::CMainFrame()
  151. {
  152. // TODO: add member initialization code here
  153. m_pSplit = NULL;
  154. m_pListLeft = NULL;
  155. m_pListRight = NULL;
  156. }
  157. CMainFrame::~CMainFrame()
  158. {
  159. }
  160. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  161. {
  162. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  163. return -1;
  164. if (!m_wndToolBar.CreateEx(this) ||
  165. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  166. {
  167. TRACE0("Failed to create toolbarn");
  168. return -1;      // fail to create
  169. }
  170. if (!m_wndDlgBar.Create(this, IDR_MAINFRAME, 
  171. CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
  172. {
  173. TRACE0("Failed to create dialogbarn");
  174. return -1; // fail to create
  175. }
  176. if (!m_wndReBar.Create(this) ||
  177. !m_wndReBar.AddBar(&m_wndToolBar) ||
  178. !m_wndReBar.AddBar(&m_wndDlgBar))
  179. {
  180. TRACE0("Failed to create rebarn");
  181. return -1;      // fail to create
  182. }
  183. if (!m_wndStatusBar.Create(this) ||
  184. !m_wndStatusBar.SetIndicators(indicators,
  185.   sizeof(indicators)/sizeof(UINT)))
  186. {
  187. TRACE0("Failed to create status barn");
  188. return -1;      // fail to create
  189. }
  190. // TODO: Remove this if you don't want tool tips
  191. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  192. CBRS_TOOLTIPS | CBRS_FLYBY);
  193. // Create image list for filelist box
  194. m_pImageList = new CSystemImageList;
  195. // Create filelist boxes
  196. m_pListLeft = new CFileList(TRUE);
  197. m_pListRight = new CFileList(FALSE);
  198. m_pListLeft->Create(this, IDC_LEFTLIST);
  199. m_pListRight->Create(this, IDC_RIGHTLIST);
  200. // Set filelist's image list
  201. m_pListLeft->SetImageList(m_pImageList->GetImageList(TRUE), LVSIL_SMALL);
  202. m_pListLeft->SetImageList(m_pImageList->GetImageList(FALSE), LVSIL_NORMAL);
  203. m_pListRight->SetImageList(m_pImageList->GetImageList(TRUE), LVSIL_SMALL);
  204. m_pListRight->SetImageList(m_pImageList->GetImageList(FALSE), LVSIL_NORMAL);
  205. //Create a splitter bar
  206. m_pSplit = new CSplitterBar;
  207. CRect rect(0,0,8,0);
  208. m_pSplit->Create(WS_CHILD|WS_BORDER|WS_DLGFRAME|WS_VISIBLE, rect,this,999);
  209. //Insert the splitter bar between a tree and a list control
  210. m_pSplit->SetPanes(m_pListLeft,m_pListRight);
  211. return 0;
  212. }
  213. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  214. {
  215. if( !CFrameWnd::PreCreateWindow(cs) )
  216. return FALSE;
  217. // TODO: Modify the Window class or styles here by modifying
  218. //  the CREATESTRUCT cs
  219. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  220. cs.lpszClass = AfxRegisterWndClass(0);
  221. return TRUE;
  222. }
  223. /////////////////////////////////////////////////////////////////////////////
  224. // CMainFrame diagnostics
  225. #ifdef _DEBUG
  226. void CMainFrame::AssertValid() const
  227. {
  228. CFrameWnd::AssertValid();
  229. }
  230. void CMainFrame::Dump(CDumpContext& dc) const
  231. {
  232. CFrameWnd::Dump(dc);
  233. }
  234. #endif //_DEBUG
  235. /////////////////////////////////////////////////////////////////////////////
  236. // CMainFrame message handlers
  237. void CMainFrame::OnSetFocus(CWnd* pOldWnd)
  238. {
  239. // forward focus to the view window
  240. if (gCurPan)
  241. {
  242. if (m_pListRight)
  243. m_pListRight->SetFocus();
  244. }
  245. else
  246. {
  247. if (m_pListLeft)
  248. m_pListLeft->SetFocus();
  249. }
  250. // m_wndView.SetFocus();
  251. }
  252. void CMainFrame::OnSize(UINT nType, int cx, int cy) 
  253. {
  254. CFrameWnd::OnSize(nType, cx, cy);
  255. // TODO: Add your message handler code here
  256. CRect rect(0,0,0,0);
  257. if (nType != SIZE_MINIMIZED)
  258. {
  259. GetClientRect(&rect);
  260. CRect rct;
  261. m_wndReBar.GetWindowRect(&rct);
  262. rect.top += rct.Height();
  263. if (m_wndStatusBar.IsWindowVisible())
  264. // if (m_wndStatusBar.IsWindowEnabled())
  265. //if ((GetMenu()->GetMenuState(ID_VIEW_STATUS_BAR, MF_BYCOMMAND) & MF_CHECKED) == 0)
  266. {
  267. m_wndStatusBar.GetWindowRect(&rct);
  268. rect.bottom -= rct.Height();
  269. }
  270. m_pSplit->SetPosition(&rect);
  271. }
  272. }