📄 maindialog.cpp
字号:
#include "unfrag.h"
#include "MainDialog.h"
#include "resource.h"
#include "Fraginator.h"
#include "Defragment.h"
#include "ReportDialog.h"
vector<wstring> DrivesList;
LRESULT AnalyzeID;
LRESULT FastID;
LRESULT ExtensiveID;
bool QuitWhenDone;
bool Stopping;
LRESULT PriHighID;
LRESULT PriAboveNormID;
LRESULT PriNormalID;
LRESULT PriBelowNormID;
LRESULT PriIdleID;
void InitDialog (HWND Dlg);
void UpdateDefragInfo (HWND Dlg);
void UpdatePriority (HWND Dlg);
wstring GetDefaultTitle (void);
wstring GetDefragTitle (void);
void SetDisables (HWND Dlg);
INT_PTR CALLBACK MainDialogProc (HWND Dlg, UINT Msg, WPARAM WParam, LPARAM LParam);
static void InitDialog (HWND Dlg)
{
// Make internal list
DWORD DriveMask;
HWND DlgItem;
int d;
// Clear out wisecracks line for now
SetDlgItemText (Dlg, IDC_WISECRACKS, L"\"Defrag, baby!\"");
// Make list of logical drives
DrivesList.resize (0);
DriveMask = GetLogicalDrives ();
for (d = 0; d < 26; d++)
{
if (DriveMask & (1 << d))
{
wstring Name;
Name = (wchar_t)(L'A' + d);
Name += L':';
DrivesList.push_back (Name);
}
}
// Give list to dropdown list
DlgItem = GetDlgItem (Dlg, IDC_DRIVES_LIST);
SendMessage (DlgItem, CB_RESETCONTENT, 0, 0);
for (d = 0; d < DrivesList.size(); d++)
{
SendMessage (DlgItem, CB_ADDSTRING, 0, (LPARAM) DrivesList[d].c_str());
}
// Put in defrag methods
DlgItem = GetDlgItem (Dlg, IDC_METHODS_LIST);
SendMessage (DlgItem, CB_RESETCONTENT, 0, 0);
AnalyzeID = SendMessage (DlgItem, CB_ADDSTRING, 0, (LPARAM) L"Analyze Only");
FastID = SendMessage (DlgItem, CB_ADDSTRING, 0, (LPARAM) L"Fast Defrag");
ExtensiveID = SendMessage (DlgItem, CB_ADDSTRING, 0, (LPARAM) L"Extensive Defrag");
// Set up process priorities
DlgItem = GetDlgItem (Dlg, IDC_PRIORITY_LIST);
SendMessage (Dlg, CB_RESETCONTENT, 0, 0);
PriHighID = SendMessage (DlgItem, CB_ADDSTRING, 0, (LPARAM) L"High");
PriAboveNormID = SendMessage (DlgItem, CB_ADDSTRING, 0, (LPARAM) L"Above Normal");
PriNormalID = SendMessage (DlgItem, CB_ADDSTRING, 0, (LPARAM) L"Normal");
PriBelowNormID = SendMessage (DlgItem, CB_ADDSTRING, 0, (LPARAM) L"Below Normal");
PriIdleID = SendMessage (DlgItem, CB_ADDSTRING, 0, (LPARAM) L"Idle");
UpdatePriority (Dlg);
// Reset texts and progress meters
SendDlgItemMessage (Dlg, IDC_STATUS, WM_SETTEXT, 0, (LPARAM) L"");
SendDlgItemMessage (Dlg, IDC_PERCENT, WM_SETTEXT, 0, (LPARAM) L"");
SendDlgItemMessage (Dlg, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM (0, 10000));
SendDlgItemMessage (Dlg, IDC_PROGRESS, PBM_SETPOS, 0, 0);
return;
}
void UpdateDefragInfo (HWND Dlg)
{
wchar_t PercentText[100];
static double OldPercent = 200.0f;
static wstring OldStatus = L"Non";
wstring NewStatus;
double NewPercent;
if (Defrag == NULL)
return;
NewPercent = Defrag->GetStatusPercent ();
if (NewPercent > 100.0f)
NewPercent = 100.0f;
if (NewPercent < 0.0f)
NewPercent = 0.0f;
if (NewPercent != OldPercent)
{
swprintf (PercentText, L"%6.2f%%", NewPercent);
SendDlgItemMessage (Dlg, IDC_PERCENT, WM_SETTEXT, 0, (LPARAM) PercentText);
SendDlgItemMessage (Dlg, IDC_PROGRESS, PBM_SETPOS,
(WPARAM) (int)(NewPercent * 100.0f), 0);
OldPercent = NewPercent;
}
NewStatus = Defrag->GetStatusString ();
if (NewStatus != OldStatus)
{ // Change & characters to && to avoid underlining
wstring Status;
wstring::iterator it;
Status = NewStatus;
it = Status.begin ();
while (it < Status.end())
{
if (*it == L'&')
{
Status.insert (it, 1, L'&');
it++;
}
it++;
}
SendDlgItemMessage (Dlg, IDC_STATUS, WM_SETTEXT, 0,
(LPARAM) Status.c_str());
OldStatus = NewStatus;
}
return;
}
wstring GetDefaultTitle (void)
{
wstring DefaultText;
DefaultText = wstring(wstring(APPNAME_GUI) + wstring(L" v") + wstring(APPVER_STR) +
wstring(L" (C) 2000 by Rick Brewster"));
return (DefaultText);
}
wstring GetDefragTitle (void)
{
wstring DefragText;
wchar_t Percent[10];
swprintf (Percent, L"%.2f%%", Defrag->GetStatusPercent());
DefragText = GetDefaultTitle ();
if (Defrag != NULL)
{
DefragText = wstring(Percent) + wstring (L" - ") + Defrag->GetVolume().GetRootPath() +
wstring (L" - ") + DefragText;
}
return (DefragText);
}
void SetDisables (HWND Dlg)
{
// If a defrag is in process, set L'Start' button to say L'Stop' and disable
// the Select Drive and Select Action controls
if (Defrag != NULL && !Defrag->IsDoneYet() && !Defrag->HasError())
{
SendMessage (GetDlgItem (Dlg, IDC_STARTSTOP), WM_SETTEXT, 0, (LPARAM) L"Stop");
EnableWindow (GetDlgItem (Dlg, IDC_DRIVES_LIST), FALSE);
EnableWindow (GetDlgItem (Dlg, IDC_METHODS_LIST), FALSE);
}
else
{
SendMessage (GetDlgItem (Dlg, IDC_STARTSTOP), WM_SETTEXT, 0, (LPARAM) L"Start");
EnableWindow (GetDlgItem (Dlg, IDC_STARTSTOP), TRUE);
EnableWindow (GetDlgItem (Dlg, IDC_QUIT), TRUE);
EnableWindow (GetDlgItem (Dlg, IDC_DRIVES_LIST), TRUE);
EnableWindow (GetDlgItem (Dlg, IDC_METHODS_LIST), TRUE);
}
return;
}
void UpdatePriority (HWND Dlg)
{
LRESULT Id;
DWORD Priority;
Id = SendDlgItemMessage (Dlg, IDC_PRIORITY_LIST, CB_GETCURSEL, 0, 0);
if (Id == PriHighID)
Priority = HIGH_PRIORITY_CLASS;
else
if (Id == PriAboveNormID)
Priority = ABOVE_NORMAL_PRIORITY_CLASS;
else
if (Id == PriNormalID)
Priority = NORMAL_PRIORITY_CLASS;
else
if (Id == PriBelowNormID)
Priority = BELOW_NORMAL_PRIORITY_CLASS;
else
if (Id == PriIdleID)
Priority = IDLE_PRIORITY_CLASS;
else
return;
SetPriorityClass (GetCurrentProcess(), Priority);
return;
}
// Save settings (ie, process priority and defrag type options)
bool GetRegKeys (HKEY *RegKeyResult)
{
HKEY RegKey;
LONG Error;
Error = RegCreateKeyEx
(
HKEY_CURRENT_USER,
L"Software\\Fraginator",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&RegKey,
NULL
);
if (Error != ERROR_SUCCESS)
return (false);
*RegKeyResult = RegKey;
return (true);
}
bool DoneRegKey (HKEY RegKey)
{
RegCloseKey (RegKey);
return (true);
}
void SaveSettings (HWND Dlg)
{
LRESULT DefragID;
DWORD DefragVal;
LRESULT PriID;
DWORD PriVal;
HKEY RegKey;
DefragID = SendDlgItemMessage (Dlg, IDC_METHODS_LIST, CB_GETCURSEL, 0, 0);
PriID = SendDlgItemMessage (Dlg, IDC_PRIORITY_LIST, CB_GETCURSEL, 0, 0);
// Action
if (DefragID == AnalyzeID)
DefragVal = (DWORD) DefragAnalyze;
else
if (DefragID == FastID)
DefragVal = (DWORD) DefragFast;
else
if (DefragID == ExtensiveID)
DefragVal = (DWORD) DefragExtensive;
// Process Priority
if (PriID == PriHighID)
PriVal = HIGH_PRIORITY_CLASS;
else
if (PriID == PriAboveNormID)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -