📄 cframe.cpp
字号:
*
* Return Value:
* BOOL TRUE if this initialization succeeded, FALSE
* otherwise.
*/
BOOL CFrame::PreShowInit(void)
{
return TRUE;
}
/*
* CFrame::OpenInitialFiles
*
* Purpose:
* Opens any files that were present on the command line.
*/
void CFrame::OpenInitialFiles(void)
{
UINT i;
PCDocument pDoc;
//Create a new document if we have nothing specific to open
if (0==m_cCmdArgs)
{
pDoc=m_pCL->NewDocument(TRUE);
if (NULL!=pDoc)
pDoc->Load(TRUE, NULL);
UpdateToolbar();
return;
}
//Iterate over the arguments and see if there's any filenames
for (i=0; i < m_cCmdArgs; i++)
{
LPTSTR psz=m_ppszCmdArgs[i];
if (NULL==psz)
break;
//Skip switches prefixed with / and -
if ((TCHAR)0!=*psz && TEXT('/')!=*psz && TEXT('-')!=*psz)
{
pDoc=m_pCL->NewDocument(TRUE);
if (NULL!=pDoc)
pDoc->Load(TRUE, psz);
}
UpdateToolbar();
}
return;
}
/*
* CFrame::CreateToolbar
*
* Purpose:
* Procedure to create all the necessary toolbar buttons.
*
* Return Value:
* UINT Number of tools added to the bar.
*/
UINT CFrame::CreateToolbar(void)
{
UINT uState=GIZMO_NORMAL;
UINT utCmd =GIZMOTYPE_BUTTONCOMMAND;
UINT utEx =GIZMOTYPE_BUTTONATTRIBUTEEX;
//File New, Open, Close, Save, Import
m_pTB->Add(utCmd, 0, IDM_FILENEW, m_dxB, m_dyB, NULL, NULL
, 3, uState);
m_pTB->Add(utCmd, 1, IDM_FILEOPEN, m_dxB, m_dyB, NULL, NULL
, 4, uState);
m_pTB->Add(utCmd, 2, IDM_FILECLOSE, m_dxB, m_dyB, NULL, m_hBmp
, 0, uState);
m_pTB->Add(utCmd, 3, IDM_FILESAVE, m_dxB, m_dyB, NULL, NULL
, 5, uState);
//Separator
m_pTB->Add(GIZMOTYPE_SEPARATOR, 4, 0, 6, m_dyB, NULL, NULL
, 0, uState);
//Edit Undo, Cut, Copy, Paste
m_pTB->Add(utCmd, 5, IDM_EDITUNDO, m_dxB, m_dyB, NULL, m_hBmp
, 1, uState);
m_pTB->Add(utCmd, 6, IDM_EDITCUT, m_dxB, m_dyB, NULL, NULL
, 0, uState);
m_pTB->Add(utCmd, 7, IDM_EDITCOPY, m_dxB, m_dyB, NULL, NULL
, 1, uState);
m_pTB->Add(utCmd, 8, IDM_EDITPASTE, m_dxB, m_dyB, NULL, NULL
, 2, uState);
return 9;
}
/*
* CFrame::MessageLoop
*
* Purpose:
* Spins in a standard message loop (with accelerators) until
* WM_QUIT is found after which it returns.
*
* Return Value:
* WPARAM Contents of msg.wParam from WM_QUIT.
*/
WPARAM CFrame::MessageLoop(void)
{
MSG msg;
while (GetMessage(&msg, NULL, 0,0 ))
{
if (!m_pCL->TranslateAccelerator(&msg))
{
if (!TranslateAccelerator(m_hWnd, m_hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return msg.wParam;
}
/*
* CFrame::FMessageHook
*
* Purpose:
* Provides a derivation of the base CFrame class to hook all
* messages to the window procedure for special processing.
* WM_COMMAND is NOT sent here as that goes through OnCommand
* instead.
*
* Parameters:
* <WndProc Parameters>
* pLRes LRESULT * in which to store the return value
* for the message.
*
* Return Value:
* BOOL TRUE to prevent further processing, FALSE
* otherwise.
*/
BOOL CFrame::FMessageHook(HWND hWnd, UINT iMsg, WPARAM wParam
, LPARAM lParam, LRESULT *pLRes)
{
*pLRes=0;
return FALSE;
}
/*
* CFrame::OnCommand
*
* Purpose:
* WM_COMMAND handler for the frame window so derivations can
* process their messages and then pass the standard commands (like
* file open and save) on to the base class.
*
* Parameters:
* hWnd HWND of the frame window.
* wParam WPARAM of the message.
* lParam LPARAM of the message.
*
* Return Value:
* LRESULT Return value for the message.
*/
LRESULT CFrame::OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PCDocument pDoc;
TCHAR szFile[CCHPATHMAX];
BOOL fOK;
UINT uTemp;
UINT uType;
PCHourglass pHour;
COMMANDPARAMS(wID, wCode, hWndMsg);
/*
* Don't bother with anything during first initialization,
* skipping many toolbar notifications.
*/
if (m_fInit)
return 0L;
pDoc=m_pCL->ActiveDocument();
switch (wID)
{
case IDM_FILENEW:
if (!m_pCL->SDIVerify())
break;
pHour=new CHourglass;
pDoc=m_pCL->NewDocument(TRUE);
//Insure the document is untitled.
if (NULL!=pDoc)
pDoc->Load(TRUE, NULL);
delete pHour;
break;
case IDM_FILEOPEN:
if (!m_pCL->SDIVerify())
break;
szFile[0]=0;
fOK=SaveOpenDialog(szFile, CCHPATHMAX, IDS_FILEOPEN
, TRUE, &uType);
if (!fOK)
return 0L;
pDoc=m_pCL->NewDocument(FALSE);
if (NULL==pDoc)
return 0L;
pHour=new CHourglass;
uTemp=pDoc->Load(TRUE, szFile);
delete pHour;
pDoc->ErrorMessage(uTemp);
//Close the new doc on failure, show on success.
if (DOCERR_NONE!=uTemp)
m_pCL->CloseDocument(pDoc);
else
m_pCL->ShowDocument(pDoc, TRUE);
return (DOCERR_NONE==uTemp);
case IDM_FILECLOSE:
//Ask if you want to save.
if (!m_pCL->FCleanVerify(pDoc))
return 0L;
m_pCL->CloseDocument(pDoc);
UpdateToolbar();
break;
case IDM_FILESAVE:
//If we get this from the toolbar, we may need Save As
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);
return (DOCERR_NONE==uTemp);
}
//FALL through to File/Save As for no name documents.
case IDM_FILESAVEAS:
//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);
case IDM_FILEEXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0L);
break;
case IDM_EDITCUT:
case IDM_EDITCOPY:
pHour=new CHourglass;
pDoc->Clip(hWnd, (IDM_EDITCUT==wID));
delete pHour;
//Update the toolbar as appropriate.
m_pTB->Enable(IDM_EDITPASTE, pDoc->FQueryPaste());
break;
case IDM_EDITUNDO:
pDoc->Undo();
break;
case IDM_EDITPASTE:
pHour=new CHourglass;
pDoc->Paste(hWnd);
delete pHour;
break;
//These commands don't happen in SDI builds; not on the menu
case IDM_WINDOWCASCADE:
m_pCL->OnWindowCommand(WM_MDICASCADE, 0);
break;
case IDM_WINDOWTILEHORZ:
m_pCL->OnWindowCommand(WM_MDITILE, MDITILE_HORIZONTAL);
break;
case IDM_WINDOWTILEVERT:
m_pCL->OnWindowCommand(WM_MDITILE, MDITILE_VERTICAL);
break;
case IDM_WINDOWICONS:
m_pCL->OnWindowCommand(WM_MDIICONARRANGE, 0);
break;
case IDM_HELPABOUT:
DialogBox(m_hInst, MAKEINTRESOURCE(IDD_ABOUT)
, m_hWnd, (DLGPROC)AboutProc);
break;
default:
return m_pCL->DefaultFrameProc(hWnd, WM_COMMAND, wParam
, lParam);
}
return 0L;
}
/*
* CFrame::OnDocumentDataChange
*
* Purpose:
* Most of the CDocumentAdviseSink notifications we get are fairly
* standard implementations. When data in the document changes,
* however, there's probably more special things we can do, so we
* keep this simple case simple with this hook, not forcing a
* derived class to reimplement CDocumentAdviseSink.
*
* Parameters:
* pDoc PCDocument notifying the sink.
*/
void CFrame::OnDocumentDataChange(PCDocument pDoc)
{
return;
}
/*
* CFrame::OnDocumentActivate
*
* Purpose:
* Most of the CDocumentAdviseSink notifications we get are fairly
* standard implementations. When the current document changes,
* however, there's probably more UI that frame derivations need
* to do, so we allow the hook here.
*
* Parameters:
* pDoc PCDocument notifying the sink.
*/
void CFrame::OnDocumentActivate(PCDocument pDoc)
{
return;
}
/*
* CFrame::SaveOpenDialog
*
* Purpose:
* Invokes the COMMDLG.DLL GetOpenFileName dialog and retrieves
* a filename for saving or opening.
*
* Parameters:
* pszFile LPTSTR buffer to receive the entered filename.
* cchFile UINT length of pszFile
* idsCaption UINT of string to use in the caption bar.
* fOpen BOOL indicating if we want file open or save.
* puType UINT * in which we store the selected type.
* Can be NULL.
*
* Return Value:
* BOOL TRUE if the function retrieved a filename,
* FALSE if the user pressed CANCEL.
*/
BOOL CFrame::SaveOpenDialog(LPTSTR pszFile, UINT cchFile
, UINT idsCaption, BOOL fOpen, UINT *puType)
{
OPENFILENAME ofn;
TCHAR szFilter[80];
UINT cch;
BOOL fRet;
#ifdef DEBUG
DWORD dwErr;
#endif
if (NULL==pszFile)
return FALSE;
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize =sizeof(OPENFILENAME);
ofn.hwndOwner =m_hWnd;
if (fOpen)
lstrcpy(szFilter, PSZ(IDS_FILEOPENFILTER));
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -