www.gusucode.com > VC++编写的SQL服务端和客户端源码程序 > VC++编写的SQL服务端和客户端源码程序\code\Server\HelpView.cpp

    //Download by http://www.NewXing.com
// HelpView.cpp : implementation file
//

#include "stdafx.h"
#include "miniSQL.h"
#include "HelpView.h"
#include "HelpDoc.h"
#include "User.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CMiniSQLApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CHelpView

IMPLEMENT_DYNCREATE(CHelpView, CEditView)

CHelpView::CHelpView()
{
	m_bReadOnly = TRUE;
	pFont = new CFont();
}

CHelpView::~CHelpView()
{
	if( pFont )
	{
		pFont->DeleteObject();
		delete pFont;
	}
}


BEGIN_MESSAGE_MAP(CHelpView, CEditView)
	//{{AFX_MSG_MAP(CHelpView)
	ON_COMMAND(ID_EDIT_SET, OnEditSet)
	ON_UPDATE_COMMAND_UI(ID_EDIT_SET, OnUpdateEditSet)
	ON_COMMAND(ID_CHANGE_FONT1, OnChangeFont1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHelpView drawing

void CHelpView::OnDraw(CDC* pDC)
{
	CHelpDoc* pDoc = ( CHelpDoc* )GetDocument();
	ASSERT_VALID( pDoc );
}

/////////////////////////////////////////////////////////////////////////////
// CHelpView diagnostics

#ifdef _DEBUG
void CHelpView::AssertValid() const
{
	CEditView::AssertValid();
}

void CHelpView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CHelpView message handlers

BOOL CHelpView::PreCreateWindow(CREATESTRUCT& cs) 
{
	cs.style |= ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE |
				WS_HSCROLL | WS_VSCROLL;

	return CEditView::PreCreateWindow( cs );
}

void CHelpView::OnInitialUpdate() 
{
	CEditView::OnInitialUpdate();

	CFont font;
	font.CreateFont( -17, 0, 0, 0, 400,
		0, 0, 0, 134, 3, 2, 1, 49,
		"宋体" );

	GetEditCtrl().SetFont( &font );
	Invalidate( FALSE );
	
	SetReadOnly( m_bReadOnly );
}

BOOL CHelpView::SetReadOnly( BOOL bReadOnly )
{
	CEdit& theEdit = GetEditCtrl();
	BOOL result = theEdit.SetReadOnly( bReadOnly );
	m_bReadOnly = !bReadOnly;
	return result;
}

void CHelpView::OnEditSet() 
{
	if( theApp.m_LogType != LOG_ADMIN )
	{
		AfxMessageBox( "只有管理员才可设定这一项!" );
		return ;
	}
	SetReadOnly( m_bReadOnly );
}

void CHelpView::OnUpdateEditSet(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( theApp.m_LogType & LOG_ADMIN );
	pCmdUI->SetCheck( !m_bReadOnly );
}

void CHelpView::OnChangeFont1() 
{
	LOGFONT lf;
	ZeroMemory( &lf, sizeof( lf ) );
	CFontDialog fDlg( &lf );

	if( fDlg.DoModal() == IDOK )
	{
		pFont->DeleteObject();
		pFont->CreateFontIndirect( &lf );
		GetEditCtrl().SetFont( pFont );
		Invalidate( FALSE );
	}
}