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

📄 cdiskwizvolumeinfopage.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if (scale == kLCS_InvalidScale)
		scale = mSizeScale;

	// Set size to legal value.
	if (kbSize < mLocalMinKbSize)
	{
		kbSize = mLocalMinKbSize;
	}
	else if (kbSize > mLocalMaxKbSize)
	{
		kbSize = mLocalMaxKbSize;
	}

	// Set scale to legal value.
	if (mLocalMaxKbSize < kSizeIsCloseRatio*kKbPerMeg)
	{
		scale = kLCS_KbScale;
	}
	else if (mLocalMaxKbSize < kSizeIsCloseRatio*kKbPerGig)
	{
		if (scale == kLCS_GbScale)
			scale = kLCS_MbScale;
	}

	// What scale do we use?
	switch (scale)
	{
	case kLCS_KbScale:

		mSizeValue = kbSize;
		UpdateData(FALSE);
		ConvertControlsToKb();
		break;

	case kLCS_MbScale:

		mSizeValue = kbSize/kKbPerMeg;
		UpdateData(FALSE);
		ConvertControlsToMb();
		break;

	case kLCS_GbScale:

		mSizeValue = kbSize/kKbPerGig;
		UpdateData(FALSE);
		ConvertControlsToGb();
		break;

	default:
		pgpAssert(FALSE);
		break;
	}
}

// GetPGPdiskSizeFromRegistry initializes the size from the value we
// previously stored in the registry.

void 
CDiskWizVolumeInfoPage::GetPGPdiskSizeFromRegistry()
{
	PGPdiskCreateScale	createScale;
	PGPdiskWin32Prefs	prefs;
	PGPUInt32			kbSize;

	if (GetPGPdiskWin32Prefs(prefs).IsntError())
	{
		kbSize = prefs.lastCreateSize;
		createScale = prefs.lastCreateScale;
		
		SetPGPdiskSize(kbSize, createScale);
	}
}

// SetPGPdiskSizeInRegistry stores the current PGPdisk size in the registry.

DualErr 
CDiskWizVolumeInfoPage::SetPGPdiskSizeInRegistry()
{
	DualErr				derr;
	PGPdiskWin32Prefs	prefs;

	derr = GetPGPdiskWin32Prefs(prefs);

	if (derr.IsntError())
	{
		prefs.lastCreateSize = GetSizeValueInKb();
		prefs.lastCreateScale = mSizeScale;

		derr = SetPGPdiskWin32Prefs(prefs);
	}

	return derr;
}

// The CDiskWizVolumeInfoPage data exchange function.

void 
CDiskWizVolumeInfoPage::DoDataExchange(CDataExchange *pDX)
{
	try
	{
		CString		text;
		PGPBoolean	skipDDX	= FALSE;

		CPropertyPage::DoDataExchange(pDX);

		// Our goal is to coax MFC into accepting NULL fields for our size
		// box.

		if (mSizeEditBox.GetSafeHwnd())
			mSizeEditBox.GetWindowText(text);

		// Don't overwrite a null field with a 0.
		if (!pDX->m_bSaveAndValidate && text.IsEmpty() && (mSizeValue == 0))
		{
			skipDDX = TRUE;
		}

		// Note the way the second 'if' statement ends within the
		// AFX_DATA_MAP. This is done so our variable will still appear in
		// the ClassWizard, but allows us to skip the DDX_Text when we want
		// to.

		if (pDX->m_bSaveAndValidate && text.IsEmpty())
		{
			skipDDX = TRUE;
			mSizeValue = 0;
		}

		if (!skipDDX)		
		//{{AFX_DATA_MAP(CDiskWizVolumeInfoPage)
			DDX_Text(pDX, IDC_SIZE_EDIT, mSizeValue);
		DDX_Control(pDX, IDC_DRIVE_COMBO, mDriveCombo);
		DDX_Control(pDX, IDC_SIDEBAR, mSidebarGraphic);
		DDX_Control(pDX, IDC_SIZE_SPIN, mSizeSpin);
		DDX_Control(pDX, IDC_SIZE_EDIT, mSizeEditBox);
		DDX_Text(pDX, IDC_FREESIZE_TEXT, mFreeSizeText);
		//}}AFX_DATA_MAP
	}
	catch (CMemoryException *ex)
	{
		ex->Delete();
	}
}

// OnKbCheck is called when the kB button is clicked.

void 
CDiskWizVolumeInfoPage::OnKbCheck() 
{
	ConvertControlsToKb();	
}

// OnMbCheck is called when the MB button is clicked.

void 
CDiskWizVolumeInfoPage::OnMbCheck() 
{
	ConvertControlsToMb();	
}

// OnMbCheck is called when the GB button is clicked.

void 
CDiskWizVolumeInfoPage::OnGbCheck() 
{
	ConvertControlsToGb();	
}


////////////////////////////////////////////////////////////
// CDiskWizVolumeInfoPage protected default message handlers
////////////////////////////////////////////////////////////

// OnHelpInfo handles context-sensitive help.

BOOL 
CDiskWizVolumeInfoPage::OnHelpInfo(HELPINFO *pHelpInfo)
{
	if ((pHelpInfo->iContextType == HELPINFO_WINDOW) &&
		(pHelpInfo->iCtrlId != ((PGPUInt16) IDC_STATIC)))
	{
		::WinHelp((HWND) pHelpInfo->hItemHandle, App->m_pszHelpFilePath, 
			HELP_WM_HELP, (PGPUInt32) HelpIds);
	}

	return TRUE;
}

// OnInitDialog is overwritten to perform property page initialization.

BOOL 
CDiskWizVolumeInfoPage::OnInitDialog() 
{
	DualErr		dummyErr;
	File		existingFile;
	PGPUInt64	bytesFile, bytesFree;

	CPropertyPage::OnInitDialog();

	// This must be called first to make MFC happy.
	UpdateData(FALSE);

	// Classwizard won't subclasss our radio buttons (sniff).
	mKbButton.SubclassWindow(GetDlgItem(IDC_KB_CHECK)->GetSafeHwnd());
	mMbButton.SubclassWindow(GetDlgItem(IDC_MB_CHECK)->GetSafeHwnd());
	mGbButton.SubclassWindow(GetDlgItem(IDC_GB_CHECK)->GetSafeHwnd());

	// Any drive letters free?
	if (!App->AreAnyDriveLettersFree())
	{
		mParentDiskWiz->mDerr = 
			DualErr(kPGDMinorError_NoDriveLettersFree);
		mParentDiskWiz->PressButton(PSBTN_CANCEL);	// NOT EndDialog (bug)

		return FALSE;
	}

	// Initialize the combo box.
	mDriveCombo.InitDriveLetters();

	// How much space do we have available?
	dummyErr = App->HowMuchFreeSpace(mParentDiskWiz->mPath, &bytesFree);

	// Don't fail if the disk free call fails, but make note of it.
	if (dummyErr.IsntError())
	{
		mAreWeFailingDiskFree = FALSE;
		mKbFree = (PGPUInt32) (bytesFree / kBytesPerKb) - 10;
	}
	else
	{
		mAreWeFailingDiskFree = TRUE;
		mKbFree = App->mPlatformMaxKbSize*2;	// fake max amount of space
	}

	// If the pathname contains the name of an existing file, the user wants
	// to replace it, so add its size to the amount of free space.

	dummyErr = existingFile.Open(mParentDiskWiz->mPath, 
		kOF_MustExist | kOF_ReadOnly);

	if (dummyErr.IsntError())
	{
		existingFile.GetLength(&bytesFile);
	}

	if (dummyErr.IsntError())
	{
		mKbFree += (PGPUInt32) (bytesFile/kBytesPerKb);
	}

	if (existingFile.Opened())
		existingFile.Close();

	// Calculate max and min PGPdisk sizes we can create.
	mLocalMaxKbSize	= min(mKbFree, App->mPlatformMaxKbSize);
	mLocalMinKbSize	= min(mKbFree, App->mPlatformMinKbSize);

	// If max size is less than one meg, disable the Mb button.
	if (mLocalMaxKbSize < kSizeIsCloseRatio*kKbPerMeg)
		mMbButton.EnableWindow(FALSE);

	// If max size is less than one gig, disable the Gb button.
	if (mLocalMaxKbSize < kSizeIsCloseRatio*kKbPerGig)
		mGbButton.EnableWindow(FALSE);

	pgpAssert(mLocalMaxKbSize >= mLocalMinKbSize);

	// Set PGPdisk size to what we remember it as in the registry.
	GetPGPdiskSizeFromRegistry();

	try
	{
		CString freeSpaceStr, maxPGPdiskStr;

		FormatSizeString(mKbFree, freeSpaceStr.GetBuffer(kMaxStringSize), 
			kMaxStringSize);

		freeSpaceStr.ReleaseBuffer();

		FormatSizeString(mLocalMaxKbSize, 
			maxPGPdiskStr.GetBuffer(kMaxStringSize), kMaxStringSize);

		maxPGPdiskStr.ReleaseBuffer();
 
		// Update the contents of the free size message shown to the user.
		if (mAreWeFailingDiskFree)
		{
			mFreeSizeText.Format(GetCommonString(kPGPdiskFreeSize3MsgString), 
				maxPGPdiskStr);
		}
		else if (mLocalMaxKbSize == App->mPlatformMaxKbSize)
		{
			mFreeSizeText.Format(GetCommonString(kPGPdiskFreeSize2MsgString), 
				freeSpaceStr, maxPGPdiskStr);
		}
		else
		{
			mFreeSizeText.Format(GetCommonString(kPGPdiskFreeSize1MsgString), 
				freeSpaceStr);
		}
	}
	catch (CMemoryException *ex)
	{
		ex->Delete();
	}

	UpdateData(FALSE);

	return TRUE;
}

// We override OnPaint to draw the sidebar graphic at the correct depth.

void 
CDiskWizVolumeInfoPage::OnPaint() 
{
	CDC			memDC;
	CPaintDC	DC(this);
	HBITMAP		oldBitmap;
	RECT		sidebarRect;

	DC.SelectPalette(&mParentDiskWiz->mSidebarPalette, FALSE);
	DC.RealizePalette();

	memDC.CreateCompatibleDC(&DC);
	memDC.SelectPalette(&mParentDiskWiz->mSidebarPalette, FALSE);
	memDC.RealizePalette();

	mSidebarGraphic.GetWindowRect(&sidebarRect);
	ScreenToClient(&sidebarRect);
	
	// MFC bug - CDC::SelectObject returns incorrect pointers/handles so don't
	// fool with it.

	oldBitmap = (HBITMAP) SelectObject(memDC, mParentDiskWiz->mSidebarBitmap);

	DC.BitBlt(sidebarRect.left, sidebarRect.top, sidebarRect.right, 
		sidebarRect.bottom, &memDC, 0, 0, SRCCOPY);

	memDC.SelectObject(oldBitmap);
	memDC.DeleteDC();
}

⌨️ 快捷键说明

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