📄 cpgpdiskapp.cpp
字号:
BOOL
CPGPdiskApp::InitInstance()
{
DualErr derr;
App = this;
// If there is a command line, we are in command-line mode.
mCommandLineMode = (m_lpCmdLine[0] != NULL);
// Quit if we're not running correct Windows version.
CheckWindowsVersion();
// Switch to another non-command-line PGPdisk if one exists.
EnforceUniquePGPdiskGUI();
#if PGPDISK_BETAVERSION
// Set beta timeout (once).
SetPGPdiskBetaTimeout();
// Check if the beta has timed out.
CheckBetaTimeout();
#elif PGPDISK_DEMOVERSION
// Check if the demo has timed out.
CheckDemoTimeout();
#endif // PGPDISK_BETAVERSION
// Resolve APIs unique to a platform.
derr = ExplicitlyLinkAPIsForPlatform();
// If there is a command line, we will not show the main window and we
// will be sure to exit after all commands are processed.
if (derr.IsntError())
{
#ifdef _AFXDLL
// Call when using MFC in shared DLL.
Enable3dControls();
#else
// Call when linking to MFC statically.
Enable3dControlsStatic();
#endif
// Intialize OLE.
if (OleInitialize(NULL) != S_OK)
derr = DualErr(kPGDMinorError_OleInitFailed);
}
// Create a PGPcontext.
if (derr.IsntError())
{
derr = CreateGlobalPGPContext();
}
// Open a handle to the driver.
if (derr.IsntError())
{
derr = OpenPGPdiskDriver();
}
// Prepare PGPdisk registry settings.
if (derr.IsntError())
{
derr = InitRegistryKeys();
}
// Get personalization info from registry.
if (derr.IsntError())
{
derr = GetPersonalizationInfo();
}
// Start and/or update the PGPdiskResident application.
if (derr.IsntError())
{
if (!UpdatePGPdiskResident())
ReportError(kPGDMajorError_CouldntFindResidentApp);
}
if (derr.IsntError())
{
// Create and hide main dialog.
derr = CreateMainDialog();
}
// Allocate our shared memory.
if (derr.IsntError())
{
derr = CreateAppInfoStruct();
}
// Check version numbers of the driver.
if (derr.IsntError())
{
derr = CheckDriverVersion();
}
// Notify the driver of our preferences.
if (derr.IsntError())
{
derr = SetDriverPrefsFromApp();
}
// Get PGPdisk info.
if (derr.IsntError())
{
derr = UpdateAppPGPdiskInfo();
}
// If there is a command line, process it now, else show the main window.
if (derr.IsntError())
{
if (mCommandLineMode)
{
CPGPdiskCmdLine cmdInfo;
cmdInfo.ParseCommandLine();
derr = DualErr(kPGDMinorError_FailSilently); // will quit app
}
else
{
mMainDialog->ShowWindow(SW_SHOWNORMAL);
mMainDialog->SetForegroundWindow();
}
}
if (derr.IsError())
{
ReportError(kPGDMajorError_AppInitFailed, derr);
ExitPGPdiskApp();
}
return TRUE;
}
////////////////////////////////////////////////////////////////////////
// CPGPdiskApp private custom functions and non-default message handlers
////////////////////////////////////////////////////////////////////////
// EnforceUniquePGPdiskGUI ensures there is only one non-command-line
// instance of PGPdisk.
void
CPGPdiskApp::EnforceUniquePGPdiskGUI()
{
if (!mCommandLineMode && FindAndShowNonCommandLinePGPdiskApp())
{
AbortPGPdiskApp();
}
}
// CheckWindowsVersion exits if we are running an incompatible version of
// Windows.
void
CPGPdiskApp::CheckWindowsVersion()
{
if (!IsWin95CompatibleMachine() && !IsWinNT4CompatibleMachine())
{
ReportError(kPGDMajorError_NotCompatibleWindows);
AbortPGPdiskApp();
}
}
#if PGPDISK_BETAVERSION
// CheckBetaTimeout checks if we are running an expired beta and warns or
// exits as appropriate.
void
CPGPdiskApp::CheckBetaTimeout()
{
if (!mCommandLineMode && HasBetaTimedOut())
{
DisplayMessage(kPGPdiskBetaTimeoutWarning);
}
}
#elif PGPDISK_DEMOVERSION
// CheckDemoTimeout checks if we are running an expired demo and warns or
// exits as appropriate.
void
CPGPdiskApp::CheckDemoTimeout()
{
if (!mCommandLineMode && HasDemoTimedOut())
{
CNagBuyDialog nagBuyDialog;
nagBuyDialog.DisplayDialog(kPGPdiskDemoTimeoutWarning);
}
}
#endif // PGPDISK_BETAVERSION
// BringThisPGPdiskAppToFront displays the frontmost window of the PGPdisk
// app specified by the given main dialog handle.
void
CPGPdiskApp::BringThisPGPdiskAppToFront(HWND mainDialogHwnd)
{
HWND frontmostWindow;
pgpAssert(IsntNull(mainDialogHwnd));
frontmostWindow = GetLastActivePopup(mainDialogHwnd);
ShowWindow(frontmostWindow, SW_RESTORE);
SetForegroundWindow(frontmostWindow);
}
// InitRegistryKeys prepares the registry with necessary PGPdisk
// initialization values, and acquires other values from the registry as
// needed.
DualErr
CPGPdiskApp::InitRegistryKeys()
{
DualErr derr;
// Update PGPdiskApp pathnames in the registry.
SetRegistryPaths();
// Now get the application preferences from the registry.
if (derr.IsntError())
{
derr = GetRegistryPrefs();
}
return derr;
}
// CreateMainDialog creates the main dialog and display it.
DualErr
CPGPdiskApp::CreateMainDialog()
{
DualErr derr;
PGPBoolean createdMainDialog = FALSE;
// Allocate the dialog.
try
{
mMainDialog = new CMainDialog;
}
catch (CMemoryException *ex)
{
derr = DualErr(kPGDMinorError_OutOfMemory);
ex->Delete();
}
createdMainDialog = derr.IsntError();
// Create the actual dialog.
if (derr.IsntError())
{
if (!mMainDialog->Create(IDD_MAIN_DLG))
derr = DualErr(kPGDMinorError_DialogDisplayFailed);
}
if (derr.IsntError())
{
m_pMainWnd = mMainDialog;
RegisterPGPdiskMsgBoxParent(mMainDialog);
// Set its title.
mMainDialog->SetWindowText(kPGPdiskMainWndTitle);
}
if (derr.IsError())
{
if (createdMainDialog)
{
delete mMainDialog;
mMainDialog = NULL;
}
}
return derr;
}
// DeleteMainDialog destroys the main dialog.
void
CPGPdiskApp::DeleteMainDialog()
{
if (IsntNull(mMainDialog))
{
delete mMainDialog;
mMainDialog = NULL;
}
}
// CreateAppInfoStruct allocates our shared application info structure.
DualErr
CPGPdiskApp::CreateAppInfoStruct()
{
DualErr derr, memError;
PGPBoolean foundNameForMem = FALSE;
pgpAssertAddrValid(mMainDialog, CMainDialog);
try
{
CString memName;
PGPUInt32 i;
// Find an untaken name for our shared memory.
for (i = 0; i < kMaxPGPdiskApps; i++)
{
memName.Format("%s%d", kSharedMemNamePrefix, i);
memError = mSharedAppInfoMem.CreateAndAttach(memName,
sizeof(AppInstanceInfo));
if (memError.IsntError())
break;
}
if (memError.IsError())
derr = DualErr(kPGDMinorError_TooManyAppsRegistered);
if (derr.IsntError())
{
// Get shared memory pointer.
mPAII = (PAppInstanceInfo) mSharedAppInfoMem.GetMemPointer();
// Initialize the shared memory object.
mPAII->commandLineMode = mCommandLineMode;
mPAII->mainDialogHwnd = mMainDialog->m_hWnd;
ClearSharedMemoryCommandInfo();
}
}
catch (CMemoryException *ex)
{
derr = DualErr(kPGDMinorError_OutOfMemory);
ex->Delete();
}
return derr;
}
// DeleteAppInfoStruct deletes our shared application info structure.
DualErr
CPGPdiskApp::DeleteAppInfoStruct()
{
DualErr derr;
if (IsntNull(mPAII))
{
pgpAssertAddrValid(mPAII, AppInstanceInfo);
derr = mSharedAppInfoMem.Detach();
mPAII = NULL;
}
return derr;
}
// ShowPGPdiskAboutBox displays the PGPdisk about box.
DualErr
CPGPdiskApp::ShowPGPdiskAboutBox()
{
DualErr derr;
PGPclHelpAbout(GetGlobalPGPContext(), App->mMainDialog->GetSafeHwnd(),
NULL, NULL, NULL);
return derr;
}
// ShowPGPdiskHelp displays the PGPdisk help file.
void
CPGPdiskApp::ShowPGPdiskHelp()
{
::WinHelp(mMainDialog->GetSafeHwnd(), m_pszHelpFilePath, HELP_FINDER,
NULL);
}
// ShowPGPdiskPrefs displays the PGPdisk preferences.
DualErr
CPGPdiskApp::ShowPGPdiskPrefs()
{
CPreferencesSheet prefsSheet;
DualErr derr;
derr = prefsSheet.mInitErr;
if (derr.IsntError())
{
derr = prefsSheet.DisplayPreferences();
}
return derr;
}
// ShowSplashScreen displays the splash screen once a day.
void
CPGPdiskApp::ShowSplashScreen()
{
PGPclSplash(GetGlobalPGPContext(), GetDesktopWindow(), kSplashTimeMs);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -