?? richeditpage.cpp
字號:
// @parm DWORD | dwCookie | handle to the file in which will be
// the rich edit control content
// @parm LPBYTE | pbBuff | Pointer to a buffer to write to .
// For a stream-out (write) operation,
// the buffer contains data from the
// control that the callback function
// writes to some storage
// @parm LONG | cb | Number of bytes to write
// @parm LONG | *pcb | Pointer to a variable that the
// callback function sets to the number
// of bytes actually write
//----------------------------------------------------------------------------
// @prog
// Frunza Adriana
// @revs
// 20-09-2001 - First implementation
//----------------------------------------------------------------------------
// @todo
//----------------------------------------------------------------------------
DWORD CALLBACK CRicheditPage::MyStreamOutCallback(DWORD dwCookie,
LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CFile* pFile = (CFile*) dwCookie;
pFile->Write(pbBuff, cb);
*pcb = cb;
return 0;
}
// function added with classwizard in 20 september 2001
void CRicheditPage::OnFileSaveAs()
{
m_nFileNew++;
if ( m_bBeginWriting )
{
if ( m_nBeginWriting==1)
{
// I define the file dialog
CFileDialog fileDlg(FALSE, "rtf", NULL, OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,
"rtf files(*.rtf)|*.rtf|");
// display the file dialog
if (fileDlg.DoModal () == IDCANCEL)
{
m_nBeginWriting=0;
m_rtf.SetModify();
return;
}
// I obtain the file name
CString filename = fileDlg.GetPathName ();
m_strFilename=filename;
CFile fis;
EDITSTREAM es;
es.dwCookie = (DWORD) &fis;
es.pfnCallback = MyStreamOutCallback;
// I open the file with tne modeWrite and modeCreate mode
fis.Open(filename, CFile::modeCreate | CFile::modeWrite);
es.dwCookie = (DWORD) &fis;
es.pfnCallback = MyStreamOutCallback;
// I put the content in the file
m_rtf.StreamOut(SF_RTF, es);
fis.Close();
m_rtf.SetModify(FALSE);
}// end m_nBeginWriting == 1
else if ( m_nBeginWriting >1)
{
CFile fis;
EDITSTREAM es;
es.dwCookie = (DWORD) &fis;
es.pfnCallback = MyStreamOutCallback;
// I open the file with tne modeWrite mode
fis.Open(m_strFilename, CFile::modeWrite);
// I put the content in the file
m_rtf.StreamOut(SF_RTF, es);
m_rtf.SetModify(FALSE);
fis.Close();
}
}//end if begin writing
else if ( m_bFisNou)
{
if ( m_nFileNew == 1)
{
// define the dialog window
CFileDialog fileDlg(FALSE, "rtf", NULL, OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,
"rtf files(*.rtf)|*.rtf|");
// display the dialog window
if (fileDlg.DoModal () == IDCANCEL)
{
m_nFileNew=0;
m_rtf.SetModify();
return;
}
// obtain the file name
CString filename = fileDlg.GetPathName ();
m_strFilename=filename;
CFile fis;
EDITSTREAM es;
es.dwCookie = (DWORD) &fis;
es.pfnCallback = MyStreamOutCallback;
// I open the file with tne modeWrite and modeCreate mode
fis.Open(filename, CFile::modeCreate | CFile::modeWrite);
es.dwCookie = (DWORD) &fis;
es.pfnCallback = MyStreamOutCallback;
// put the content in the file
m_rtf.StreamOut(SF_RTF, es);
fis.Close();
m_rtf.SetModify(FALSE);
}// end m_nFileNew==1
else if ( m_nFileNew > 1 )
{
CFile fis;
EDITSTREAM es;
es.dwCookie = (DWORD) &fis;
es.pfnCallback = MyStreamOutCallback;
// open the file with the modeWrite mode
fis.Open(m_strFilename, CFile::modeWrite);
// put the content in the file
m_rtf.StreamOut(SF_RTF, es);
m_rtf.SetModify(FALSE);
fis.Close();
}
}//end if file new
else if (m_bFisOpen)// file open
{
// if I want to save the file that I have opened and I did not
// CREATED and I have changed the content, I don't want to appear
// the dialog box which asks me for the name to save the file, but
// I want the file to be saved with the name the file has already
CFile fis;
EDITSTREAM es;
es.dwCookie = (DWORD) &fis;
es.pfnCallback = MyStreamOutCallback;
// open the file with the modeWrite mode
fis.Open(m_strFilename, CFile::modeWrite);
// put the content in the file
m_rtf.StreamOut(SF_RTF, es);
m_rtf.SetModify(FALSE);
fis.Close();
}// end file open
CString msg;
msg.Format("MyRtf - %s" , m_strFilename );
SetWindowText ( msg ) ;
}
// function added with classwizard in 20 september 2001
void CRicheditPage::OnFilePrint()
{
Print(TRUE);
}
// function added with classwizard on Friday 21 september 2001
void CRicheditPage::OnBold()
{
m_rtf.SetSelectionBold();
}
// function added with classwizard on Friday 21 september 2001
void CRicheditPage::OnItalic()
{
m_rtf.SetSelectionItalic();
}
// function added with classwizard on Friday 21 september 2001
void CRicheditPage::OnUnderline()
{
m_rtf.SetSelectionUnderline();
}
// function added with classwizard on Friday 21 september 2001
void CRicheditPage::OnEditUndo()
{
// if possible undo the last operation
if (m_rtf.CanUndo())
m_rtf.Undo();
}
// function added with classwizard on Friday 21 september 2001
void CRicheditPage::OnEditCut()
{
// Delete the selected text and copy it to the clipboard.
m_rtf.Cut();
}
// function added with classwizard on Friday 21 september 2001
void CRicheditPage::OnEditCopy()
{
// Copy the text to the clipboard.
m_rtf.Copy();
}
// function added with classwizard on Friday 21 september 2001
void CRicheditPage::OnEditPaste()
{
// Paste the clipboard data if possible.
if (m_rtf.CanPaste())
// Replace the selected text with the text in the clipboard.
m_rtf.Paste();
}
// FUNCTION ADDED ON SATURDAY 22 SEPTEMBER 2001
void CRicheditPage::OnColour()
{
m_rtf.SetColour();
}
// function added with classwizard on Friday 21 september 2001
void CRicheditPage::OnClose()
{
// Reset the modified state only if the text has been modified.
if (m_rtf.GetModify())
{
MessageBeep(0xFFFFFFFF);
int nResp = MessageBox(" Do you want to save the changes made to your document?", "MyRtf",MB_ICONWARNING | MB_YESNOCANCEL);
if ( nResp == IDYES )
{
OnFileSave();
m_rtf.SetModify(FALSE);
CDialog::OnClose();
}
else if ( nResp == IDNO )
CDialog::OnClose();
else if ( nResp == IDCANCEL )
{/* do not close the application*/}
}
else CDialog::OnClose();
}
// function added with classwizard on Saturday 21 september 2001
void CRicheditPage::OnParagraphLeft()
{
m_rtf.SetParagraphLeft();
}
// function added with classwizard on Monday 24 september 2001
void CRicheditPage::OnParagraphCenter()
{
m_rtf.SetParagraphCenter();
}
// function added with classwizard on Monday 24 september 2001
void CRicheditPage::OnParagraphRight()
{
m_rtf.SetParagraphRight();
}
// function added with classwizard on Monday 24 september 2001
void CRicheditPage::OnParagraphBulleted()
{
m_rtf.SetParagraphBulleted();
}
// function added with classwizard on Wednesday 26 september 2001
void CRicheditPage::OnFormatFont()
{
CFontDialog dlg( NULL , CF_BOTH | CF_EFFECTS );
if ( dlg.DoModal() != IDOK )
return;
if ( dlg.IsUnderline() )
{
m_rtf.SetSelectionUnderline ();
}
CString faceName = dlg.GetFaceName();
m_rtf.SetFontName( faceName ) ;
COLORREF clr= dlg.GetColor ();
m_rtf.SetColor(clr);
int nPointSize = dlg.GetSize();
m_rtf.SetFontSize( nPointSize ) ;
}
// function added with classwizard on Tuesday 16 octomber 2001
// select all of the text
void CRicheditPage::OnEditSelectAll()
{
m_rtf.SetSel(0, -1);
}
// function added with classwizard on Tuesday 16 octomber 2001
// delete the current selection
void CRicheditPage::OnEditDelete()
{
m_rtf.Clear();
}
// function added with classwizard on Saturday 20 octomber 2001
// this code is taken from dlgcbr32
BOOL CRicheditPage::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
{
ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
// allow top level routing frame to handle the message
if (GetRoutingFrame() != NULL)
return FALSE;
// need to handle both ANSI and UNICODE versions of the message
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
TCHAR szFullText[256];
CString strTipText;
UINT nID = pNMHDR->idFrom;
if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
{
// idFrom is actually the HWND of the tool
nID = ((UINT)(WORD)::GetDlgCtrlID((HWND)nID));
}
if (nID != 0) // will be zero on a separator
{
AfxLoadString(nID, szFullText);
// this is the command id, not the button index
AfxExtractSubString(strTipText, szFullText, 1, '\n');
}
#ifndef _UNICODE
if (pNMHDR->code == TTN_NEEDTEXTA)
lstrcpyn(pTTTA->szText, strTipText,
(sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0])));
else
_mbstowcsz(pTTTW->szText, strTipText,
(sizeof(pTTTW->szText)/sizeof(pTTTW->szText[0])));
#else
if (pNMHDR->code == TTN_NEEDTEXTA)
_wcstombsz(pTTTA->szText, strTipText,
(sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0])));
else
lstrcpyn(pTTTW->szText, strTipText,
(sizeof(pTTTW->szText)/sizeof(pTTTW->szText[0])));
#endif
*pResult = 0;
// bring the tooltip window above other popup windows
::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,
SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
return TRUE; // message was handled
}
/////////////////////////////////////////////////////////////////////////////
// CRicheditPage::OnEnterIdle
// OnEnterIdle updates the status bar when there's nothing better to do.
// This code is based on CFrameWnd::OnEnterIdle.
void CRicheditPage::OnEnterIdle(UINT nWhy, CWnd* pWho)
{
if (nWhy != MSGF_MENU || m_nIDTracking == m_nIDLastMessage)
return;
ASSERT(m_nIDTracking == m_nIDLastMessage);
}
void CRicheditPage::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
// this code is taken from Ftptree MSDN sample
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -