📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "MultiDrives.h"
#include "MainFrm.h"
// #include "LeftView.h"
#include "MultiDrivesView.h"
#include "DriveView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
// ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles)
// ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle)
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
bSplitterCreated = FALSE;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
// | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
// !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
// {
// TRACE0("Failed to create toolbar\n");
// return -1; // fail to create
// }
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
// m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
// EnableDocking(CBRS_ALIGN_ANY);
// DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
int MPPR = 5;
int iDriveCount = GetDriveCount();
// create splitter window
if (!m_wndSplitter.CreateStatic(this, (iDriveCount > MPPR ? 3:2) , 1) )
return FALSE;
if(!m_wndSplitter.CreateView( (iDriveCount > MPPR ? 2:1), 0, RUNTIME_CLASS(CMultiDrivesView), CSize(0, 0), pContext))
return FALSE;
int i, nCount, nBalance;
nCount = iDriveCount / 2;
nBalance = iDriveCount - nCount;
if (!m_wndSplitter1.CreateStatic(
&m_wndSplitter, // our parent window is the first splitter
1, (iDriveCount > MPPR ? nCount : iDriveCount), // the new splitter is 2 rows, 1 column
WS_CHILD | WS_VISIBLE | WS_BORDER, // style, WS_BORDER is needed
m_wndSplitter.IdFromRowCol(0, 0)
// new splitter is in the first row, 2nd column of first splitter
))
{
TRACE0("Failed to create nested splitter\n");
return FALSE;
}
if(iDriveCount > MPPR)
{
if (!m_wndSplitter2.CreateStatic(
&m_wndSplitter, // our parent window is the first splitter
1, nBalance, // the new splitter is 2 rows, 1 column
WS_CHILD | WS_VISIBLE | WS_BORDER, // style, WS_BORDER is needed
m_wndSplitter.IdFromRowCol(1, 0)
// new splitter is in the first row, 2nd column of first splitter
))
{
TRACE0("Failed to create nested splitter\n");
return FALSE;
}
}
for(i = 0; i <= (iDriveCount > MPPR ? nCount : iDriveCount) -1; i++)
{
if (!m_wndSplitter1.CreateView(0, i, RUNTIME_CLASS(CDriveView), CSize(0, 0), pContext))
{
m_wndSplitter1.DestroyWindow();
return FALSE;
}
}
if(iDriveCount > MPPR)
{
for(i = 0; i <= nBalance-1 ; i++)
{
if (!m_wndSplitter2.CreateView(0, i, RUNTIME_CLASS(CDriveView), CSize(0, 0), pContext))
{
m_wndSplitter2.DestroyWindow();
return FALSE;
}
}
}
UpdateTreeViews(&m_wndSplitter1, 0 , iDriveCount > 5 ? nCount : iDriveCount);
if(iDriveCount > 5)
UpdateTreeViews(&m_wndSplitter2, nBalance , iDriveCount);
bSplitterCreated = TRUE;
return TRUE;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
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
int CMainFrame::GetDriveCount()
{
char *ptr;
int i=0;
GetLogicalDriveStrings(500,m_drives_name);
ptr=m_drives_name;
while (*ptr)
{
ptr+=strlen(ptr)+1;
i++;
}
return i;
}
int CMainFrame::UpdateTreeViews(CSplitterWnd* m_Splitter , int nStart , int nEnd)
{
int nCount = 0;
char *ptr;
GetLogicalDriveStrings(500,m_drives_name);
ptr=m_drives_name;
for(int i = 0 ; i <= nStart-1 ; i++)
ptr+=strlen(ptr)+1;
while (*ptr)
{
CDriveView* lv = (CDriveView*)m_Splitter->GetPane(0,nCount);
lv->InitializeView(ptr , 0);
ptr+=strlen(ptr)+1;
nCount++;
if(nCount >= nEnd)
break;
}
return 0;
}
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(bSplitterCreated)
{
int iHeight = cy/m_wndSplitter.GetRowCount()+30;
m_wndSplitter.SetRowInfo(0, iHeight, 50);
m_wndSplitter.SetRowInfo(1, iHeight, 50);
int iWidth = cx/m_wndSplitter1.GetColumnCount()+50;
for(int i = 0 ; i <= m_wndSplitter1.GetColumnCount()-1;i++)
m_wndSplitter1.SetColumnInfo(i, iWidth , 100);
if(m_wndSplitter.GetRowCount() > 2)
{
iWidth = cx/m_wndSplitter2.GetColumnCount()+50;
for(int i = 0 ; i <= m_wndSplitter2.GetColumnCount()-1;i++)
m_wndSplitter2.SetColumnInfo(i, iWidth , 100);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -