📄 cmaindialog.cpp
字号:
for (PGPUInt32 i=0; i < numDropped; i++)
{
AppCommandInfo ACI;
CString path;
DualErr derr;
try
{
DragQueryFile(hDrop, i, path.GetBuffer(kMaxStringSize),
kMaxStringSize);
path.ReleaseBuffer();
ACI.op = kAppOp_Mount;
ACI.flags = NULL;
ACI.drive = kInvalidDrive;
strcpy(ACI.path, path);
App->DispatchAppCommandInfo(&ACI);
}
catch (CMemoryException *ex)
{
ex->Delete();
}
}
}
// OnHelpInfo handles context-sensitive help.
BOOL
CMainDialog::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 called to perform dialog initialization for CMainDialog.
BOOL
CMainDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// Show the main menu.
mInitErr = ShowMainMenu();
if (mInitErr.IsntError())
{
// Recall where the user last put this window.
RecallWindowPos(this);
// Load our accelerator table.
mAccelTable = LoadAccelerators(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDR_MAINDLG_ACCEL));
// Set the icon for this dialog.
SetIcon(mHIcon, TRUE); // Set big icon
SetIcon(mHIcon, FALSE); // Set small icon
// Load the big icons for the four main buttons.
mMountBigIcon = (HICON) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_MOUNT), IMAGE_ICON, kSideLengthBigIcon,
kSideLengthBigIcon, NULL);
mNewBigIcon = (HICON) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_NEW), IMAGE_ICON, kSideLengthBigIcon,
kSideLengthBigIcon, NULL);
mPrefsBigIcon = (HICON) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_PREFS), IMAGE_ICON, kSideLengthBigIcon,
kSideLengthBigIcon, NULL);
mUnmountBigIcon = (HICON) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_UNMOUNT), IMAGE_ICON, kSideLengthBigIcon,
kSideLengthBigIcon, NULL);
// Load the small icons for the four main buttons.
mMountSmallIcon = (HICON) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_MOUNT), IMAGE_ICON, kSideLengthSmallIcon,
kSideLengthSmallIcon, NULL);
mNewSmallIcon = (HICON) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_NEW), IMAGE_ICON, kSideLengthSmallIcon,
kSideLengthSmallIcon, NULL);
mPrefsSmallIcon = (HICON) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_PREFS), IMAGE_ICON, kSideLengthSmallIcon,
kSideLengthSmallIcon, NULL);
mUnmountSmallIcon = (HICON) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_UNMOUNT), IMAGE_ICON, kSideLengthSmallIcon,
kSideLengthSmallIcon, NULL);
if (!mMountBigIcon || !mNewBigIcon || !mPrefsBigIcon ||
!mUnmountBigIcon || !mMountSmallIcon || !mNewSmallIcon ||
!mPrefsSmallIcon || !mUnmountSmallIcon)
{
mInitErr = kPGDMinorError_DialogDisplayFailed;
}
}
if (mInitErr.IsntError())
{
CMenu *pSysMenu;
PGPdiskWin32Prefs prefs;
if (GetPGPdiskWin32Prefs(prefs).IsntError())
{
if (prefs.wasDialogSmall)
ConvertMainDialogToSmall();
else
ConvertMainDialogToLarge();
}
// Alter the system menu.
pSysMenu = GetSystemMenu(FALSE);
pgpAssertAddrValid(pSysMenu, CMenu);
pSysMenu->DeleteMenu(SC_MAXIMIZE, MF_BYCOMMAND);
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_STAYONTOP, "Stay On &Top");
DrawMenuBar();
// Accept dragged files.
DragAcceptFiles();
// Recall the window on top preference.
RecallMainWndOnTop();
// Focus on the new PGPdisk button.
mNewButton.SetFocus();
}
mArePastInitDialog = TRUE;
return FALSE;
}
// OnInitMenu is called when the File menu is displayed.
void
CMainDialog::OnInitMenu(CMenu *pMenu)
{
PGPBoolean haveWeTimedOut = FALSE;
CDialog::OnInitMenu(pMenu);
// If the shift key is help down, show "Remove Alternate Passphrases" and
// "Convert Old PGPdisks".
if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
{
pMenu->ModifyMenu(IDM_REMOVEPASS, MF_BYCOMMAND | MF_STRING,
IDM_REMOVEALL, "Remove Alternate Passphrases...");
}
else
{
pMenu->ModifyMenu(IDM_REMOVEALL, MF_BYCOMMAND | MF_STRING,
IDM_REMOVEPASS, "Remove Passphrase...");
}
// Disable certain menu commands if we've timed out.
#if PGPDISK_BETAVERSION
haveWeTimedOut = App->HasBetaTimedOut();
#elif PGPDISK_DEMOVERSION
haveWeTimedOut = App->HasDemoTimedOut();
#endif // PGPDISK_BETAVERSION
if (haveWeTimedOut)
{
pMenu->EnableMenuItem(IDM_NEWPGPDISK, MF_GRAYED);
pMenu->EnableMenuItem(IDM_ADDPASS, MF_GRAYED);
pMenu->EnableMenuItem(IDM_CHANGEPASS, MF_GRAYED);
pMenu->EnableMenuItem(IDM_REMOVEPASS, MF_GRAYED);
pMenu->EnableMenuItem(IDM_REMOVEALL, MF_GRAYED);
}
}
// OnPaint is called when part of the dialog must be repainted.
void
CMainDialog::OnPaint()
{
CRect rect;
if (IsIconic()) // MFC iconic stuff
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1)/2;
int y = (rect.Height() - cyIcon + 1)/2;
// Draw the icon
dc.DrawIcon(x, y, mHIcon);
}
else
{
CDialog::OnPaint();
}
}
// OnSize is called when the dialog has been resized. We alter the buttons and
// the menu as needed.
void
CMainDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (mArePastInitDialog)
{
if (mAreWeInLargeMode)
ConvertMainDialogToLarge();
else
ConvertMainDialogToSmall();
}
}
// OnSizing is called when the user is resizing the dialog.
void
CMainDialog::OnSizing(UINT fwSide, LPRECT pRect)
{
if (mArePastInitDialog)
{
PGPInt32 edgeX = GetSystemMetrics(SM_CXFIXEDFRAME);
PGPInt32 edgeY = GetSystemMetrics(SM_CYFIXEDFRAME);
PGPInt32 captionY = GetSystemMetrics(SM_CYCAPTION);
PGPInt32 menuY = GetSystemMetrics(SM_CYMENU);
PGPInt32 smallSizeX, smallSizeY, largeSizeX, largeSizeY;
largeSizeX = kWidthLargeMainDialog + edgeX * 2;
largeSizeY = kHeightLargeMainDialog + edgeY * 2 + captionY + menuY;
smallSizeX = kWidthSmallMainDialog + edgeX * 2;
smallSizeY = kHeightSmallMainDialog + edgeY * 2 + captionY;
// There are only two allowable positions for the drag rectangle.
// Enforce this.
switch (fwSide)
{
case WMSZ_BOTTOM:
if ((pRect->bottom - pRect->top) < largeSizeY - 5)
{
pRect->bottom = pRect->top + smallSizeY;
pRect->right = pRect->left + smallSizeX;
mAreWeInLargeMode = FALSE;
}
if ((pRect->bottom - pRect->top) > smallSizeY + 5)
{
pRect->bottom = pRect->top + largeSizeY;
pRect->right = pRect->left + largeSizeX;
mAreWeInLargeMode = TRUE;
}
break;
case WMSZ_BOTTOMLEFT:
if ((pRect->bottom - pRect->top) < largeSizeY - 5)
{
pRect->bottom = pRect->top + smallSizeY;
pRect->left = pRect->right - smallSizeX;
mAreWeInLargeMode = FALSE;
}
if ((pRect->bottom - pRect->top) > smallSizeY + 5)
{
pRect->bottom = pRect->top + largeSizeY;
pRect->left = pRect->right - largeSizeX;
mAreWeInLargeMode = TRUE;
}
if ((pRect->right - pRect->left) < largeSizeX - 5)
{
pRect->left = pRect->right - smallSizeX;
pRect->bottom = pRect->top + smallSizeY;
mAreWeInLargeMode = FALSE;
}
if ((pRect->right - pRect->left) > smallSizeX + 5)
{
pRect->left = pRect->right - largeSizeX;
pRect->bottom = pRect->top + largeSizeY;
mAreWeInLargeMode = TRUE;
}
break;
case WMSZ_BOTTOMRIGHT:
if ((pRect->bottom - pRect->top) < largeSizeY - 5)
{
pRect->bottom = pRect->top + smallSizeY;
pRect->right = pRect->left + smallSizeX;
mAreWeInLargeMode = FALSE;
}
if ((pRect->bottom - pRect->top) > smallSizeY + 5)
{
pRect->bottom = pRect->top + largeSizeY;
pRect->right = pRect->left + largeSizeX;
mAreWeInLargeMode = TRUE;
}
if ((pRect->right - pRect->left) < largeSizeX - 5)
{
pRect->right = pRect->left + smallSizeX;
pRect->bottom = pRect->top + smallSizeY;
mAreWeInLargeMode = FALSE;
}
if ((pRect->right - pRect->left) > smallSizeX + 5)
{
pRect->right = pRect->left + largeSizeX;
pRect->bottom = pRect->top + largeSizeY;
mAreWeInLargeMode = TRUE;
}
break;
case WMSZ_LEFT:
if ((pRect->right - pRect->left) < largeSizeX - 5)
{
pRect->left = pRect->right - smallSizeX;
pRect->bottom = pRect->top + smallSizeY;
mAreWeInLargeMode = FALSE;
}
if ((pRect->right - pRect->left) > smallSizeX + 5)
{
pRect->left = pRect->right - largeSizeX;
pRect->bottom = pRect->top + largeSizeY;
mAreWeInLargeMode = TRUE;
}
break;
case WMSZ_RIGHT:
if ((pRect->right - pRect->left) < largeSizeX - 5)
{
pRect->right = pRect->left + smallSizeX;
pRect->bottom = pRect->top + smallSizeY;
mAreWeInLargeMode = FALSE;
}
if ((pRect->right - pRect->left) > smallSizeX + 5)
{
pRect->right = pRect->left + largeSizeX;
pRect->bottom = pRect->top + largeSizeY;
mAreWeInLargeMode = TRUE;
}
break;
case WMSZ_TOP:
if ((pRect->bottom - pRect->top) < largeSizeY - 5)
{
pRect->top = pRect->bottom - smallSizeY;
pRect->right = pRect->left + smallSizeX;
mAreWeInLargeMode = FALSE;
}
if ((pRect->bottom - pRect->top) > smallSizeY + 5)
{
pRect->top = pRect->bottom - largeSizeY;
pRect->right = pRect->left + largeSizeX;
mAreWeInLargeMode = TRUE;
}
break;
case WMSZ_TOPLEFT:
if ((pRect->bottom - pRect->top) < largeSizeY - 5)
{
pRect->top = pRect->bottom - smallSizeY;
pRect->left = pRect->right - smallSizeX;
mAreWeInLargeMode = FALSE;
}
if ((pRect->bottom - pRect->top) > smallSizeY + 5)
{
pRect->top = pRect->bottom - largeSizeY;
pRect->left = pRect->right - largeSizeX;
mAreWeInLargeMode = TRUE;
}
if ((pRect->right - pRect->left) < largeSizeX - 5)
{
pRect->left = pRect->right - smallSizeX;
pRect->bottom = pRect->top + smallSizeY;
mAreWeInLargeMode = FALSE;
}
if ((pRect->right - pRect->left) > smallSizeX + 5)
{
pRect->left = pRect->right - largeSizeX;
pRect->bottom = pRect->top + largeSizeY;
mAreWeInLargeMode = TRUE;
}
break;
case WMSZ_TOPRIGHT:
if ((pRect->bottom - pRect->top) < largeSizeY - 5)
{
pRect->top = pRect->bottom - smallSizeY;
pRect->right = pRect->left + smallSizeX;
mAreWeInLargeMode = FALSE;
}
if ((pRect->bottom - pRect->top) > smallSizeY + 5)
{
pRect->top = pRect->bottom - largeSizeY;
pRect->right = pRect->left + largeSizeX;
mAreWeInLargeMode = TRUE;
}
if ((pRect->right - pRect->left) < largeSizeX - 5)
{
pRect->right = pRect->left + smallSizeX;
pRect->bottom = pRect->top + smallSizeY;
mAreWeInLargeMode = FALSE;
}
if ((pRect->right - pRect->left) > smallSizeX + 5)
{
pRect->right = pRect->left + largeSizeX;
pRect->bottom = pRect->top + largeSizeY;
mAreWeInLargeMode = TRUE;
}
break;
default:
pgpAssert(FALSE);
break;
}
}
CDialog::OnSizing(fwSide, pRect);
}
// OnSysCommand is called when the user makes a choice from the system menu
// and also in other circumstances.
void
CMainDialog::OnSysCommand(UINT nId, LONG lParam)
{
CMenu *pSysMenu;
PGPUInt32 checkState;
// Did the user select the "Stay On Top" menu item?
switch (nId)
{
case IDM_STAYONTOP:
pSysMenu = GetSystemMenu(FALSE);
pgpAssertAddrValid(pSysMenu, CMenu);
checkState = pSysMenu->GetMenuState(IDM_STAYONTOP, MF_BYCOMMAND);
if (checkState == MF_CHECKED)
{
pSysMenu->CheckMenuItem(IDM_STAYONTOP,
MF_BYCOMMAND | MF_UNCHECKED);
SetWindowPos(&CWnd::wndNoTopMost, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
}
else
{
pSysMenu->CheckMenuItem(IDM_STAYONTOP, MF_BYCOMMAND | MF_CHECKED);
SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
}
// Save the window on top position in the registry.
SaveMainWndOnTop();
break;
default:
CWnd::OnSysCommand(nId, lParam);
break;
}
}
// OnQueryDragIcon is called to obtain the cursor to display when dragging a
// minimized window.
HCURSOR
CMainDialog::OnQueryDragIcon()
{
return (HCURSOR) mHIcon;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -