📄 direction2view.cpp
字号:
// direction2View.cpp : implementation of the CDirection2View class
//
#include "StdAfx.h"
#include "direction2.h"
#include "TsFont.h"
#include "direction2Doc.h"
#include "direction2View.h"
#include "Word.h"
#include <afxwin.h>
#include <windows.h>
#include <stdlib.h>
#include "str.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MAXSIDE 200
/////////////////////////////////////////////////////////////////////////////
// CDirection2View
IMPLEMENT_DYNCREATE(CDirection2View, CScrollView)
BEGIN_MESSAGE_MAP(CDirection2View, CScrollView)
//{{AFX_MSG_MAP(CDirection2View)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_CHUSHIHUA, OnChushihua)
ON_COMMAND(ID_COLORPEN, OnColorpen)
ON_COMMAND(ID_COLORFILL, OnColorfill)
ON_COMMAND(ID_PENSTYLE, OnPenstyle)
ON_COMMAND(ID_RECTHW, OnRecthw)
ON_UPDATE_COMMAND_UI(ID_RECTHW, OnUpdateRecthw)
ON_MESSAGE(WM_CHANG_PEN,Setpenstyle)
ON_MESSAGE(WM_RECT_CHANGE,Setrectwh)
ON_WM_LBUTTONDBLCLK()
ON_WM_KEYDOWN()
ON_COMMAND(ID_SHUXING, OnShuxing)
ON_MESSAGE(WM_CHANGE_RECTSHX,Onrectchange)
ON_MESSAGE(WM_CHANGE_LINE,Onlinechange)
ON_MESSAGE(WM_TEXT_CHANGE,WriteText)
ON_COMMAND(ID_LOOK, OnLook)
ON_COMMAND(ID_SHANCHU112, OnShanchu112)
ON_COMMAND(ID_FANHUI, OnFanhui)
ON_COMMAND(ID_SETBEDIN, OnSetbedin)
ON_COMMAND(ID_SETLAST, OnSetlast)
ON_UPDATE_COMMAND_UI(ID_PENSTYLE, OnUpdatePenstyle)
ON_COMMAND(ID_BEGIN22, OnBegin22)
ON_UPDATE_COMMAND_UI(ID_BEGIN22, OnUpdateBegin22)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDirection2View construction/destruction
CDirection2View::CDirection2View()
{
// TODO: add construction code here
m_text.lfHeight = 17;
m_text.lfWidth = 0;
m_text.lfEscapement=0;
m_text.lfOrientation =0;
m_text.lfWeight = FW_NORMAL;
m_text.lfItalic = FALSE;
m_text.lfUnderline = FALSE;
m_text.lfStrikeOut = FALSE;
m_text.lfCharSet= GB2312_CHARSET;
m_text.lfOutPrecision = OUT_STROKE_PRECIS;
m_text.lfClipPrecision = CLIP_STROKE_PRECIS;
m_text.lfQuality = DRAFT_QUALITY;
m_text.lfPitchAndFamily = VARIABLE_PITCH|FF_MODERN;
strcpy(m_text.lfFaceName,"仿宋_GB2312" );
m_cTextColor=RGB(0,0,0); //黑色
m_FillColor = RGB(0,0,0);//填充颜色
m_PenColor = RGB(0,0,0);//画笔颜色
m_CurrentLineStyle = PS_DOT; // 直线式样
m_CurrentPenThickness = 1; //画笔宽度 直线的宽度
recrwidth=10;
rectchang=10;
selectindex=-1; //开始默认为第一个被选中
m_Dragging=0; //鼠标左键是否按下
m_IsRect=FALSE; //是否绘制Focus矩形
m_hArrow = AfxGetApp()->LoadStandardCursor(IDC_ARROW); //箭头光标
m_hCross = AfxGetApp()->LoadStandardCursor(IDC_CROSS); //十字光标
m_PenDotted.CreatePen(PS_SOLID,1,RGB(0,0,0)); //画笔
lindex1=-1;
lindex2=-1;
index=-1;
type=-1;
m_begin=-1; //最短路径的起点
m_last=-1;
}
CDirection2View::~CDirection2View()
{
}
void CDirection2View::Onrectchange(WPARAM wParam ,LPARAM lParam)
{
//收到矩形改变时,应该更新矩形的属性,
CRectFill *rectfill;
CDirection2Doc* pDoc = GetDocument();
selectindex =(int)lParam;
rectfill = (CRectFill *)pDoc->GetDraw(selectindex);
rectfill->m_height = m_rectset->m_high;
rectfill->m_width =m_rectset->m_width;
rectfill->m_name =m_rectset->m_name;
rectfill->m_rectfillcolor=m_rectset->m_incolor;
rectfill->m_rectcolor =m_rectset->m_sidecolor;
rectfill->m_color =m_rectset->m_textcolor;
rectfill->m_text =m_rectset->m_text;
rectfill->SetZhi(m_rectset->m_zhi);
//判断是否已经设计为起点 或 是终点
if((m_rectset->m_begin).GetCheck())
m_begin=selectindex;
else if((m_rectset->m_over).GetCheck())
m_last=selectindex;
//并更新矩形的显示
CClientDC ClientDC(this);
OnPrepareDC(&ClientDC);
ClientDC.SelectObject(&m_PenDotted);
ClientDC.SetROP2(R2_NOT);
ClientDC.SetBkMode(TRANSPARENT);
ClientDC.SelectStockObject(NULL_BRUSH);
ClientDC.SetROP2(R2_COPYPEN);
this->Invalidate();
OnDraw(&ClientDC);
}
void CDirection2View::Onlinechange(WPARAM wParam ,LPARAM lParam)
{
//收到直线改变时,应该更新直线的属性,
CLine *line;
CDirection2Doc* pDoc = GetDocument();
selectindex =(int)lParam;
line = (CLine *)pDoc->GetDraw(selectindex);
line->linewidth =m_lineset->m_linewidth;
line->m_name =m_lineset->m_name;
line->m_linecolor=m_lineset->m_linecolor;
line->m_linestyle =(m_lineset->m_linestyle).GetCurSel();
line->m_color =m_lineset->m_textcolor;
line->m_text =m_lineset->m_text;
line->SetZhi(m_lineset->m_zhi);
//并更新直线的显示
CClientDC ClientDC(this);
OnPrepareDC(&ClientDC);
ClientDC.SelectObject(&m_PenDotted);
ClientDC.SetROP2(R2_NOT);
ClientDC.SetBkMode(TRANSPARENT);
ClientDC.SelectStockObject(NULL_BRUSH);
ClientDC.SetROP2(R2_COPYPEN);
this->Invalidate();
OnDraw(&ClientDC);
}
BOOL CDirection2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
m_ClassName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,0,
(HBRUSH) :: GetStockObject(WHITE_BRUSH),0);
cs.lpszClass = m_ClassName;
return CScrollView::PreCreateWindow(cs);
}
void CDirection2View::OnDraw(CDC* pDC)
{
CDirection2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//得到视图窗口的
CSize ScrollSize = GetTotalSize();
//在视图窗口显示绘图区域
pDC->MoveTo(ScrollSize.cx,0);
pDC->LineTo(ScrollSize.cx,ScrollSize.cy);
pDC->LineTo(0,ScrollSize.cy);
CRect ClipRect;
CRect DimRect;
CRect IntRect;
CBasepic *pDraw;
pDC->GetClipBox(&ClipRect);
int NumDraws = pDoc->GetDrawnum();
for(int Index = 0; Index < NumDraws;++Index)
{
pDraw = (CBasepic *)pDoc->GetDraw(Index);
DimRect = pDraw->GetDimRect();
// if(IntRect.IntersectRect(DimRect,ClipRect)) //判断当前矩形是否在此矩形内
pDraw->Draw(pDC);
}
}
void CDirection2View::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CDirection2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// include afxwin.h 这个文件的.
//GetWindowRect(&rcWin);
// rcWin.Wdith();
// rcWin.Heigth();
//CClientDC dc(this); //创建的图形DC
// int width = dc.GetDeviceCaps(HORZRES);//获取屏幕宽度
// int height = dc.GetDeviceCaps(VERTRES);//获取屏幕高度
CRect rcWin; //获取窗口矩形域
GetWindowRect( &rcWin ); //rect是gameFrame的公有成员,CRect类型,获取窗口大小
HDC screenDC;
screenDC = CreateDC("DISPLAY", NULL, NULL, NULL);
int nLogDPIX = GetDeviceCaps(screenDC, HORZRES);
int nLogDPIY = GetDeviceCaps(screenDC, VERTRES);
DeleteDC(screenDC);
CSize sizeTotal;
sizeTotal.cx = nLogDPIX;
sizeTotal.cy = nLogDPIY;
SetScrollSizes(MM_TEXT, sizeTotal);
m_huitu=new CZUOTU(this);//创建初始化的设计窗口
if(m_huitu !=NULL)
{
m_huitu->Create(IDD_HUITU,this);
//显示对话框
m_huitu->Setinfo(m_CurrentPenThickness,m_CurrentLineStyle);
// m_huitu->ShowWindow(SW_SHOW);
}
else
MessageBox("创建窗口对象失败","错误",MB_OK);
m_rect=new CRECTHW(this);//创建初始化的设计窗口
if(m_huitu !=NULL)
{
m_rect->Create(IDD_RECTHW,this);
//显示对话框
m_rect->Setinfo(recrwidth,rectchang);
//m_rect->ShowWindow(SW_SHOW);
}
else
MessageBox("创建窗口对象失败","错误",MB_OK);
// CRectSet *m_rectset;
// cTextSet *m_textset;
m_rectset=new CRectSet(this);//创建初始化的设计窗口
if(m_rectset !=NULL)
m_rectset->Create(IDD_RECT,this);
else
MessageBox("创建窗口对象失败","错误",MB_OK);
m_lineset=new CLineSet(this);//创建初始化的设计窗口
if(m_lineset !=NULL)
m_lineset->Create(IDD_LINE,this);
else
MessageBox("创建窗口对象失败","错误",MB_OK);
m_textset=new CWord(this);//创建初始化的设计窗口
if(m_textset !=NULL)
m_textset->Create(IDD_DIALOG1,this);
else
MessageBox("创建窗口对象失败","错误",MB_OK);
}
/////////////////////////////////////////////////////////////////////////////
// CDirection2View printing
BOOL CDirection2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDirection2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDirection2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDirection2View diagnostics
#ifdef _DEBUG
void CDirection2View::AssertValid() const
{
CScrollView::AssertValid();
}
void CDirection2View::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CDirection2Doc* CDirection2View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDirection2Doc)));
return (CDirection2Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDirection2View message handlers
void CDirection2View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC ClientDC(this); //定义一个DC对象
OnPrepareDC(&ClientDC);
CDirection2App *pApp = (CDirection2App *)AfxGetApp();
if(m_IsRect)
{
CDC *pDC = GetDC();
CRect rect(m_PointOrigin.x,m_PointOrigin.y,m_PointOld.x,m_PointOld.y);
rect.NormalizeRect();
pDC->DrawFocusRect(rect);
ReleaseDC(pDC);
m_IsRect = FALSE;
}
if(pApp->m_CurrentTool==ID_DRAW_SELECT)
ClientDC.DPtoLP(&point); //转化逻辑坐标
CSize ScrollSize = GetTotalSize();
CRect ScrollRect(0,0,ScrollSize.cx,ScrollSize.cy);
if(!ScrollRect.PtInRect(point)) return; //判断鼠标是否在绘图区域内
CDirection2Doc *pDoc = GetDocument();
CBasepic *pDraw;
CRect rect;
/////////////////////////////////////////////////
//在此要实现 判断点中的是否在矩形里 而且是在 SELECT 或 LINE 直线 的情况下
if(pApp->m_CurrentTool ==ID_DRAW_SELECT)
{ int i;
int num = pDoc->GetDrawnum();
for( i=num;i>0;i--)
{
pDraw = pDoc->GetDraw(i-1);
rect = pDraw ->GetDimRect();
if(rect.PtInRect(point))
{ index=i-1;
selectindex=index; //所选择的对象的索引
pDraw -> Setselete(true); /// 缺点为当对象重合时会选择多个对象
break;
}
else
pDraw ->Setselete(false);
}
if(i>1)
{
for(int j=i-2;j>=0;j--)
{pDraw = pDoc->GetDraw(j);
pDraw -> Setselete(false);
}
}
if(i==0)
selectindex=-1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -