RichEdDlg.cpp
上传用户:niucheng
上传日期:2007-01-02
资源大小:56k
文件大小:7k
- // RichEdDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "RichEd.h"
- #include "RichEdDlg.h"
- #include "GetFontNameDlg.h"
- #include "GetFontSizeDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CRichEdDlg dialog
- CRichEdDlg::CRichEdDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CRichEdDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CRichEdDlg)
- m_sEdit = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CRichEdDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CRichEdDlg)
- DDX_Control(pDX, IDC_COMBO, m_combo);
- DDX_Control(pDX, IDC_RICHEDIT, m_richedit);
- DDX_Text(pDX, IDC_EDIT, m_sEdit);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CRichEdDlg, CDialog)
- //{{AFX_MSG_MAP(CRichEdDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDEXECUTE, OnExecute)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CRichEdDlg message handlers
- BOOL CRichEdDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
-
- // Fill up the combo box.
- m_combo.AddString("SetRTF()");
- m_combo.AddString("GetRTF()");
- m_combo.AddString("------------");
- m_combo.AddString("SetSelectionBold()");
- m_combo.AddString("SetSelectionItalic()");
- m_combo.AddString("SetSelectionUnderlined()");
- m_combo.AddString("------------");
- m_combo.AddString("SelectionIsBold()");
- m_combo.AddString("SelectionIsItalic()");
- m_combo.AddString("SelectionIsUnderlined()");
- m_combo.AddString("------------");
- m_combo.AddString("SetParagraphLeft()");
- m_combo.AddString("SetParagraphCenter()");
- m_combo.AddString("SetParagraphRight()");
- m_combo.AddString("------------");
- m_combo.AddString("ParagraphIsLeft()");
- m_combo.AddString("ParagraphIsCentered()");
- m_combo.AddString("ParagraphIsRight()");
- m_combo.AddString("------------");
- m_combo.AddString("SetParagraphBulleted()");
- m_combo.AddString("ParagraphIsBulleted()");
- m_combo.AddString("------------");
- m_combo.AddString("SelectColor()");
- m_combo.AddString("------------");
- m_combo.AddString("SetFontName()");
- m_combo.AddString("SetFontSize()");
- m_combo.AddString("GetSelectionFontName()");
- m_combo.AddString("GetSelectionFontSize()");
- return TRUE; // return TRUE unless you set the focus to a control
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CRichEdDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CRichEdDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CRichEdDlg::OnExecute()
- {
- // TODO: Add your control notification handler code here
- UpdateData(true);
- CString sCmd = "";
- m_combo.GetWindowText(sCmd); // Get the selected string from the combo box.
- // Do what they want.
- if (sCmd == "SetRTF()")
- {
- m_richedit.SetRTF(m_sEdit); // Set the richedit's text w/ the text of sEdit.
- // sEdit should have an RTF string, otherwise it won't work.
- }
- else if (sCmd == "GetRTF()")
- {
- m_sEdit = m_richedit.GetRTF();
- }
- else if (sCmd == "SelectionIsBold()")
- {
- if (m_richedit.SelectionIsBold())
- MessageBox("true");
- else
- MessageBox("false");
- }
- else if (sCmd == "SelectionIsItalic()")
- {
- if (m_richedit.SelectionIsItalic())
- MessageBox("true");
- else
- MessageBox("false");
- }
- else if (sCmd == "SelectionIsUnderlined()")
- {
- if (m_richedit.SelectionIsUnderlined())
- MessageBox("true");
- else
- MessageBox("false");
- }
- else if (sCmd == "SetSelectionBold()")
- m_richedit.SetSelectionBold();
- else if (sCmd == "SetSelectionItalic()")
- m_richedit.SetSelectionItalic();
- else if (sCmd == "SetSelectionUnderlined()")
- m_richedit.SetSelectionUnderlined();
- else if (sCmd == "SetParagraphLeft()")
- m_richedit.SetParagraphLeft();
- else if (sCmd == "SetParagraphCenter()")
- m_richedit.SetParagraphCenter();
- else if (sCmd == "SetParagraphRight()")
- m_richedit.SetParagraphRight();
- else if (sCmd == "ParagraphIsLeft()")
- {
- if (m_richedit.ParagraphIsLeft())
- MessageBox("true");
- else
- MessageBox("false");
- }
- else if (sCmd == "ParagraphIsRight()")
- {
- if (m_richedit.ParagraphIsRight())
- MessageBox("true");
- else
- MessageBox("false");
- }
- else if (sCmd == "ParagraphIsCentered()")
- {
- if (m_richedit.ParagraphIsCentered())
- MessageBox("true");
- else
- MessageBox("false");
- }
- else if (sCmd == "SetParagraphBulleted()")
- m_richedit.SetParagraphBulleted();
- else if (sCmd == "ParagraphIsBulleted()")
- {
- if (m_richedit.ParagraphIsBulleted())
- MessageBox("true");
- else
- MessageBox("false");
- }
- else if (sCmd == "SelectColor()")
- m_richedit.SelectColor();
- else if (sCmd == "SetFontName()")
- {
- CGetFontNameDlg dlg;
- CStringArray saFontList;
- m_richedit.GetSystemFonts(saFontList);
- dlg.m_psaFontList = &saFontList; // give the dialog our font list.
- int r = dlg.DoModal();
- if (r == IDCANCEL)
- return;
- m_richedit.SetFontName(dlg.m_sFontName); //otherwise set the font name.
- }
- else if (sCmd == "SetFontSize()")
- {
- CGetFontSizeDlg dlg;
- int r = dlg.DoModal(); // Get the size from the user.
- if (r == IDCANCEL)
- return;
- m_richedit.SetFontSize(dlg.m_nFontSize);
- }
- else if (sCmd == "GetSelectionFontName()")
- MessageBox(m_richedit.GetSelectionFontName());
- else if (sCmd == "GetSelectionFontSize()")
- {
- char num[2];
- ltoa(m_richedit.GetSelectionFontSize(), num, 10);
- MessageBox(num);
- }
- m_richedit.SetFocus();
- UpdateData(false);
- }