⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 infoframe.cpp

📁 磁盘容量扫描、但界面和程序结构非常不错
💻 CPP
字号:
// InfoFrame.cpp : implementation file
//

#include "stdafx.h"
#include "DiskInfo.h"
#include "InfoFrame.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInfoFrame

IMPLEMENT_DYNCREATE(CInfoFrame, CFrameWnd)

CInfoFrame::CInfoFrame()
{
	m_bActive = FALSE;
	m_bNeedToCenter = FALSE;
}

CInfoFrame::~CInfoFrame()
{
}


BEGIN_MESSAGE_MAP(CInfoFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CInfoFrame)
	ON_WM_CLOSE()
	ON_WM_CREATE()
	ON_WM_SETFOCUS()
	ON_WM_SIZE()
	ON_WM_GETMINMAXINFO()
	ON_COMMAND(ID_EXIT, OnExit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInfoFrame message handlers

void CInfoFrame::OnClose() 
{
	m_wndView.SendMessage(WM_COMMAND, ID_STOP, NULL);
	AfxGetMainWnd()->SendMessage(WM_CLOSE, NULL, NULL);
}

int CInfoFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// create a view to occupy the client area of the frame
	if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW|WS_CLIPCHILDREN,
		CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
	{
		TRACE0("Failed to create view window\n");
		return -1;
	}
	m_wndView.ModifyStyleEx(WS_EX_CLIENTEDGE, NULL, SWP_FRAMECHANGED);
	
	HINSTANCE hIns = AfxGetResourceHandle();
	AfxSetResourceHandle(AfxGetInstanceHandle());
	if (!m_wndToolBar.Create(this) ||
		!m_wndToolBar.LoadToolBar(IDR_INFO_FRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}
	AfxSetResourceHandle(hIns);
	
	// 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);


	return 0;
}

BOOL CInfoFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	// let the view have first crack at the command
	if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
		return TRUE;	

	return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

void CInfoFrame::OnSetFocus(CWnd* pOldWnd) 
{
	CFrameWnd::OnSetFocus(pOldWnd);
	
	m_wndView.SetFocus();	
}

BOOL CInfoFrame::PreCreateWindow(CREATESTRUCT& cs) 
{
	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", "InfoStatus",   -1)) &&
         -1 != (t = app->GetProfileInt("Position", "InfoTop",      -1)) &&
         -1 != (l = app->GetProfileInt("Position", "InfoLeft",     -1)) &&
         -1 != (b = app->GetProfileInt("Position", "InfoBottom",   -1)) &&
         -1 != (r = app->GetProfileInt("Position", "InfoRight",    -1))
       ) {

		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);
    }else
		m_bNeedToCenter = TRUE;

	return CFrameWnd::PreCreateWindow(cs);
}

void CInfoFrame::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 | SWP_SHOWWINDOW);	
}

void CInfoFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
{
	/*
	lpMMI->ptMinTrackSize.x = 540;
	lpMMI->ptMaxTrackSize.x = 540;

	//To be updated later
	int nMin, nMax;
	CRect rcView, rcWin;

	m_wndView.GetMaxMinHeight(nMin, nMax);
	if (m_wndView.m_hWnd && m_hWnd)
	{
		m_wndView.GetWindowRect(&rcView);
		GetWindowRect(&rcWin);

		lpMMI->ptMinTrackSize.y = rcWin.Height() - (rcView.Height() - nMin);
		lpMMI->ptMaxTrackSize.y = rcWin.Height() - (rcView.Height() - nMax);
	}
	/*
	else
	{
		lpMMI->ptMinTrackSize.y = nMin;
		lpMMI->ptMaxTrackSize.y = nMax;
	}
*/
	CFrameWnd::OnGetMinMaxInfo(lpMMI);
}

void CInfoFrame::ActivateFrame(int nCmdShow) 
{
	UpdateWindowSize();
	
	CFrameWnd::ActivateFrame(nCmdShow);
}

void CInfoFrame::OnOptionChanged()
{
	m_wndView.OnOptionChanged();

	if (m_bActive)
	{
		ActivateFrame();
		m_wndToolBar.RedrawWindow();
		m_wndView.SendMessage(WM_COMMAND, ID_RESCAN_ALL, NULL);
	}
}

void CInfoFrame::UpdateWindowSize()
{
	int nMin, nMax;
	CRect rcView, rcWin;
	m_wndView.GetMaxMinHeight(nMin, nMax);
	if (m_wndView.m_hWnd && m_hWnd)
	{
		m_wndView.GetWindowRect(&rcView);
		GetWindowRect(&rcWin);

		SetWindowPos(NULL, rcWin.left, rcWin.top,
			540, 
			rcWin.Height() - (rcView.Height() - nMin),
			SWP_NOMOVE|SWP_NOZORDER);



		//lpMMI->ptMinTrackSize.y = rcWin.Height() - (rcView.Height() - nMin);
		//lpMMI->ptMaxTrackSize.y = rcWin.Height() - (rcView.Height() - nMax);
	}

	//MoveWindow(rc);

	if (m_bNeedToCenter)
	{
		CenterWindow();
		m_bNeedToCenter = FALSE;
	}
}

void CInfoFrame::DoSwitch(BOOL bShow)
{
	m_bActive = bShow;

	if (bShow)
	{
		ActivateFrame();
		m_wndToolBar.RedrawWindow();
		m_wndView.UpdateDrives();
		m_wndView.UpdateFolders();
	}else
	{
		m_wndView.SendMessage(WM_COMMAND, ID_STOP, NULL);
	}
}

void CInfoFrame::OnExit() 
{
	PostMessage(WM_CLOSE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -