📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "DiskInfo.h"
#include "MainFrm.h"
#include "Common/Useful.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_SETFOCUS()
ON_WM_CLOSE()
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_GETMINMAXINFO()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_OUTBAR_NOTIFY, OnOutbarNotify)
ON_MESSAGE(WM_FOLDER_RESELECTED, UpdateBarStatus)
/*ON_COMMAND(ID_SINGLE_VIEW, OnSingleView)
ON_UPDATE_COMMAND_UI(ID_SINGLE_VIEW, OnUpdateSingleView)
ON_COMMAND(ID_TWO_VIEW_HOR, OnTwoViewHor)
ON_UPDATE_COMMAND_UI(ID_TWO_VIEW_HOR, OnUpdateTwoViewHor)
ON_COMMAND(ID_TWO_VIEW_VER, OnTwoViewVer)
ON_UPDATE_COMMAND_UI(ID_TWO_VIEW_VER, OnUpdateTwoViewVer)*/
ON_MESSAGE(WM_USER_SCANPROGRESS, OnScanProgressNotify)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
//ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
//m_nViewType = 0; // 0=Single view, 1=Double hor 2=Double ver
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndSplitterVer.CreateStatic(this, 1, 2)) return false;
//if (!m_wndSplitter.CreateView(0, 1, pContext->m_pNewViewClass, CSize(0,0), pContext)) return false;
DWORD dwf = CGfxOutBarCtrl::fRemoveItems|CGfxOutBarCtrl::fAddGroups|CGfxOutBarCtrl::fSelHighlight;
m_wndBar.Create(WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), &m_wndSplitterVer, m_wndSplitterVer.IdFromRowCol(0, 0), dwf);
m_wndBar.SetOwner(this);
m_wndBar.SetFont(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT)));
m_menuManager.m_bAutoAccel = TRUE;
m_menuManager.Install(this);
//m_menuManager.LoadToolbar(IDR_SAFECLN);
HINSTANCE hIns = AfxGetResourceHandle();
AfxSetResourceHandle(AfxGetInstanceHandle());
m_imaLarge.Create(IDB_TYPE_LIST,32,0,RGB(255, 0, 255));
if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_DISKINFO))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_menuManager.LoadToolbar(IDR_DISKINFO);
AfxSetResourceHandle(hIns);
m_wndBar.SetImageList(&m_imaLarge, CGfxOutBarCtrl::fLargeIcon);
m_wndBar.SetAnimationTickCount(1);
//m_wndBar.SetAnimSelHighlight(20);
// TODO: Remove this if you don't want tool tips or a resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
EnableToolTips();
CString strTemp, strFace, strTooltip;
strTemp.LoadString(ID_SWITCH);
AfxExtractSubString(strFace, strTemp, 2); // the third sub-string
AfxExtractSubString(strTooltip, strTemp, 1);
m_wndSwitchButton.Create(strFace, WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, ID_SWITCH);
m_wndSwitchButton.SetFont(m_wndToolBar.GetFont());
m_wndSwitchButton.ModifyFlag(CFlatButton::FBS_BORDER|CFlatButton::FBS_FOCUS,
NULL);
m_wndSwitchButton.SetTooltipText(strTooltip);
if (!m_wndStatusBar.CreateStatusBar(this, indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
//m_wndStatusBar.SetMode(1, XSB_TEXT | DT_CENTER);
//m_wndStatusBar.SetMode(2, XSB_TEXT | DT_CENTER); // Fest (Caps)
// 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);
*/
CString strShortCuts;
strShortCuts.LoadString(IDS_SHORTCUTS);
m_wndBar.AddFolder(strShortCuts, 0);
m_wndBar.SetSelFolder(0);
UpdateShortCutBar();
m_wndBar.SetCurSel(-1);
CRect r;
GetClientRect(&r);
int cxCur = AfxGetApp()->GetProfileInt("Settings", "ShortcutBarWidth", 65);
if (cxCur<=10)
cxCur = 65;
m_wndSplitterVer.SetColumnInfo( 0, cxCur, 0 );
//m_wndSplitter.SetColumnInfo( 1, w2, 0 );
//ReCreateViews();
//m_wndSplitterVer.RecalcLayout();
m_pwndView = new CDetailView();
if (!m_pwndView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW|WS_CLIPCHILDREN,
CRect(0, 0, 0, 0), &m_wndSplitterVer, m_wndSplitterVer.IdFromRowCol(0, 1), NULL))
{
TRACE0("Failed to create view window\n");
return -1;
}
m_pwndView->m_bVerMode = TRUE;
/*
UINT nID[] =
{
ID_WEB_MINISTARS,
ID_WEB_SAFECLEAN,
ID_E_MAIL,
};
m_menuManager.AddSingleBitmap(IDB_WEB_LINK, 3, nID);
*/
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);
CWinApp* app = AfxGetApp();
int s, t, b, r, l;
// only restore if there is a previously saved position
if ( -1 != (s = app->GetProfileInt("Position", "Status", -1)) &&
-1 != (t = app->GetProfileInt("Position", "Top", -1)) &&
-1 != (l = app->GetProfileInt("Position", "Left", -1)) &&
-1 != (b = app->GetProfileInt("Position", "Bottom", -1)) &&
-1 != (r = app->GetProfileInt("Position", "Right", -1))
) {
// restore the window's status
app->m_nCmdShow = s;
// restore the window's width and height
cs.cx = r - l;
cs.cy = b - t;
// the following correction is needed when the taskbar is
// at the left or top and it is not "auto-hidden"
RECT workArea;
SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
l += workArea.left;
t += workArea.top;
// make sure the window is not completely out of sight
int max_x = GetSystemMetrics(SM_CXSCREEN) -
GetSystemMetrics(SM_CXICON);
int max_y = GetSystemMetrics(SM_CYSCREEN) -
GetSystemMetrics(SM_CYICON);
cs.x = min(l, max_x);
cs.y = min(t, max_y);
}
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 (m_pwndView1 && m_pwndView->m_hWnd)
m_pwndView->SetFocus();*/
}
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// let the view have first crack at the command
if (m_pwndView->m_hWnd && m_pwndView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
/*
if (m_pwndView2->m_hWnd && m_pwndView2->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
*/
// otherwise, do default handling
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
void CMainFrame::OnClose()
{
if (m_pwndView->m_hWnd)
m_pwndView->OnStop();
CWinApp* app = AfxGetApp();
WINDOWPLACEMENT wp;
GetWindowPlacement(&wp);
app->WriteProfileInt("Position", "Status", wp.showCmd);
app->WriteProfileInt("Position", "Top", wp.rcNormalPosition.top);
app->WriteProfileInt("Position", "Left", wp.rcNormalPosition.left);
app->WriteProfileInt("Position", "Bottom", wp.rcNormalPosition.bottom);
app->WriteProfileInt("Position", "Right", wp.rcNormalPosition.right);
app->WriteProfileInt("Position", "MainFrameVisible", IsWindowVisible());
// InfoFrame
((CDiskInfoApp*)app)->m_infoFrame.GetWindowPlacement(&wp);
app->WriteProfileInt("Position", "InfoStatus", wp.showCmd);
app->WriteProfileInt("Position", "InfoTop", wp.rcNormalPosition.top);
app->WriteProfileInt("Position", "InfoLeft", wp.rcNormalPosition.left);
app->WriteProfileInt("Position", "InfoBottom", wp.rcNormalPosition.bottom);
app->WriteProfileInt("Position", "InfoRight", wp.rcNormalPosition.right);
//Save Bar width
int cxCur, cxMin;
m_wndSplitterVer.GetColumnInfo( 0, cxCur, cxMin );
if (cxCur>10)
app->WriteProfileInt("Settings", "ShortcutBarWidth", cxCur);
CFrameWnd::OnClose();
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
return TRUE;
}
//#define _nMargin_ 3
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
CRect rcToolbar;
m_wndToolBar.GetWindowRect(&rcToolbar);
ScreenToClient(&rcToolbar);
CRect rect;
m_wndToolBar.GetItemRect((m_wndToolBar.GetToolBarCtrl()).GetButtonCount()-1, &rect);
m_wndToolBar.ClientToScreen(&rect);
ScreenToClient(&rect);
int nWidth = (int)(rect.Height()*2.8);
m_wndSwitchButton.SetWindowPos(&wndTop, rcToolbar.right-nWidth,
rect.top , nWidth,rect.Height(),
SWP_NOOWNERZORDER);
}
/*
void CMainFrame::OnSingleView()
{
if (m_nViewType != 0)
{
m_nViewType = 0; // 0=Single view, 1=Double hor 2=Double ver
ReCreateViews();
}
}
void CMainFrame::OnUpdateSingleView(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_nViewType == 0);
}
void CMainFrame::OnTwoViewHor()
{
if (m_nViewType != 1)
{
m_nViewType = 1; // 0=Single view, 1=Double hor 2=Double ver
ReCreateViews();
}
}
void CMainFrame::OnUpdateTwoViewHor(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_nViewType == 1);
}
void CMainFrame::OnTwoViewVer()
{
if (m_nViewType != 2)
{
m_nViewType = 2; // 0=Single view, 1=Double hor 2=Double ver
ReCreateViews();
}
}
void CMainFrame::OnUpdateTwoViewVer(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_nViewType == 2);
}
*/
/*void CMainFrame::ReCreateViews()
{
CRect rc;
if (m_pwndView1 && m_pwndView->m_hWnd)
{
m_pwndView->DestroyWindow();
delete m_pwndView1;
m_pwndView1 = NULL;
}
if (m_pwndView2 && m_pwndView2->m_hWnd)
{
m_pwndView2->DestroyWindow();
delete m_pwndView2;
m_pwndView2 = NULL;
}
//if (!wndSplitter.CreateStatic(this, 1, 2)) return false;
// create a view to occupy the client area of the frame
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -