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

📄 childview.cpp

📁 可以在状态栏中随鼠标移动实时显示出设备坐标和逻辑坐标
💻 CPP
字号:
// ChildView.cpp : implementation of the CChildView class
//
#include "stdafx.h"
#include "color.h"
#include "ChildView.h"
#include "MainFrm.h"

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


//int MyGlobal;

/////////////////////////////////////////////////////////////////////////////
// CChildView

CChildView::CChildView()
	{
	m_ptMouse = CPoint(0,0);  // Initialize the m_ptMouse
	}

CChildView::~CChildView()
	{
	}


BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
//ON_WM_PAINT()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
	{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;
	
	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);
	
	return TRUE;
	}

/*void CChildView::OnPaint() 
	{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here

	// Demonstrate how to access the global variable.
	MyGlobal = 9999;

	CColorApp * pApp = (CColorApp *)AfxGetApp();
	pApp->MyGlobal = 8888;

	// Display some prompt text.往屏幕上写字
	dc.TextOut(20,20,"It demonstrates message relection of WM_CTLCOLOR. please see About Dialog ");
	dc.TextOut(20,40,"It demonstrates the path of GDI.");
	dc.TextOut(20,60,"It demonstrates how to add a global variable.");
	dc.TextOut(20,80,"It demonstrates the MAP_MODE of GDI, and displays the coordinate of mouse in status bar.");
	
	// I will draw a rectangle with a sin() edge.画特殊的四边形
	dc.BeginPath();
	CRect rectTemp(200,200,500,400);
	DrawSpecialRect(dc, rectTemp);
	dc.EndPath();

	CBrush MyBrush (RGB(255,0,255));
	CBrush * OldBrush = (CBrush *) dc.SelectObject(&MyBrush);
	dc.StrokeAndFillPath();
	dc.SelectObject(OldBrush);

	// I will draw a cross line of new coordinate.
	CRect rect;
	GetClientRect(rect);
	dc.MoveTo(0, rect.Height()/2);
	dc.LineTo(rect.Width(), rect.Height()/2);
	dc.MoveTo(rect.Width()/2, 0);
	dc.LineTo(rect.Width()/2, rect.Height());
	// Do not call CWnd::OnPaint() for painting messages
	}


void CChildView::DrawSpecialRect(CPaintDC &dc, CRect rect)
	{
	CPoint pt1, pt2, pt3, pt4;
	
	pt1 = rect.TopLeft();
	pt2 = pt1 + CSize(rect.Width(), 0);
	pt3 = rect.BottomRight();
	pt4 = pt1 + CSize(0, rect.Height());
		
	dc.MoveTo(pt1);
	DrawSinLine(dc, pt1, pt2);
	dc.LineTo(pt3);
	dc.LineTo(pt4);
	dc.LineTo(pt1);	
	}

void CChildView::DrawSinLine(CPaintDC &dc, CPoint pt1, CPoint pt2)
	{
	// Note: (pt1.y == pt2.y) && (pt2.x > pt1.x)
	// I will draw the line with 1000 points in two circle of sin();
	double step = double(pt2.x - pt1.x) / 1000;
	double x, y;

	for (x = 0; x <= 1000; x++)
		{
		y = sin(8*3.1415926*x/1000); // 1000 points adapts to 4*Pi
		dc.LineTo(pt1.x+ int(x*step),pt1.y-int(y*20));
		}
	}
*/
void CChildView::OnPrepareDC(CDC *pDC, CPrintInfo *pInfo)
	{/*
	CRect rect;

	// Set the MapMode to LOMETRIC (0.1mm),Right-Up direction.
	pDC->SetMapMode (MM_LOMETRIC);

	// Set the origin of logical coordinate to the center of client area.
	GetClientRect(rect);
	pDC->SetViewportOrg(rect.Width()/2, rect.Height()/2);
*/	}

void CChildView::OnMouseMove(UINT nFlags, CPoint point) 
	{
	// TODO: Add your message handler code here and/or call default
	CClientDC dc(this);
	CString str;
	
	OnPrepareDC(&dc);
	//To access CMainFrame, you need include file mainfrm.h
	CMainFrame * pFrame = (CMainFrame *) AfxGetApp()->m_pMainWnd;
	//To access m_wndStatusBar, you need public the member variable.
	CStatusBar * pStatus = (CStatusBar *) &pFrame->m_wndStatusBar;
	
	m_ptMouse = point;
	str.Format ("设备坐标 X=%i pixel, Y=%i pixel", m_ptMouse.x, m_ptMouse.y);
	pStatus->SetPaneText(1, str);
	
	dc.DPtoLP(&m_ptMouse);
	str.Format ("逻辑坐标 X=%i * 0.1mm, Y=%i * 0.1mm", m_ptMouse.x, m_ptMouse.y);
	pStatus->SetPaneText(2, str);
	
	//CWnd ::OnMouseMove(nFlags, point);
	}

⌨️ 快捷键说明

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