📄 diskinfo.cpp
字号:
// DiskInfo.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "DiskInfo.h"
#include "MainFrm.h"
#include "Common/Useful.h"
#include "Common/DrawEx.h"
#include "OptionSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const UINT wm_Activate =::RegisterWindowMessage("MinistarsDiskInfoProActivate");
/////////////////////////////////////////////////////////////////////////////
// CDiskInfoApp
BEGIN_MESSAGE_MAP(CDiskInfoApp, CWinApp)
//{{AFX_MSG_MAP(CDiskInfoApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_SWITCH, OnSwitchMainWindow)
ON_COMMAND(ID_OPTIONS, OnOptions)
//}}AFX_MSG_MAP
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
const UINT WM_DiskInfoOptionChanged =::RegisterWindowMessage("DiskInfoOptionChanged");
/////////////////////////////////////////////////////////////////////////////
// CDiskInfoApp construction
CDiskInfoApp::CDiskInfoApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
//First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszAppName);
//Change the name of the application file.
//The CWinApp destructor will free the memory.
m_pszAppName = _tcsdup(_T("DiskInfo Pro"));
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CDiskInfoApp object
CDiskInfoApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDiskInfoApp initialization
BOOL CDiskInfoApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Ministars Software"));
// Detect another instance of our app
if (!FirstInstance())
return FALSE;
// To create the main window, this code creates a new frame window
// object and then sets it as the application's main window object.
HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//Create MainFrame
CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame;
pFrame->LoadFrame(IDR_DISKINFO,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
NULL);
pFrame->SetIcon(hIcon, TRUE); // Set big icon
//Create InfoFrame
CString strFullString, strTitle;
if (strFullString.LoadString(IDR_DISKINFO))
AfxExtractSubString(strTitle, strFullString, 0); // first sub-string
m_infoFrame.Create(NULL, strTitle, WS_OVERLAPPED|WS_MINIMIZEBOX
|WS_SYSMENU); // WS_THICKFRAME
m_infoFrame.ModifyStyleEx(WS_EX_CLIENTEDGE, NULL, SWP_FRAMECHANGED);
m_infoFrame.LoadAccelTable(MAKEINTRESOURCE(IDR_DISKINFO));
m_infoFrame.SetIcon(hIcon, TRUE); // Set big icon
//Display one of the frames
int nStartMode = GetProfileInt("Settings", "StartUpMode", 0);
int nVisible = GetProfileInt("Position", "MainFrameVisible", 0);
if ((nStartMode == 0 && nVisible) || nStartMode == 1)
{
m_infoFrame.ShowWindow(SW_HIDE);
m_infoFrame.EnableWindow(FALSE);
pFrame->ActivateFrame(m_nCmdShow);
pFrame->ShowWindow(m_nCmdShow);
pFrame->UpdateWindow();
m_infoFrame.UpdateWindow();
pFrame->DoSwitch(TRUE);
}else
{
pFrame->ShowWindow(SW_HIDE);
pFrame->EnableWindow(FALSE);
m_infoFrame.ActivateFrame(m_nCmdShow);
m_infoFrame.ShowWindow(m_nCmdShow);
pFrame->UpdateWindow();
m_infoFrame.UpdateWindow();
m_infoFrame.DoSwitch(TRUE);
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CDiskInfoApp message handlers
//typedef void (WINAPI * DoAboutProc)();
// App command to run the dialog
void CDiskInfoApp::OnAppAbout()
{
AfxMessageBox("About DiskInfo Pro\n\nCopyright Ministars Software & David Yuheng Zhao\nhttp://www.ministars.com\n\nMore information, please read README.TXT and COPYING.TXT");
}
/////////////////////////////////////////////////////////////////////////////
// CDiskInfoApp message handlers
void CDiskInfoApp::OnSwitchMainWindow()
{
CWnd* pWnd = CWnd::GetDesktopWindow();
CRect rc1;
CRect rc2;
m_pMainWnd->GetWindowRect(&rc1);
m_infoFrame.GetWindowRect(&rc2);
if (m_pMainWnd->IsWindowVisible())
{
DrawAniRects(&rc1, &rc2);
((CMainFrame*)m_pMainWnd)->DoSwitch(FALSE);
m_pMainWnd->ShowWindow(SW_HIDE);
m_pMainWnd->EnableWindow(FALSE);
m_infoFrame.EnableWindow(TRUE);
m_infoFrame.ShowWindow(SW_SHOW);
m_infoFrame.DoSwitch(TRUE);
m_infoFrame.BringWindowToTop();
}else
{
DrawAniRects(&rc2, &rc1);
m_infoFrame.DoSwitch(FALSE);
m_infoFrame.ShowWindow(SW_HIDE);
m_infoFrame.EnableWindow(FALSE);
m_pMainWnd->EnableWindow(TRUE);
m_pMainWnd->ShowWindow(SW_SHOW);
((CMainFrame*)m_pMainWnd)->DoSwitch(TRUE);
m_pMainWnd->BringWindowToTop();
}
}
int CDiskInfoApp::ExitInstance()
{
return CWinApp::ExitInstance();
}
void CDiskInfoApp::OnOptions()
{
COptionSheet propSheet;
propSheet.DoModal();
m_infoFrame.OnOptionChanged();
((CMainFrame*)m_pMainWnd)->OnOptionChanged();
}
BOOL CDiskInfoApp::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == wm_Activate)
{
// Activate main window
// Does not work for in-place activated objects
CWnd* pWnd = AfxGetMainWnd();
if (pWnd && !pWnd->IsWindowVisible())
pWnd = &m_infoFrame;
if (pWnd != NULL)
{
CWnd* pChildWnd = pWnd->GetLastActivePopup();
if (pWnd->IsIconic())
pWnd->ShowWindow(SW_RESTORE);
pChildWnd -> SetForegroundWindow();
}
}
return CWinApp::PreTranslateMessage(pMsg);
}
BOOL CDiskInfoApp::FirstInstance()
{
HANDLE hMutex = CreateMutex (NULL, TRUE, "MinistarsDiskInfoPro");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
::PostMessage(HWND_BROADCAST, wm_Activate, 0,0);
return FALSE;
}else
return TRUE; // First instance. Proceed as normal.
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -