📄 cframe.cpp
字号:
lstrcpy(szFilter, PSZ(IDS_FILESAVEFILTER));
cch=lstrlen(szFilter);
ReplaceCharWithNull(szFilter, szFilter[cch-1]);
ofn.lpstrFilter =szFilter;
ofn.nFilterIndex =1L;
ofn.lpstrTitle =PSZ(idsCaption);
ofn.lpstrFile =pszFile;
ofn.nMaxFile =cchFile;
ofn.lpstrDefExt =PSZ(IDS_DEFEXT);
if (fOpen)
{
ofn.Flags=OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
fRet=GetOpenFileName(&ofn);
}
else
{
ofn.Flags=OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
fRet=GetSaveFileName(&ofn);
}
if (fRet || NULL!=puType)
*puType=(UINT)ofn.nFilterIndex;
#ifdef DEBUG
dwErr=CommDlgExtendedError();
#endif
return fRet;
}
/*
* CFrame::ReplaceCharWithNull
*
* Purpose:
* Walks a null-terminated string and replaces a given character
* with a zero for use with the SaveOpenDialog member.
*
* Parameters:
* psz LPTSTR to the string to process.
* ch int character to replace.
*
* Return Value:
* int Number of characters replaced. -1 if psz is NULL
*/
UINT CFrame::ReplaceCharWithNull(LPTSTR psz, int ch)
{
UINT cChanged=0;
if (NULL==psz)
return 0;
while ((TCHAR)0!=*psz)
{
if (ch==*psz)
{
*psz=0;
cChanged++;
}
psz++;
}
return cChanged;
}
/*
* CFrame::PszWhiteSpaceScan
*
* Purpose:
* Skips characters in a string until a whitespace or non-whitespace
* character is seen. Whitespace is defined as \n, \r, \t, or ' '.
*
* Parameters:
* psz LPTSTR to string to manipulate
* fSkip BOOL TRUE if we want to skip whitespace.
* FALSE if we want to skip anything but whitespace.
*
* Return Value:
* LPTSTR Pointer to first character in the string that
* either non-whitespace (fSkip=TRUE) or
* whitespace (fSkip=FALSE), which may be the
* null terminator.
*/
LPTSTR CFrame::PszWhiteSpaceScan(LPTSTR psz, BOOL fSkip)
{
TCHAR ch;
BOOL fWhite;
while (ch=*psz)
{
//Not too sure how this localizes...
fWhite=(TEXT('\n')==ch || TEXT('\r')==ch
|| TEXT('\t')==ch || TEXT(' ')==ch);
//Too bad C doesn't have a logical XOR (^^) operator.
if ((fSkip && !fWhite) || (!fSkip && fWhite))
break;
psz++;
}
return psz;
}
//PUBLIC FUNCTIONS
/*
* CFrame::AskAndSave
*
* Purpose:
* If a document is closed and is dirty the client window we own
* will get the document's filename and call us here. We will
* ask the user if they want to save that file and if so, send a
* message to our frame window to execute the Save command.
*
* Parameters:
* pszDoc LPTSTR name of the document. If the first
* character is 0 then we use (Untitled).
*
* Return Value:
* BOOL TRUE if the user saved or didn't; FALSE on
* if the user pressed cancel.
*/
BOOL CFrame::AskAndSave(LPTSTR pszDoc)
{
BOOL fRet=TRUE;
UINT uRet;
TCHAR szTemp[CCHFILENAMEMAX+100];
if (NULL==pszDoc)
return FALSE;
if ((TCHAR)0==*pszDoc)
pszDoc=PSZ(IDS_UNTITLED);
else
{
GetFileTitle(pszDoc, szTemp, CCHFILENAMEMAX);
lstrcpy(pszDoc, szTemp);
}
wsprintf(szTemp, PSZ(IDS_FILEDIRTY), pszDoc);
uRet=MessageBox(m_hWnd, szTemp, PSZ(IDS_CAPTION)
, MB_YESNOCANCEL | MB_ICONEXCLAMATION);
/*
* If the user wants to save, tell the window to execute the
* command.
*/
if (IDYES==uRet)
{
/*
* The following is code taken from IDM_SAVE and IDM_SAVEAS
* cases inside OnCommand above. It's copied here to
* allow processing of the return value from pDoc->Save.
*/
PCDocument pDoc;
TCHAR szFile[CCHPATHMAX];
BOOL fOK;
UINT uTemp;
UINT uType;
PCHourglass pHour;
pDoc=m_pCL->ActiveDocument();
fOK=pDoc->FQuerySave();
if (fOK)
{
//Save using current document name and version
pHour=new CHourglass;
uTemp=pDoc->Save(0, NULL);
delete pHour;
pDoc->ErrorMessage(uTemp);
//This return code is for CFrame::AskAndSave
return (DOCERR_NONE==uTemp);
}
//Go get a filename, then save it.
pDoc->FilenameGet(szFile, CCHPATHMAX);
fOK=SaveOpenDialog(szFile, CCHPATHMAX, IDS_FILESAVEAS
, FALSE, &uType);
if (!fOK)
return 0L;
pHour=new CHourglass;
uTemp=pDoc->Save(uType, szFile);
delete pHour;
pDoc->ErrorMessage(uTemp);
return (DOCERR_NONE==uTemp);
}
//TRUE for No, False for Cancel
return (IDCANCEL!=uRet);
}
/*
* CFrame::UpdateMenus
*
* Purpose:
* Handles the WM_INITMENU message for the frame window. Depending
* on the existence of an active window, menu items are selectively
* enabled and disabled.
*
* Parameters:
* hMenu HMENU of the menu to intialize
* iMenu UINT position of the menu.
*/
void CFrame::UpdateMenus(HMENU hMenu, UINT iMenu)
{
PCDocument pDoc;
BOOL fOK=FALSE;
UINT uTemp;
UINT uTempE;
UINT uTempD;
pDoc=m_pCL->ActiveDocument();
uTempE=MF_ENABLED | MF_BYCOMMAND;
uTempD=MF_DISABLED | MF_GRAYED | MF_BYCOMMAND;
uTemp=((NULL!=pDoc) ? uTempE : uTempD);
/*
* File menu: If there is no current document window, disable
* Close, Save, and Save As. If there is a document but
* it doesn't have a filename, disable save.
*/
if (m_phMenu[0]==hMenu)
{
EnableMenuItem(hMenu, IDM_FILECLOSE, uTemp);
EnableMenuItem(hMenu, IDM_FILESAVE, uTemp);
EnableMenuItem(hMenu, IDM_FILESAVEAS, uTemp);
if (NULL!=pDoc)
fOK=pDoc->FQuerySave();
EnableMenuItem(hMenu, IDM_FILESAVE, (fOK) ? uTempE : uTempD);
}
/*
* Edit menus: If there's no document, disable all of it.
* If there's a document but no clipboard format available,
* disable paste only.
*/
if (m_phMenu[1]==hMenu)
{
EnableMenuItem(hMenu, IDM_EDITUNDO, uTemp);
EnableMenuItem(hMenu, IDM_EDITCOPY, uTemp);
EnableMenuItem(hMenu, IDM_EDITCUT, uTemp);
/*
* Paste has two dependencies; format available and an open
* document
*/
if (NULL!=pDoc)
fOK=pDoc->FQueryPaste();
fOK &=(uTemp==uTempE);
EnableMenuItem(hMenu,IDM_EDITPASTE, (fOK) ? uTempE : uTempD);
}
#ifdef MDI
//Window menu: no document, no commands
if (m_hMenuWindow==hMenu)
{
EnableMenuItem(hMenu, IDM_WINDOWCASCADE, uTemp);
EnableMenuItem(hMenu, IDM_WINDOWTILEHORZ, uTemp);
EnableMenuItem(hMenu, IDM_WINDOWTILEVERT, uTemp);
EnableMenuItem(hMenu, IDM_WINDOWICONS, uTemp);
}
#endif
return;
}
/*
* CFrame::UpdateToolbar
*
* Purpose:
* Enables and disablest toolbar buttons depending on whether we
* have a document or not and depending on clipboard format
* availability.
*/
void CFrame::UpdateToolbar(void)
{
PCDocument pDoc;
BOOL fEnable;
pDoc=m_pCL->ActiveDocument();
fEnable=(NULL!=pDoc);
if (m_fLastEnable!=fEnable)
{
m_fLastEnable=fEnable;
//No document, disable just about everything
m_pTB->Enable(IDM_FILECLOSE, fEnable);
m_pTB->Enable(IDM_FILESAVE, fEnable);
m_pTB->Enable(IDM_EDITUNDO, fEnable);
m_pTB->Enable(IDM_EDITCUT, fEnable);
m_pTB->Enable(IDM_EDITCOPY, fEnable);
}
//Special handling: clipboard format available, enable paste
if (NULL!=pDoc)
fEnable &= pDoc->FQueryPaste();
//Paste is not enabled unless there's a document too
if (m_fLastPaste!=fEnable)
{
m_fLastPaste=fEnable;
m_pTB->Enable(IDM_EDITPASTE, fEnable);
}
return;
}
/*
* CFrame::WindowTitleSet
*
* Purpose:
* Handles changing the caption bar of a document window.
*
* Parameters:
* pDoc PCDocument of the document affected. If NULL,
* then we remove titles.
* fDocTitle BOOL indicating to set the document or the main
* window captions. In MDI we may do either, this
* is ignored in SDI.
*/
void CFrame::WindowTitleSet(PCDocument pDoc, BOOL fDocTitle)
{
TCHAR szTitle[CCHPATHMAX];
TCHAR szFile[CCHPATHMAX];
/*
* Go grab the filename. If we get an emtpy file back, then
* we'll use (Untitled). If we have a NULL document, then we'll
* just set the title of the app back to having no filename.
*/
if (NULL!=pDoc)
{
pDoc->FilenameGet(szTitle, CCHPATHMAX);
if ((TCHAR)0==szTitle[0])
lstrcpy(szFile, PSZ(IDS_UNTITLED));
else
{
GetFileTitle(szTitle, szFile, sizeof(szFile));
#ifndef WIN32
AnsiUpper(szFile);
#endif
}
}
else
szFile[0]=0;
#ifndef MDI
//SDI always titles the application window
fDocTitle=FALSE;
#endif
if (fDocTitle)
{
if (NULL!=pDoc)
SetWindowText(pDoc->Window(), szFile);
}
else
{
if ((TCHAR)0!=szFile[0])
{
wsprintf(szTitle, TEXT("%s - %s"), PSZ(IDS_CAPTION)
, (LPTSTR)szFile);
SetWindowText(m_hWnd, szTitle);
}
else
SetWindowText(m_hWnd, PSZ(IDS_CAPTION));
}
return;
}
/*
* CFrame::StatusLine (inline)
*
* Purpose:
* Returns the status line object pointer to the caller so they can
* display status messages.
*
* Return Value:
* PCStatusLine Pointer to the status line object.
*/
PCStatusLine inline CFrame::StatusLine(void)
{
return m_pSL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -