www.gusucode.com > 一些VC++窗体菜单的操作源码-源码程序 > 一些VC++窗体菜单的操作源码-源码程序\code\如何获得光标的坐标\Demo\DemoView.cpp
//Download by http://www.NewXing.com // DemoView.cpp : implementation of the CDemoView class // #include "stdafx.h" #include "Demo.h" #include "DemoDoc.h" #include "DemoView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDemoView IMPLEMENT_DYNCREATE(CDemoView, CView) BEGIN_MESSAGE_MAP(CDemoView, CView) //{{AFX_MSG_MAP(CDemoView) ON_WM_MOUSEMOVE() //}}AFX_MSG_MAP // 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() ///////////////////////////////////////////////////////////////////////////// // CDemoView construction/destruction CDemoView::CDemoView() { // TODO: add construction code here } CDemoView::~CDemoView() { } BOOL CDemoView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CDemoView drawing void CDemoView::OnDraw(CDC* pDC) { //获得客户区坐标 CRect rect; GetClientRect(rect); //绘制十字光标 pDC->MoveTo(0, m_Point.y); pDC->LineTo(rect.Width(), m_Point.y); pDC->MoveTo(m_Point.x, 0); pDC->LineTo(m_Point.x, rect.Height()); //输出光标坐标 CString strText =_T(""); strText.Format(_T("%d, %d"), m_Point.x, m_Point.y); pDC->SetBkMode(TRANSPARENT); pDC->SetTextAlign(TA_RIGHT | TA_BOTTOM); pDC->TextOut(m_Point.x, m_Point.y, strText); } ///////////////////////////////////////////////////////////////////////////// // CDemoView printing BOOL CDemoView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CDemoView diagnostics #ifdef _DEBUG void CDemoView::AssertValid() const { CView::AssertValid(); } void CDemoView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CDemoDoc* CDemoView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemoDoc))); return (CDemoDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CDemoView message handlers void CDemoView::OnMouseMove(UINT nFlags, CPoint point) { //保存光标坐标 m_Point = point; //刷新客户区 Invalidate(); CView::OnMouseMove(nFlags, point); }