📄 wfwiz.c
字号:
/*____________________________________________________________________________
Copyright (C) 1997 Network Associates Inc. and affiliated companies.
All rights reserved.
$Id: WFwiz.c,v 1.35 1999/03/10 03:04:55 heller Exp $
____________________________________________________________________________*/
#include "precomp.h"
#include "TaskSchl.h"
BOOL CALLBACK IntroDlgProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK InfoDlgProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK StatusDlgProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK FinishDlgProc(HWND,UINT,WPARAM,LPARAM);
void WipeThread(void* pvoid);
BOOL g_bWiping = FALSE;
HWND g_status = NULL;
HWND g_wipe_progress = NULL;
HWND g_pass_progress = NULL;
HWND g_pass_status = NULL;
HFONT g_boldfont, g_defaultfont;
static HPALETTE
CreateDIBPalette (LPBITMAPINFO lpbmi,
LPINT lpiNumColors);
static HBITMAP
LoadResourceBitmap (HINSTANCE hInstance,
LPSTR lpString,
HPALETTE FAR* lppalette);
BOOL FreeSpaceWipeCmdLine(HWND hwnd, void* PGPsc, char *Drive)
{
PROPSHEETPAGE psp[NUM_PAGES];
PROPSHEETHEADER psh;
int index;
wizard_data data;
LOGFONT lf;
PGPError error;
PGPPrefRef prefRef;
PGPMemoryMgrRef memoryMgr;
PGPUInt32 passes = 1;
HDC hdc = NULL;
int bits, bmp;
PGPContextRef context;
context=(PGPContextRef)PGPsc;
memoryMgr = PGPGetContextMemoryMgr(context);
error = PGPclOpenClientPrefs( memoryMgr,
&prefRef );
if(IsntPGPError(error) )
{
PGPGetPrefNumber ( prefRef,
kPGPPrefDiskWipePasses,
(PGPUInt32*)&passes);
PGPclCloseClientPrefs (prefRef, FALSE);
}
// initialize the wizard data
memset(&data, 0x00, sizeof(data));
data.cookie = 0;
data.passes = passes;
data.hinst = g_hinst;
data.context = context;
strcpy(data.drive,Drive);
data.cmdline=TRUE;
// Determine which bitmap will be displayed in the wizard
hdc = GetDC (NULL); // DC for desktop
bits = GetDeviceCaps (hdc, BITSPIXEL) * GetDeviceCaps (hdc, PLANES);
ReleaseDC (NULL, hdc);
if (bits <= 1)
bmp = IDB_WIPEWIZ1;
else if (bits <= 8)
bmp = IDB_WIPEWIZ4;
else
bmp = IDB_WIPEWIZ8;
data.bmp = LoadResourceBitmap(g_hinst, MAKEINTRESOURCE(bmp),
&(data.palette));
// Set the PROPSHEETPAGE values common to all pages
for (index=0; index < NUM_PAGES; index++)
{
psp[index].dwSize = sizeof(PROPSHEETPAGE);
psp[index].dwFlags = PSP_DEFAULT;
psp[index].hInstance = g_hinst;
psp[index].pszTemplate = NULL;
psp[index].hIcon = NULL;
psp[index].pszTitle = NULL;
psp[index].pfnDlgProc = NULL;
psp[index].lParam = (LPARAM) &data;
psp[index].pfnCallback = NULL;
psp[index].pcRefParent = NULL;
}
// Set up the intro page
psp[intro].pszTemplate = MAKEINTRESOURCE(IDD_INTRO);
psp[intro].pfnDlgProc = (DLGPROC) IntroDlgProc;
// Set up the info page
psp[info].pszTemplate = MAKEINTRESOURCE(IDD_INFO);
psp[info].pfnDlgProc = (DLGPROC) InfoDlgProc;
// Set up the status page
psp[status].pszTemplate = MAKEINTRESOURCE(IDD_STATUS);
psp[status].pfnDlgProc = (DLGPROC) StatusDlgProc;
// Set up the finish page
psp[finish].pszTemplate = MAKEINTRESOURCE(IDD_FINISH);
psp[finish].pfnDlgProc = (DLGPROC) FinishDlgProc;
// Fill out the header
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_WIZARD | PSH_PROPSHEETPAGE;
psh.hwndParent = hwnd;
psh.hInstance = g_hinst;
psh.hIcon = NULL;
psh.pszCaption = NULL;
psh.nPages = NUM_PAGES;
psh.nStartPage = status;
psh.ppsp = psp;
psh.pfnCallback = NULL;
// set some convenient globals
g_defaultfont = GetStockObject(DEFAULT_GUI_FONT);
GetObject(g_defaultfont, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
g_boldfont = CreateFontIndirect(&lf);
// Execute the Wizard - doesn't return until Cancel or Finish
PropertySheet(&psh);
DeleteObject(g_boldfont);
return data.result;
}
void FreeSpaceWipeWizard(HWND hwnd, void* PGPsc)
{
PROPSHEETPAGE psp[NUM_PAGES];
PROPSHEETHEADER psh;
int index;
wizard_data data;
LOGFONT lf;
PGPError error;
PGPPrefRef prefRef;
PGPMemoryMgrRef memoryMgr;
PGPUInt32 passes = 1;
HDC hdc = NULL;
int bits, bmp;
PGPContextRef context;
context=(PGPContextRef)PGPsc;
memoryMgr = PGPGetContextMemoryMgr(context);
error = PGPclOpenClientPrefs( memoryMgr,
&prefRef );
if(IsntPGPError(error) )
{
PGPGetPrefNumber ( prefRef,
kPGPPrefDiskWipePasses,
(PGPUInt32*)&passes);
PGPclCloseClientPrefs (prefRef, FALSE);
}
// initialize the wizard data
memset(&data, 0x00, sizeof(data));
data.cookie = 0;
data.passes = passes;
data.hinst = g_hinst;
data.context = context;
// Determine which bitmap will be displayed in the wizard
hdc = GetDC (NULL); // DC for desktop
bits = GetDeviceCaps (hdc, BITSPIXEL) * GetDeviceCaps (hdc, PLANES);
ReleaseDC (NULL, hdc);
if (bits <= 1)
bmp = IDB_WIPEWIZ1;
else if (bits <= 8)
bmp = IDB_WIPEWIZ4;
// else if (bits <= 8) // No pallette cycling -wjb
// bmp = IDB_WIPEWIZ8;
else
bmp = IDB_WIPEWIZ8; // save some space <grin>
//bmp = IDB_WIPEWIZ24;
data.bmp = LoadResourceBitmap(g_hinst, MAKEINTRESOURCE(bmp),
&(data.palette));
// Set the PROPSHEETPAGE values common to all pages
for (index=0; index < NUM_PAGES; index++)
{
psp[index].dwSize = sizeof(PROPSHEETPAGE);
psp[index].dwFlags = PSP_DEFAULT;
psp[index].hInstance = g_hinst;
psp[index].pszTemplate = NULL;
psp[index].hIcon = NULL;
psp[index].pszTitle = NULL;
psp[index].pfnDlgProc = NULL;
psp[index].lParam = (LPARAM) &data;
psp[index].pfnCallback = NULL;
psp[index].pcRefParent = NULL;
}
// Set up the intro page
psp[intro].pszTemplate = MAKEINTRESOURCE(IDD_INTRO);
psp[intro].pfnDlgProc = (DLGPROC) IntroDlgProc;
// Set up the info page
psp[info].pszTemplate = MAKEINTRESOURCE(IDD_INFO);
psp[info].pfnDlgProc = (DLGPROC) InfoDlgProc;
// Set up the status page
psp[status].pszTemplate = MAKEINTRESOURCE(IDD_STATUS);
psp[status].pfnDlgProc = (DLGPROC) StatusDlgProc;
// Set up the finish page
psp[finish].pszTemplate = MAKEINTRESOURCE(IDD_FINISH);
psp[finish].pfnDlgProc = (DLGPROC) FinishDlgProc;
// Fill out the header
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_WIZARD | PSH_PROPSHEETPAGE;
psh.hwndParent = hwnd;
psh.hInstance = g_hinst;
psh.hIcon = NULL;
psh.pszCaption = NULL;
psh.nPages = NUM_PAGES;
psh.nStartPage = intro;
psh.ppsp = psp;
psh.pfnCallback = NULL;
// set some convenient globals
g_defaultfont = GetStockObject(DEFAULT_GUI_FONT);
GetObject(g_defaultfont, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
g_boldfont = CreateFontIndirect(&lf);
// Execute the Wizard - doesn't return until Cancel or Finish
PropertySheet(&psh);
DeleteObject(g_boldfont);
}
BOOL CALLBACK IntroDlgProc( HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
BOOL bReturnValue = FALSE;
static wizard_data* data = NULL;
switch(msg)
{
case WM_INITDIALOG:
{
PROPSHEETPAGE* psp = (PROPSHEETPAGE*) lParam;
HWND welcome = GetDlgItem(hwnd, IDC_WELCOME);
HWND hwndParent = GetParent(hwnd);
int x,y;
RECT rect;
data = (wizard_data*) psp->lParam;
SendMessage(welcome,
WM_SETFONT,
(WPARAM)g_boldfont,
MAKELPARAM(TRUE, 0));
// center the wizard on the screen
GetClientRect(hwndParent, &rect);
x = (GetSystemMetrics (SM_CXFULLSCREEN) - rect.right) / 2;
y = (GetSystemMetrics (SM_CYFULLSCREEN) - rect.bottom) / 2;
SetWindowPos ( hwndParent,
HWND_TOP,
x,
y,
0,
0,
SWP_NOSIZE);
bReturnValue = TRUE;
break;
}
case WM_DESTROY:
{
break;
}
case WM_PAINT:
{
if (data->palette)
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint (hwnd, &ps);
SelectPalette (hDC, data->palette, FALSE);
RealizePalette (hDC);
EndPaint (hwnd, &ps);
bReturnValue = TRUE;
}
break;
}
case WM_NOTIFY:
{
LPNMHDR pnmh;
pnmh = (LPNMHDR) lParam;
switch(pnmh->code)
{
case PSN_SETACTIVE:
{
// Initialize window
PostMessage(GetParent(hwnd),
PSM_SETWIZBUTTONS,
0,
PSWIZB_NEXT);
SendDlgItemMessage( hwnd,
IDC_WIZBITMAP,
STM_SETIMAGE,
IMAGE_BITMAP,
(LPARAM) data->bmp);
bReturnValue = TRUE;
break;
}
}
break;
}
}
return bReturnValue;
}
BOOL CALLBACK InfoDlgProc( HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
BOOL bReturnValue = FALSE;
static wizard_data* data = NULL;
static HWND drivelist = NULL;
static HWND numpasses = NULL;
switch(msg)
{
case WM_INITDIALOG:
{
PROPSHEETPAGE* psp = (PROPSHEETPAGE*) lParam;
char buf[512] = {0x00};
int len;
char *drive;
HWND spin = GetDlgItem(hwnd, IDC_SPIN1);
SendMessage(spin,
UDM_SETRANGE,
0,
MAKELPARAM(32, 1));
drivelist = GetDlgItem(hwnd, IDC_DRIVECOMBO);
numpasses = GetDlgItem(hwnd, IDC_NUMPASSES);
data = (wizard_data*) psp->lParam;
SetWindowLong(hwnd, GWL_USERDATA, (LPARAM) data);
len = GetLogicalDriveStrings(sizeof(buf), buf);
drive = buf;
while(*drive)
{
*drive=(char)toupper((int)*drive);
SendMessage(drivelist,
CB_ADDSTRING,
0,
(LPARAM)drive);
drive += strlen(drive) + 1;
}
SendMessage(drivelist,
CB_SETCURSEL,
0,
0);
SendMessage(numpasses,
EM_SETLIMITTEXT,
2,
0);
wsprintf(buf, "%d", data->passes);
SetWindowText(numpasses, buf);
bReturnValue = TRUE;
break;
}
case WM_COMMAND:
{
switch LOWORD(wParam)
{
case IDC_STATIC_1:
case IDC_STATIC_2:
case IDC_STATIC_3:
case IDC_STATIC_4:
{
if( HIWORD(wParam) == BN_CLICKED )
{
short alt = GetKeyState( VK_MENU ) & 0x8000;
short shift = GetKeyState( VK_SHIFT ) & 0x8000;
short ctrl = GetKeyState( VK_CONTROL ) & 0x8000;
if(alt && shift && ctrl)
{
SetWindowText(GetDlgItem(hwnd, IDC_STATIC_1), "Hugh Heffner:");
SetWindowText(GetDlgItem(hwnd, IDC_STATIC_2), "Go! Computing:");
SetWindowText(GetDlgItem(hwnd, IDC_STATIC_3), "Theodore Kaczynski:");
SetWindowText(GetDlgItem(hwnd, IDC_STATIC_4), "Benedict Arnold:");
}
}
break;
}
}
break;
}
case WM_PAINT:
{
if (data->palette)
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint (hwnd, &ps);
SelectPalette (hDC, data->palette, FALSE);
RealizePalette (hDC);
EndPaint (hwnd, &ps);
bReturnValue = TRUE;
}
break;
}
case WM_NOTIFY:
{
LPNMHDR pnmh;
pnmh = (LPNMHDR) lParam;
switch(pnmh->code)
{
case PSN_SETACTIVE:
{
// Initialize window
PostMessage(GetParent(hwnd),
PSM_SETWIZBUTTONS,
0,
PSWIZB_NEXT | PSWIZB_BACK);
SendDlgItemMessage( hwnd,
IDC_WIZBITMAP,
STM_SETIMAGE,
IMAGE_BITMAP,
(LPARAM) data->bmp);
bReturnValue = TRUE;
break;
}
case PSN_KILLACTIVE:
{
// Save user data for this page
char buf[512] = {0x00};
int passes;
GetWindowText(drivelist, buf, sizeof(buf));
strcpy(data->drive, buf);
GetWindowText(numpasses, buf, sizeof(buf));
passes = atoi(buf);
data->passes = passes;
break;
}
case PSN_WIZNEXT:
{
// Save user data for this page
char buf[512] = {0x00};
int passes;
GetWindowText(numpasses, buf, sizeof(buf));
passes = atoi(buf);
data->passes = passes;
if((passes<1)||(passes>32))
{
char Caption[100];
char Message[500];
LoadString (g_hinst, IDS_PGPERROR, Caption, sizeof(Caption));
LoadString (g_hinst, IDS_PASSESOUTOFRANGE, Message, sizeof(Message));
MessageBox(hwnd,Message,Caption,
MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
if(passes<1)
SetWindowText(numpasses, "1");
if(passes>32)
SetWindowText(numpasses, "32");
SetWindowLong(hwnd,DWL_MSGRESULT,(LPARAM)-1); // Don't go on...
return TRUE;
}
break;
}
case PSN_WIZFINISH:
{
// Save user data for all pages
break;
}
case PSN_HELP:
{
// Display help
break;
}
case PSN_QUERYCANCEL:
{
// User wants to quit
break;
}
}
break;
}
}
return bReturnValue;
}
BOOL CALLBACK StatusDlgProc(HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
BOOL bReturnValue = FALSE;
static wizard_data* data = NULL;
static HWND fsdata = NULL;
static HWND ncdata = NULL;
static HWND scdata = NULL;
static HWND bsdata = NULL;
static HWND tcdata = NULL;
static HWND group = NULL;
switch(msg)
{
case WM_INITDIALOG:
{
PROPSHEETPAGE* psp = (PROPSHEETPAGE*) lParam;
char buf[512] = {0x00};
data = (wizard_data*) psp->lParam;
fsdata = GetDlgItem(hwnd, IDC_FSDATA);
ncdata = GetDlgItem(hwnd, IDC_NCDATA);
scdata = GetDlgItem(hwnd, IDC_SCDATA);
bsdata = GetDlgItem(hwnd, IDC_BSDATA);
tcdata = GetDlgItem(hwnd, IDC_TCDATA);
group = GetDlgItem(hwnd, IDC_GROUP);
g_status = GetDlgItem(hwnd, IDC_STATUS);
g_wipe_progress = GetDlgItem(hwnd, IDC_WIPE_PROGRESS);
g_pass_progress = GetDlgItem(hwnd, IDC_PASS_PROGRESS);
g_pass_status = GetDlgItem(hwnd, IDC_STATIC_PASS);
SetWindowLong(hwnd, GWL_USERDATA, (LPARAM) data);
if(data->cmdline)
{
data->hwnd = hwnd;
_beginthread(WipeThread, 0, (void*)data);
}
bReturnValue = TRUE;
break;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BEGIN:
{
data->hwnd = hwnd;
_beginthread(WipeThread, 0, (void*)data);
bReturnValue = TRUE;
break;
}
case IDC_SCHEDULE:
{
HRESULT hRes;
hRes=SchedulePGPwipe(hwnd,data->context,&(data->drive[0]));
if(hRes==S_OK)
{
EndDialog(GetParent(hwnd),TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -