www.pudn.com > RulerRichEditCtrlDemo.rar > RulerRichEditCtrlDemoDlg.cpp


// RulerRichEditCtrlDemoDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "RulerRichEditCtrlDemo.h" 
#include "RulerRichEditCtrlDemoDlg.h" 
#include "AboutDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CRulerRichEditCtrlDemoDlg dialog 
 
CRulerRichEditCtrlDemoDlg::CRulerRichEditCtrlDemoDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CRulerRichEditCtrlDemoDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CRulerRichEditCtrlDemoDlg) 
	m_showRuler = FALSE; 
	m_showToolbar = FALSE; 
	m_readOnly = FALSE; 
	//}}AFX_DATA_INIT 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CRulerRichEditCtrlDemoDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CRulerRichEditCtrlDemoDlg) 
	DDX_Control(pDX, IDC_CHECK_SHOW_TOOLBAR, m_toolbar); 
	DDX_Control(pDX, IDC_CHECK_SHOW_RULER, m_ruler); 
	DDX_Control(pDX, IDC_BUTTON_NEW, m_new); 
	DDX_Control(pDX, IDC_BUTTON_SAVE, m_save); 
	DDX_Control(pDX, IDC_BUTTON_LOAD, m_load); 
	DDX_Control(pDX, IDOK, m_ok); 
	DDX_Control(pDX, IDC_STATIC_PLACEMENT, m_placement); 
	DDX_Check(pDX, IDC_CHECK_SHOW_RULER, m_showRuler); 
	DDX_Check(pDX, IDC_CHECK_SHOW_TOOLBAR, m_showToolbar); 
	DDX_Check(pDX, IDC_CHECK_READONLY, m_readOnly); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CRulerRichEditCtrlDemoDlg, CDialog) 
	//{{AFX_MSG_MAP(CRulerRichEditCtrlDemoDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_WM_SIZE() 
	ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave) 
	ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad) 
	ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew) 
	ON_BN_CLICKED(IDC_CHECK_SHOW_RULER, OnCheckShowRuler) 
	ON_BN_CLICKED(IDC_CHECK_SHOW_TOOLBAR, OnCheckShowToolbar) 
	ON_BN_CLICKED(IDC_CHECK_READONLY, OnCheckReadonly) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CRulerRichEditCtrlDemoDlg message handlers 
 
BOOL CRulerRichEditCtrlDemoDlg::OnInitDialog() 
{ 
	m_showRuler = TRUE; 
	m_showToolbar = TRUE; 
 
	CDialog::OnInitDialog(); 
 
	// Add "About..." menu item to system menu. 
 
	// IDM_ABOUTBOX must be in the system command range. 
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 
	ASSERT(IDM_ABOUTBOX < 0xF000); 
 
	CMenu* pSysMenu = GetSystemMenu(FALSE); 
	if (pSysMenu != NULL) 
	{ 
		CString strAboutMenu; 
		strAboutMenu.LoadString(IDS_ABOUTBOX); 
		if (!strAboutMenu.IsEmpty()) 
		{ 
			pSysMenu->AppendMenu(MF_SEPARATOR); 
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 
		} 
	} 
 
	// 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 
	 
	CRect rect; 
	m_placement.GetWindowRect( rect ); 
	ScreenToClient( rect ); 
	m_rtf.Create( WS_TABSTOP | WS_CHILD | WS_VISIBLE, rect, this, 100, TRUE ); 
 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CRulerRichEditCtrlDemoDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
	if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
	{ 
		CAboutDlg dlgAbout; 
		dlgAbout.DoModal(); 
	} 
	else 
	{ 
		CDialog::OnSysCommand(nID, lParam); 
	} 
} 
 
// 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 CRulerRichEditCtrlDemoDlg::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 CRulerRichEditCtrlDemoDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CRulerRichEditCtrlDemoDlg::OnSize(UINT nType, int cx, int cy)  
{ 
 
	CDialog::OnSize(nType, cx, cy); 
	 
	// Move or resize controls 
	if( m_rtf.m_hWnd ) 
	{ 
		int margin = 4; 
		CRect rect; 
		m_ok.GetWindowRect( rect ); 
		ScreenToClient( rect ); 
		m_ok.SetWindowPos( NULL, rect.left, cy - ( rect.Height() + 4 ), 0, 0, SWP_NOZORDER | SWP_NOSIZE ); 
		 
		m_new.GetWindowRect( rect ); 
		ScreenToClient( rect ); 
		m_new.SetWindowPos( NULL, rect.left, cy - ( rect.Height() + 4 ), 0, 0, SWP_NOZORDER | SWP_NOSIZE ); 
 
		m_ruler.GetWindowRect( rect ); 
		ScreenToClient( rect ); 
		m_ruler.SetWindowPos( NULL, rect.left, cy - ( rect.Height() + 4 ), 0, 0, SWP_NOZORDER | SWP_NOSIZE ); 
 
		m_toolbar.GetWindowRect( rect ); 
		ScreenToClient( rect ); 
		m_toolbar.SetWindowPos( NULL, rect.left, cy - ( rect.Height() + 4 ), 0, 0, SWP_NOZORDER | SWP_NOSIZE ); 
 
		m_load.GetWindowRect( rect ); 
		ScreenToClient( rect ); 
		m_load.SetWindowPos( NULL, rect.left, cy - ( rect.Height() + 4 ), 0, 0, SWP_NOZORDER | SWP_NOSIZE ); 
 
		m_save.GetWindowRect( rect ); 
		ScreenToClient( rect ); 
		m_save.SetWindowPos( NULL, rect.left, cy - ( rect.Height() + 4 ), 0, 0, SWP_NOZORDER | SWP_NOSIZE ); 
 
		m_rtf.SetWindowPos( NULL, margin, margin, cx - margin * 2, cy - 8 - ( rect.Height() + 8 ), SWP_NOZORDER ); 
 
	} 
	 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CRulerRichEditCtrlDemoDlg button handlers 
 
void CRulerRichEditCtrlDemoDlg::OnButtonSave()  
{ 
 
	CString filename; 
	m_rtf.Save( filename ); 
	 
} 
 
void CRulerRichEditCtrlDemoDlg::OnButtonLoad()  
{ 
 
	CString filename; 
	m_rtf.Load( filename ); 
	 
} 
 
void CRulerRichEditCtrlDemoDlg::OnCancel()  
{ 
	CDialog::OnCancel(); 
} 
 
void CRulerRichEditCtrlDemoDlg::OnButtonNew()  
{ 
 
	m_rtf.GetRichEditCtrl().SetWindowText( _T( "" ) ); 
	 
} 
 
void CRulerRichEditCtrlDemoDlg::OnCheckShowRuler()  
{ 
 
	UpdateData(); 
	m_rtf.ShowRuler( m_showRuler ); 
 
} 
 
void CRulerRichEditCtrlDemoDlg::OnCheckShowToolbar()  
{ 
 
	UpdateData(); 
	m_rtf.ShowToolbar( m_showToolbar ); 
	 
} 
 
 
void CRulerRichEditCtrlDemoDlg::OnCheckReadonly()  
{ 
 
	UpdateData(); 
	m_rtf.SetReadOnly( m_readOnly )	; 
 
}