MainFrm.cpp
资源名称:DXGuide.zip [点击查看]
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:9k
源码类别:
DirextX编程
开发平台:
Visual C++
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "PFM.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // COptions
- COptions::COptions()
- {
- if (!LoadOptions())
- GetDefaultSetting();
- }
- COptions::~COptions()
- {
- SaveOptions();
- }
- VOID COptions::GetDefaultSetting()
- {
- char buf[MAX_PATH];
- ::GetCurrentDirectory(MAX_PATH, buf);
- // [left] section
- m_strStartPathLeft = buf;
- m_nShowLeft = 1;
- m_nSortColLeft = 1; // start at 0, default is the second column
- m_nSortOrderLeft = 1;
- // [right] section
- m_strStartPathRight = buf;
- m_nShowRight = 1;
- m_nSortColRight = 1;
- m_nSortOrderRight = 1;
- // [colors] section
- m_nUseBackColorSelected = 0;
- m_crBackColorSelected = 0x00808000;
- m_crForeColorSelected = 0x000000FF;
- m_nUseBackColorFocused = 1;
- m_crBackColorFocused = 0x00808000;
- m_crForeColorFocused = 0x0000FFFF;
- m_crForeColorNormal = 0x00000000;
- }
- BOOL COptions::LoadOptions(LPCTSTR lpszPath/* = NULL*/)
- {
- CString strPath = lpszPath;
- if (!strPath.IsEmpty())
- strPath += strPath.Right(1)=="\"?"":"\";
- strPath += "PFM.ini";
- // [left] section
- char buf[MAX_PATH];
- ::GetPrivateProfileString("left", "path", "C:\", buf, MAX_PATH, strPath);
- m_strStartPathLeft = buf;
- m_nShowLeft = ::GetPrivateProfileInt("left", "show", 1, strPath);
- m_nSortColLeft = ::GetPrivateProfileInt("left", "SortColumn", 1, strPath);
- m_nSortOrderLeft = ::GetPrivateProfileInt("left", "SortOrder", 1, strPath);
- // [right]
- ::GetPrivateProfileString("right", "path", "C:\", buf, MAX_PATH, strPath);
- m_strStartPathRight = buf;
- m_nShowRight = ::GetPrivateProfileInt("right", "show", 1, strPath);
- m_nSortColRight = ::GetPrivateProfileInt("right", "SortColumn", 1, strPath);
- m_nSortOrderRight = ::GetPrivateProfileInt("right", "SortOrder", 1, strPath);
- // [colors]
- m_nUseBackColorSelected = ::GetPrivateProfileInt("colors", "SelectedUseBackColor", 0, strPath);
- m_crBackColorSelected = ::GetPrivateProfileInt("colors", "SelectedBackColor", 0x00808000, strPath);
- m_crForeColorSelected = ::GetPrivateProfileInt("colors", "SelectedForeColor", 0x000000FF, strPath);
- m_nUseBackColorFocused = ::GetPrivateProfileInt("colors", "FocusedUseBackColor", 1, strPath);
- m_crBackColorFocused = ::GetPrivateProfileInt("colors", "FocusedBackColor", 0x00808000, strPath);
- m_crForeColorFocused = ::GetPrivateProfileInt("colors", "FocusedForeColor", 0x0000FFFF, strPath);
- m_crForeColorNormal = ::GetPrivateProfileInt("colors", "NormalForeColor", 0x00000000, strPath);
- return TRUE;
- }
- BOOL COptions::SaveOptions(LPCTSTR lpszPath/* = NULL*/)
- {
- CString strPath = lpszPath;
- if (!strPath.IsEmpty())
- strPath += strPath.Right(1)=="\"?"":"\";
- strPath += "PFM.ini";
- CString strTmp;
- if (!WritePrivateProfileString("left", "path", m_strStartPathLeft, strPath))
- return FALSE;
- strTmp.Format("%d", m_nShowLeft);
- if (!WritePrivateProfileString("left", "show", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_nSortColLeft);
- if (!WritePrivateProfileString("left", "SortColumn", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_nSortOrderLeft);
- if (!WritePrivateProfileString("left", "SortOrder", strTmp, strPath))
- return FALSE;
- if (!WritePrivateProfileString("right", "path", m_strStartPathRight, strPath))
- return FALSE;
- strTmp.Format("%d", m_nShowRight);
- if (!WritePrivateProfileString("right", "show", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_nSortColRight);
- if (!WritePrivateProfileString("right", "SortColumn", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_nSortOrderRight);
- if (!WritePrivateProfileString("right", "SortOrder", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_nUseBackColorSelected);
- if (!WritePrivateProfileString("colors", "SelectedUseBackColor", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_crBackColorSelected);
- if (!WritePrivateProfileString("colors", "SelectedBackColor", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_crForeColorSelected);
- if (!WritePrivateProfileString("colors", "SelectedForeColor", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_nUseBackColorFocused);
- if (!WritePrivateProfileString("colors", "FocusedUseBackColor", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_crBackColorFocused);
- if (!WritePrivateProfileString("colors", "FocusedBackColor", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_crForeColorFocused);
- if (!WritePrivateProfileString("colors", "FocusedForeColor", strTmp, strPath))
- return FALSE;
- strTmp.Format("%d", m_crForeColorNormal);
- if (!WritePrivateProfileString("colors", "NormalForeColor", strTmp, strPath))
- return FALSE;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_WM_SETFOCUS()
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- // Global help commands
- ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
- ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
- ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
- ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
- m_pSplit = NULL;
- m_pListLeft = NULL;
- m_pListRight = NULL;
- }
- CMainFrame::~CMainFrame()
- {
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (!m_wndToolBar.CreateEx(this) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- if (!m_wndDlgBar.Create(this, IDR_MAINFRAME,
- CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
- {
- TRACE0("Failed to create dialogbarn");
- return -1; // fail to create
- }
- if (!m_wndReBar.Create(this) ||
- !m_wndReBar.AddBar(&m_wndToolBar) ||
- !m_wndReBar.AddBar(&m_wndDlgBar))
- {
- TRACE0("Failed to create rebarn");
- return -1; // fail to create
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Remove this if you don't want tool tips
- m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
- CBRS_TOOLTIPS | CBRS_FLYBY);
- // Create image list for filelist box
- m_pImageList = new CSystemImageList;
- // Create filelist boxes
- m_pListLeft = new CFileList(TRUE);
- m_pListRight = new CFileList(FALSE);
- m_pListLeft->Create(this, IDC_LEFTLIST);
- m_pListRight->Create(this, IDC_RIGHTLIST);
- // Set filelist's image list
- m_pListLeft->SetImageList(m_pImageList->GetImageList(TRUE), LVSIL_SMALL);
- m_pListLeft->SetImageList(m_pImageList->GetImageList(FALSE), LVSIL_NORMAL);
- m_pListRight->SetImageList(m_pImageList->GetImageList(TRUE), LVSIL_SMALL);
- m_pListRight->SetImageList(m_pImageList->GetImageList(FALSE), LVSIL_NORMAL);
- //Create a splitter bar
- m_pSplit = new CSplitterBar;
- CRect rect(0,0,8,0);
- m_pSplit->Create(WS_CHILD|WS_BORDER|WS_DLGFRAME|WS_VISIBLE, rect,this,999);
- //Insert the splitter bar between a tree and a list control
- m_pSplit->SetPanes(m_pListLeft,m_pListRight);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
- cs.lpszClass = AfxRegisterWndClass(0);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnSetFocus(CWnd* pOldWnd)
- {
- // forward focus to the view window
- if (gCurPan)
- {
- if (m_pListRight)
- m_pListRight->SetFocus();
- }
- else
- {
- if (m_pListLeft)
- m_pListLeft->SetFocus();
- }
- // m_wndView.SetFocus();
- }
- void CMainFrame::OnSize(UINT nType, int cx, int cy)
- {
- CFrameWnd::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- CRect rect(0,0,0,0);
- if (nType != SIZE_MINIMIZED)
- {
- GetClientRect(&rect);
- CRect rct;
- m_wndReBar.GetWindowRect(&rct);
- rect.top += rct.Height();
- if (m_wndStatusBar.IsWindowVisible())
- // if (m_wndStatusBar.IsWindowEnabled())
- //if ((GetMenu()->GetMenuState(ID_VIEW_STATUS_BAR, MF_BYCOMMAND) & MF_CHECKED) == 0)
- {
- m_wndStatusBar.GetWindowRect(&rct);
- rect.bottom -= rct.Height();
- }
- m_pSplit->SetPosition(&rect);
- }
- }