⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alignmodeview.cpp

📁 对齐的 bnnbc nccb
💻 CPP
字号:
// AlignModeView.cpp : implementation of the CAlignModeView class
//

#include "stdafx.h"
#include "AlignMode.h"
#include "TestDlg.h"
#include "AlignModeDoc.h"
#include "AlignModeView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAlignModeView

IMPLEMENT_DYNCREATE(CAlignModeView, CView)

BEGIN_MESSAGE_MAP(CAlignModeView, CView)
	//{{AFX_MSG_MAP(CAlignModeView)
	ON_COMMAND(ID_MODE_LEFT, OnModeLeft)
	ON_COMMAND(ID_MODE_RIGHT, OnModeRight)
	ON_COMMAND(ID_MODE_CENTER, OnModeCenter)
	ON_UPDATE_COMMAND_UI(ID_MODE_LEFT, OnUpdateModeLeft)
	ON_UPDATE_COMMAND_UI(ID_MODE_CENTER, OnUpdateModeCenter)
	ON_UPDATE_COMMAND_UI(ID_MODE_RIGHT, OnUpdateModeRight)
	ON_COMMAND(IDM_DLG_IP, OnDlgIp)
	//}}AFX_MSG_MAP
	ON_COMMAND_RANGE(ID_MODE_TOP,ID_MODE_BOTTOM,OnSelVerAlignMode)
    ON_UPDATE_COMMAND_UI_RANGE(ID_MODE_TOP,ID_MODE_BOTTOM,OnUpdateSelVerAlignMode)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAlignModeView construction/destruction

CAlignModeView::CAlignModeView()
{
	// TODO: add construction code here
	//初始化标志变量
	m_bLeft=TRUE;
	m_bCenter=FALSE;
	m_bRight=FALSE;
	//初始化成员变量
	m_nVerIndex=0;
}

CAlignModeView::~CAlignModeView()
{
}

BOOL CAlignModeView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CAlignModeView drawing


void CAlignModeView::OnDraw(CDC* pDC)
{
	CAlignModeDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	//获取窗口客户区矩形
	CRect rcClient;
	GetClientRect(&rcClient);

	//计算窗口客户区的中点
	int xCenter,yCenter;
	xCenter=(rcClient.left+rcClient.right)/2;
	yCenter=(rcClient.top+rcClient.bottom)/2;

	//确定水平对齐方式
	UINT nHorMode;
	if (m_bLeft)
		nHorMode=TA_LEFT;
	if (m_bCenter)
		nHorMode=TA_CENTER;
	if (m_bRight)
		nHorMode=TA_RIGHT;

	//确定垂直对齐方式
	UINT nVerMode;
	switch (m_nVerIndex)
	{
	case 0:
		nVerMode=TA_TOP;
		break;
	case 1:
		nVerMode=TA_BASELINE;
		break;
	case 2:
		nVerMode=TA_BOTTOM;
		break;
	}

	//设置输出字符串的对齐方式
	pDC->SetTextAlign(nHorMode|nVerMode);

	//显示特定的字符串
	pDC->TextOut(xCenter,yCenter,"Align Text with the Cross");

	//画“十”字基准符号
	pDC->MoveTo(xCenter,yCenter-20);
	pDC->LineTo(xCenter,yCenter+20);
	pDC->MoveTo(xCenter-50,yCenter);
	pDC->LineTo(xCenter+50,yCenter);
}

/////////////////////////////////////////////////////////////////////////////
// CAlignModeView printing

BOOL CAlignModeView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CAlignModeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CAlignModeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CAlignModeView diagnostics

#ifdef _DEBUG
void CAlignModeView::AssertValid() const
{
	CView::AssertValid();
}

void CAlignModeView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CAlignModeDoc* CAlignModeView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAlignModeDoc)));
	return (CAlignModeDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CAlignModeView message handlers



void CAlignModeView::OnModeLeft() 
{
	// TODO: Add your command handler code here
	//设置标志变量
	m_bLeft=TRUE;
	m_bCenter=FALSE;
	m_bRight=FALSE;
	//无效化窗口,引起重画
	Invalidate();
}

void CAlignModeView::OnModeRight() 
{
	// TODO: Add your command handler code here
	//设置标志变量
	m_bLeft=FALSE;
	m_bCenter=FALSE;
	m_bRight=TRUE;
	//无效化窗口,引起重画
	Invalidate();
}

//DEL void CAlignModeView::OnModeTop() 
//DEL {
//DEL 	// TODO: Add your command handler code here
//DEL }

void CAlignModeView::OnModeCenter() 
{
	// TODO: Add your command handler code here
	//设置标志变量
	m_bLeft=FALSE;
	m_bCenter=TRUE;
	m_bRight=FALSE;
	//无效化窗口,引起重画
	Invalidate();
}

//DEL void CAlignModeView::OnModeBotton() 
//DEL {
//DEL 	// TODO: Add your command handler code here
//DEL 	
//DEL }

//DEL void CAlignModeView::OnModeBaseline() 
//DEL {
//DEL 	// TODO: Add your command handler code here
//DEL 	
//DEL }

void CAlignModeView::OnSelVerAlignMode(UINT nID)
{
	//根据用户选择的菜单项确定m_nVerIndex的取值
	m_nVerIndex=nID-ID_MODE_TOP;
	//无效化窗口,引起重画
	Invalidate();
}

void CAlignModeView::OnUpdateModeLeft(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	//设置或取消核选标记
	pCmdUI->SetCheck(m_bLeft);
}

void CAlignModeView::OnUpdateModeCenter(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
    //设置或取消核选标记
	pCmdUI->SetCheck(m_bCenter);
}

void CAlignModeView::OnUpdateModeRight(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	//设置或取消核选标记
	pCmdUI->SetCheck(m_bRight);
}

void CAlignModeView::OnUpdateSelVerAlignMode(CCmdUI* pCmdUI)
{
	//设置或取消核选标记
	pCmdUI->SetCheck(pCmdUI->m_nID==(ID_MODE_TOP+m_nVerIndex));
}

void CAlignModeView::OnDlgIp() 
{
	// TODO: Add your command handler code here
	CTestDlg dlg;
	dlg.DoModal();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -