📄 scwfwiz.c
字号:
vi->hwnd=hwnd;
if(vi->bCmdLine)
{
_beginthread(WipeThread, 0, (void*)vi);
}
break;
}
case WM_TIMER:
{
float pos;
vi = (VOLINFO *)GetWindowLong (hwnd, GWL_USERDATA);
if((vi->dwClusterCount!=0)&&
(vi->dwOldWritten!=vi->dwClustersWritten))
{
// char szText[100];
// sprintf(szText,"%d of %d",vi->dwClustersWritten,vi->dwClusterCount);
//
// StatusMessage(vi,szText,FALSE);
pos = ( (float)vi->dwClustersWritten /
(float)vi->dwClusterCount )*100;
WipeProgress(vi,(int)pos);
vi->dwOldWritten=vi->dwClustersWritten;
}
break;
}
case WM_COMMAND:
vi = (VOLINFO *)GetWindowLong (hwnd, GWL_USERDATA);
switch (HIWORD(wParam)) {
case BN_CLICKED:
if (LOWORD (wParam) == IDC_BEGIN)
{
_beginthread(WipeThread, 0, (void*)vi);
}
if (LOWORD (wParam) == IDC_SCHEDULE)
{
HRESULT hRes;
hRes=SchedulePGPwipe(hwnd,vi->context,&(vi->drive[0]),vi->passes);
if(hRes==S_OK)
{
SendMessage(GetParent(hwnd),WM_CLOSE,0,0);
// bReturnCode=TRUE;
// SetWindowLong(hwnd, DWL_MSGRESULT, TRUE);
// EndDialog(GetParent(hwnd),TRUE);
}
}
break;
}
break;
case WM_NOTIFY:
{
LPNMHDR pnmh = (LPNMHDR) lParam;
switch(pnmh->code) {
case PSN_SETACTIVE:
{
char StrRes[500];
PostMessage(GetParent(hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
vi = (VOLINFO *)GetWindowLong (hwnd, GWL_USERDATA);
SetWindowText(GetDlgItem(hwnd,IDC_RESTARTINGTEXT),
"");
WipeProgress(vi,0);
PassProgress(vi,0,vi->passes);
LoadString (g_hinst, IDS_DISKSTAT, StrRes, sizeof(StrRes));
strcat(StrRes, vi->drive);
SetWindowText(GetDlgItem(hwnd, IDC_GROUP), StrRes);
WipeFree(vi,
vi->drive,
NULL,
FALSE);
DisplayDiskStats(vi);
LoadString (g_hinst, IDS_BEGINWIPE, StrRes, sizeof(StrRes));
StatusMessage(vi,StrRes, FALSE);
SetWindowLong(hwnd, DWL_MSGRESULT, 0L);
bReturnCode = TRUE;
break;
case PSN_WIZNEXT:
{
vi = (VOLINFO *)GetWindowLong (hwnd, GWL_USERDATA);
break;
}
case PSN_QUERYCANCEL:
{
NMHDR* nmhdr = (NMHDR*) lParam;
vi = (VOLINFO *)GetWindowLong (hwnd, GWL_USERDATA);
// User wants to quit
if( vi->bWiping )
{
vi->bCancel=TRUE;
bReturnCode=TRUE;
SetWindowLong(hwnd, DWL_MSGRESULT, TRUE);
}
break;
}
}
}
}
}
return bReturnCode;
}
// ______________________________________________
//
// Dialog procedure for handling beginning introductory
// dialog.
static LRESULT WINAPI
sWipeWizardIntroDlgProc (
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
BOOL bReturnCode = FALSE;
VOLINFO *vi = NULL;
switch (uMsg) {
case WM_INITDIALOG:
{
PROPSHEETPAGE *ppspMsgRec = (PROPSHEETPAGE *) lParam;
vi = (VOLINFO *) ppspMsgRec->lParam;
SetWindowLong (hwnd, GWL_USERDATA, (LPARAM)vi);
// center dialog on screen
PGPclCenterWindowOnMonitor (GetParent(hwnd), kPGPclWindowMonitor);
SendDlgItemMessage (hwnd, IDC_HEADING, WM_SETFONT,
(WPARAM)vi->hfontIntro, (LPARAM)FALSE);
break;
}
case WM_ACTIVATE :
InvalidateRect (hwnd, NULL, TRUE);
break;
case WM_PAINT :
vi = (VOLINFO *)GetWindowLong (hwnd, GWL_USERDATA);
if (vi->hpaletteIntro)
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint (hwnd, &ps);
SelectPalette (hDC, vi->hpaletteIntro, FALSE);
RealizePalette (hDC);
EndPaint (hwnd, &ps);
}
break;
case WM_NOTIFY:
{
LPNMHDR pnmh = (LPNMHDR) lParam;
switch(pnmh->code) {
case PSN_SETACTIVE:
vi = (VOLINFO *)GetWindowLong (hwnd, GWL_USERDATA);
PostMessage(GetParent(hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_NEXT);
SendDlgItemMessage(hwnd, IDC_WIZBITMAP, STM_SETIMAGE,
IMAGE_BITMAP, (LPARAM) vi->hbitmapIntro);
SetWindowLong(hwnd, DWL_MSGRESULT, 0L);
bReturnCode = TRUE;
break;
}
break;
}
}
return bReturnCode;
}
// ______________________________________________
//
// Load DIB bitmap and associated palette
static HPALETTE
sCreateDIBPalette (
LPBITMAPINFO lpbmi,
LPINT lpiNumColors)
{
LPBITMAPINFOHEADER lpbi;
LPLOGPALETTE lpPal;
HANDLE hLogPal;
HPALETTE hPal = NULL;
INT i;
lpbi = (LPBITMAPINFOHEADER)lpbmi;
if (lpbi->biBitCount <= 8)
*lpiNumColors = (1 << lpbi->biBitCount);
else
*lpiNumColors = 0; // No palette needed for 24 BPP DIB
if (*lpiNumColors)
{
hLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) +
sizeof (PALETTEENTRY) * (*lpiNumColors));
lpPal = (LPLOGPALETTE) GlobalLock (hLogPal);
lpPal->palVersion = 0x300;
lpPal->palNumEntries = *lpiNumColors;
for (i = 0; i < *lpiNumColors; i++)
{
lpPal->palPalEntry[i].peRed = lpbmi->bmiColors[i].rgbRed;
lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
lpPal->palPalEntry[i].peBlue = lpbmi->bmiColors[i].rgbBlue;
lpPal->palPalEntry[i].peFlags = 0;
}
hPal = CreatePalette (lpPal);
GlobalUnlock (hLogPal);
GlobalFree (hLogPal);
}
return hPal;
}
static HBITMAP
sLoadResourceBitmap (
HINSTANCE hInstance,
LPSTR lpString,
HPALETTE* phpalette)
{
HRSRC hRsrc;
HGLOBAL hGlobal;
HBITMAP hbitmapFinal = NULL;
LPBITMAPINFOHEADER lpbi;
HDC hdc;
INT iNumColors;
if (hRsrc = FindResource (hInstance, lpString, RT_BITMAP))
{
hGlobal = LoadResource (hInstance, hRsrc);
lpbi = (LPBITMAPINFOHEADER)LockResource (hGlobal);
hdc = GetDC(NULL);
*phpalette = sCreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors);
if (*phpalette)
{
SelectPalette (hdc,*phpalette,FALSE);
RealizePalette (hdc);
}
hbitmapFinal = CreateDIBitmap (hdc,
(LPBITMAPINFOHEADER)lpbi,
(LONG)CBM_INIT,
(LPSTR)lpbi + lpbi->biSize + iNumColors * sizeof(RGBQUAD),
(LPBITMAPINFO)lpbi,
DIB_RGB_COLORS );
ReleaseDC (NULL,hdc);
UnlockResource (hGlobal);
FreeResource (hGlobal);
}
return (hbitmapFinal);
}
void StatusMessage(VOLINFO *vi,char *msg, BOOL bold)
{
if(bold)
{
SendMessage(GetDlgItem(vi->hwnd, IDC_STATUS),
WM_SETFONT,
(WPARAM)vi->boldfont,
MAKELPARAM(TRUE, 0));
}
else
{
SendMessage(GetDlgItem(vi->hwnd, IDC_STATUS),
WM_SETFONT,
(WPARAM)vi->defaultfont,
MAKELPARAM(TRUE, 0));
}
SetWindowText(GetDlgItem(vi->hwnd, IDC_STATUS), msg);
}
void WipeProgress(VOLINFO *vi,int pos)
{
if(vi->RestartDelay!=0)
{
vi->RestartDelay++;
if(vi->RestartDelay==16)
{
vi->RestartDelay=0;
SetWindowText(
GetDlgItem(vi->hwnd,IDC_RESTARTINGTEXT),
"");
}
}
SendMessage(GetDlgItem(vi->hwnd, IDC_WIPE_PROGRESS),
PBM_SETPOS ,
(WPARAM)pos,
0);
InvalidateRect(GetDlgItem(vi->hwnd, IDC_WIPE_PROGRESS),NULL,FALSE);
}
void PassProgress(VOLINFO *vi,int pass, int total)
{
char msg[] = "Pass: %d/%d";
char buf[128];
SendMessage(GetDlgItem(vi->hwnd, IDC_PASS_PROGRESS),
PBM_SETRANGE,
0,
MAKELPARAM(0, total));
SendMessage(GetDlgItem(vi->hwnd, IDC_PASS_PROGRESS),
PBM_SETPOS ,
(WPARAM)pass,
0);
pass=pass+1; // now one based instead of zero based
if(pass>total)
pass=total;
wsprintf(buf, msg, pass , total);
SetWindowText(GetDlgItem(vi->hwnd, IDC_STATIC_PASS), buf);
}
BOOL DisplayDiskStats(VOLINFO *vi)
{
char buf[256];
switch(vi->dwFS)
{
case FS_FAT12:
strcpy(buf,"FAT 12");
break;
case FS_FAT16:
strcpy(buf,"FAT 16");
break;
case FS_FAT32:
strcpy(buf,"FAT 32");
break;
case FS_NTFS:
strcpy(buf,"NTFS");
break;
default: // Should never get here
strcpy(buf,"Unknown");
}
SendMessage(GetDlgItem(vi->hwnd,IDC_FSDATA),
WM_SETTEXT,
(WPARAM)0,
(LPARAM)buf);
sprintf(buf,"%d",vi->no_of_clusters);
SendMessage(GetDlgItem(vi->hwnd,IDC_NCDATA),
WM_SETTEXT,
(WPARAM)0,
(LPARAM)buf);
sprintf(buf,"%d",vi->sectors_per_clus);
SendMessage(GetDlgItem(vi->hwnd,IDC_SCDATA),
WM_SETTEXT,
(WPARAM)0,
(LPARAM)buf);
sprintf(buf,"%d",vi->sector_size);
SendMessage(GetDlgItem(vi->hwnd,IDC_BSDATA),
WM_SETTEXT,
(WPARAM)0,
(LPARAM)buf);
sprintf(buf,"%.0f K",vi->fTotalCapacity/1024);
SendMessage(GetDlgItem(vi->hwnd,IDC_TCDATA),
WM_SETTEXT,
(WPARAM)0,
(LPARAM)buf);
return TRUE;
}
// ______________________________________________
//
// Create wizard data structures and call PropertySheet
// to actually create wizard
BOOL
WipeWizard (
HWND hwndParent,PGPContextRef context,
char *CmdLineDrive,int CmdLinePasses,BOOL bAuto)
{
VOLINFO *vi;
PROPSHEETPAGE pspWiz[NUM_WIZ_PAGES];
PROPSHEETHEADER pshWiz;
INT iIndex;
INT iNumBits, iBitmap;
HDC hDC;
PGPPrefRef prefRef;
LOGFONT lf;
PGPError err;
vi=(VOLINFO *)malloc(sizeof(VOLINFO));
memset(vi,0x00,sizeof(VOLINFO));
vi->bCmdLine=bAuto;
if(CmdLineDrive!=NULL)
{
strcpy(vi->drive,CmdLineDrive);
vi->drive[0]=(char)toupper((int)vi->drive[0]);
}
// Get number of passes
err=PGPclPeekClientLibPrefRefs(&prefRef,NULL);
if(IsntPGPError(err))
{
PGPGetPrefNumber (prefRef,
kPGPPrefDiskWipePasses,
(PGPUInt32*)&(vi->passes));
}
if(CmdLinePasses!=0)
{
if((vi->passes>=1)&&(vi->passes<=32))
vi->passes=CmdLinePasses;
}
vi->context=context;
// set some convenient globals
vi->defaultfont = GetStockObject(DEFAULT_GUI_FONT);
GetObject(vi->defaultfont, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
vi->boldfont = CreateFontIndirect(&lf);
// Determine which bitmap will be displayed in the wizard
hDC = GetDC (NULL); // DC for desktop
iNumBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES);
ReleaseDC (NULL, hDC);
if (iNumBits <= 1)
iBitmap = IDB_WIPEWIZ1;
else if (iNumBits <= 4)
iBitmap = IDB_WIPEWIZ4;
else
iBitmap = IDB_WIPEWIZ8;
vi->hbitmapIntro = sLoadResourceBitmap (g_hinst,
MAKEINTRESOURCE (iBitmap), &vi->hpaletteIntro);
vi->hbitmapDone = sLoadResourceBitmap (g_hinst,
MAKEINTRESOURCE (iBitmap), &vi->hpaletteDone);
// load special fonts
vi->hfontIntro = sLoadHeadingFont (FALSE);
vi->hfontInterior = sLoadHeadingFont (TRUE);
// Set the values common to all pages
for (iIndex=0; iIndex<NUM_WIZ_PAGES; iIndex++)
{
pspWiz[iIndex].dwSize = sizeof(PROPSHEETPAGE);
pspWiz[iIndex].dwFlags = PSP_DEFAULT;
pspWiz[iIndex].hInstance = g_hinst;
pspWiz[iIndex].pszTemplate = NULL;
pspWiz[iIndex].hIcon = NULL;
pspWiz[iIndex].pszTitle = NULL;
pspWiz[iIndex].pfnDlgProc = NULL;
pspWiz[iIndex].lParam = (LPARAM) vi;
pspWiz[iIndex].pfnCallback = NULL;
pspWiz[iIndex].pcRefParent = NULL;
}
// Set up the intro page
pspWiz[WIPEWIZ_INTRO].pszTemplate = MAKEINTRESOURCE(IDD_WIPEWIZ_INTRO);
pspWiz[WIPEWIZ_INTRO].pfnDlgProc = sWipeWizardIntroDlgProc;
// Set up the gather drive page
pspWiz[WIPEWIZ_INFO].pszTemplate = MAKEINTRESOURCE(IDD_WIPEWIZ_INFO);
pspWiz[WIPEWIZ_INFO].pfnDlgProc = sWipeWizardInfoDlgProc;
// Set up the status/work page
pspWiz[WIPEWIZ_STATUS].pszTemplate = MAKEINTRESOURCE(IDD_WIPEWIZ_STATUS);
pspWiz[WIPEWIZ_STATUS].pfnDlgProc = sWipeWizardStatusDlgProc;
// Set up the final page
pspWiz[WIPEWIZ_DONE].pszTemplate = MAKEINTRESOURCE(IDD_WIPEWIZ_DONE);
pspWiz[WIPEWIZ_DONE].pfnDlgProc = sWipeWizardDoneDlgProc;
// Create the header
pshWiz.dwSize = sizeof(PROPSHEETHEADER);
pshWiz.dwFlags = PSH_WIZARD | PSH_PROPSHEETPAGE;
pshWiz.hwndParent = hwndParent;
pshWiz.hInstance = g_hinst;
pshWiz.hIcon = NULL;
pshWiz.pszCaption = NULL;
pshWiz.nPages = NUM_WIZ_PAGES;
if(vi->bCmdLine)
pshWiz.nStartPage = WIPEWIZ_STATUS;
else
pshWiz.nStartPage = WIPEWIZ_INTRO;
pshWiz.ppsp = pspWiz;
pshWiz.pfnCallback = NULL;
// Execute the Wizard - doesn't return until Cancel or Save
PropertySheet(&pshWiz);
DeleteObject (vi->hbitmapIntro);
DeleteObject (vi->hbitmapDone);
DeleteObject (vi->hfontIntro);
DeleteObject (vi->hfontInterior);
DeleteObject (vi->defaultfont);
DeleteObject (vi->boldfont);
free(vi);
return kPGPError_NoErr;
}
void PGPscFreeSpaceWipeWizard(HWND hwndParent, void* PGPsc)
{
WipeWizard (hwndParent,PGPsc,NULL,0,FALSE);
}
BOOL PGPscFreeSpaceWipeCmdLine(HWND hwndParent, void* PGPsc,
char *Drive, int Passes, BOOL bAuto)
{
return WipeWizard (hwndParent,PGPsc,Drive,Passes,bAuto);
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -