📄 blcview.cpp
字号:
// blcView.cpp : implementation of the CBlcView class
//
#include "stdafx.h"
#include "blc.h"
#include "MainFrm.h"
#include "blcDoc.h"
#include "blcView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBlcView
IMPLEMENT_DYNCREATE(CBlcView, CScrollView)
BEGIN_MESSAGE_MAP(CBlcView, CScrollView)
//{{AFX_MSG_MAP(CBlcView)
ON_COMMAND(ID_MAX, OnMax)
ON_COMMAND(ID_MIN, OnMin)
ON_COMMAND(ID_ALL, OnAll)
ON_WM_MOUSEMOVE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CBlcView construction/destruction
CBlcView::CBlcView()
{
// TODO: add construction code here
blc=1.0;
A0rect.left=0;
A0rect.top=0;
A0rect.right=914;
A0rect.bottom=1219;
m_CoorStr.Empty();
m_CoorPoint.x=0;
m_CoorPoint.y=0;
i=0;
j=0;
}
CBlcView::~CBlcView()
{
}
BOOL CBlcView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CBlcView drawing
void CBlcView::OnDraw(CDC* pDC)
{
CBlcDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
GetCurrentPen1();
CPen pen;
pen.CreatePen(i,j+1,RGB(128,0,128));
pDC->SelectObject(pen);
pDC->Rectangle((int)(A0rect.left*blc)+10,(int)(A0rect.top*blc)+10,
(int)(A0rect.right*blc)-10,(int)(A0rect.bottom*blc)-10);
pDC->MoveTo((int)(A0rect.left*blc)+10,(int)(A0rect.top*blc)+10);
pDC->LineTo((int)(A0rect.right*blc)-10,(int)(A0rect.bottom*blc)-10);
pDC->MoveTo((int)(A0rect.right*blc)-10,(int)(A0rect.top*blc)+10);
pDC->LineTo((int)(A0rect.left*blc)+10,(int)(A0rect.bottom*blc)-10);
}
void CBlcView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
m_WndStatusBar=(CStatusBar *)AfxGetApp()->GetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CSize sizeTotal;
m_CoorStr.Format("X坐标:%8d mmY坐标:%8d mm",m_CoorPoint.x,m_CoorPoint.y);
m_WndStatusBar->SetPaneText(1,m_CoorStr);
// TODO: calculate the total size of this view
sizeTotal.cx=A0rect.right; sizeTotal.cy=A0rect.bottom;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CBlcView printing
BOOL CBlcView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CBlcView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CBlcView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CBlcView diagnostics
#ifdef _DEBUG
void CBlcView::AssertValid() const
{
CScrollView::AssertValid();
}
void CBlcView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CBlcDoc* CBlcView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBlcDoc)));
return (CBlcDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBlcView message handlers
void CBlcView::OnMax()
{
// TODO: Add your command handler code here
CDC *dc=GetDC();
CRect clientrect;
CBrush brush(RGB(255,255,255));
dc->GetWindow()->GetClientRect(&clientrect);
dc->FillRect(&clientrect,&brush);
dc->SetWindowOrg(0,0);
dc->SetViewportOrg(0,0);
blc=1.2*blc;
OnDraw(dc);
ReleaseDC(dc);
}
void CBlcView::OnMin()
{
// TODO: Add your command handler code here
CDC *dc=GetDC();
CRect clientrect;
CBrush brush(RGB(255,255,255));
dc->GetWindow()->GetClientRect(&clientrect);
dc->FillRect(&clientrect,&brush);
dc->SetWindowOrg(0,0);
dc->SetViewportOrg(0,0);
blc=0.8*blc;
OnDraw(dc);
ReleaseDC(dc);
}
void CBlcView::OnAll()
{
// TODO: Add your command handler code here
double blc1;
CDC *dc=GetDC();
CRect clientrect;
CBrush brush(RGB(255,255,255));
dc->GetWindow()->GetClientRect(&clientrect);
dc->FillRect(&clientrect,&brush);
dc->SetWindowOrg(0,0);
dc->SetViewportOrg(0,0);
blc=914/(float)clientrect.right;
blc1=1219/(float)clientrect.bottom;
if(blc<blc1)
blc=blc1;
blc=1/blc;
char m_blc[8];
sprintf(m_blc,"%f",blc);
// AfxMessageBox(m_blc[8]);
OnDraw(dc);
ReleaseDC(dc);
}
void CBlcView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC *pDC=GetDC();
pDC->SetWindowOrg(0,0);
pDC->SetViewportOrg(0,0);
m_CoorPoint=point;
m_CoorStr.Format("X:%8d mm,Y:%8d mm",m_CoorPoint.x,m_CoorPoint.y);
m_WndStatusBar->SetPaneText(4,m_CoorStr);
ReleaseDC(pDC);
CScrollView::OnMouseMove(nFlags, point);
}
//DEL void CBlcView::GetCurrentPen()
//DEL {
//DEL CMainFrame * pMainFrm=(CMainFrame *)AfxGetApp()->GetMainWnd();
//DEL CComboBox *p_Com1=(CComboBox * )pMainFrm->m_wndDlgBar.GetDlgItem(IDC_COMBO1);
//DEL int i=p_Com1->GetCurSel();
//DEL CComboBox *p_Com2=(CComboBox *)pMainFrm->m_wndDlgBar.GetDlgItem(IDC_COMBO2);
//DEL int j=p_Com2->GetCurSel();
//DEL m_pen.CreatePen(2,2,RGB(0,0,0));
//DEL CDC *dc;
//DEL dc=GetDC();
//DEL dc->SelectObject(&m_pen);
//DEL }
CPen * CBlcView::GetCurrentPen1()
{
CMainFrame * pMainFrm=(CMainFrame *)AfxGetApp()->GetMainWnd();
CComboBox *p_Com1=(CComboBox * )pMainFrm->m_wndDlgBar.GetDlgItem(IDC_COMBO1);
i=p_Com1->GetCurSel();
CComboBox *p_Com2=(CComboBox *)pMainFrm->m_wndDlgBar.GetDlgItem(IDC_COMBO2);
j=p_Com2->GetCurSel();
CPen mypen;
CPen * pen;
pen=&mypen;
mypen.CreatePen(i+1,j+1,RGB(128,0,128));
// CDC *dc;
// dc=GetDC();
// dc->SelectObject(&m_pen);
// dc->MoveTo(0,0);
// dc->LineTo(400,400);
// CString string;
// string.Format("%d %d",i+1,j+1);
// dc->TextOut(100,100,string);
return pen;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -