// MiniDrawView.cpp : CMiniDrawView 类的实现
//
#include "stdafx.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MiniDraw.h"
#endif
#include "MiniDrawDoc.h"
#include "MiniDrawView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMiniDrawView
IMPLEMENT_DYNCREATE(CMiniDrawView, CView)
BEGIN_MESSAGE_MAP(CMiniDrawView, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CMiniDrawView::OnFilePrintPreview)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
// CMiniDrawView 构造/析构
CMiniDrawView::CMiniDrawView()
{
// TODO: 在此处添加构造代码
m_Dragging=0;
m_HCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);
}
CMiniDrawView::~CMiniDrawView()
{
}
BOOL CMiniDrawView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
m_ClassName = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, 0, (HBRUSH)::GetStockObject-j ect(WHITE_BRUSH), 0);
cs.lpszClass=m_ClassName;
return CView::PreCreateWindow(cs);
}
// CMiniDrawView 绘制
void CMiniDrawView::OnDraw(CDC* /*pDC*/)
{
CMiniDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
}
// CMiniDrawView 打印
void CMiniDrawView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CMiniDrawView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CMiniDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void CMiniDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清理过程
}
void CMiniDrawView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void CMiniDrawView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CMiniDrawView 诊断
#ifdef _DEBUG
void CMiniDrawView::AssertValid() const
{
CView::AssertValid();
}
void CMiniDrawView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMiniDrawDoc* CMiniDrawView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMiniDrawDoc)));
return (CMiniDrawDoc*)m_pDocument;
}
#endif //_DEBUG
// CMiniDrawView 消息处理程序
void CMiniDrawView::OnLButtonDown(UINT nFlags,CPoint point)
{
//TODO:Add your message handler code here and/or call
//defalt
m_PointOrigin = point;
m_PointOld = point;
SetCapture();
m_Dragging = 1;
RECT Rect;
GetClientRect(&Rect);
ClientToScreen(&Rect);
::ClipCursor(&Rect);
CView::OnLButtonDown(nFlags,point);
}
void CMiniDrawView::OnMouseMove(UINT nFlags,CPoint point)
{
//TODO:Add your message handler code here and/or call
//default
::SetCursor(m_HCross);
if(m_Dragging)
{
CClientDC ClientDC(this);
ClientDC.SetROP2(R2_NOT);
ClientDC.MoveTo(m_PointOrigin);
ClientDC.LineTo(m_PointOld);
ClientDC.MoveTo(m_PointOrigin);
ClientDC.LineTo(point);
m_PointOld=point;
}
CView::OnMouseMove(nFlags,point);
}
void CMiniDrawView::OnLButtonUp(UINT nFlags,CPoint point)
{
//TODO:Add your message handler code here and/or call default
if(m_Dragging)
{
m_Dragging=0;
::ReleaseCapture();
::ClipCursor(NULL);
CClientDC ClientDC(this);
ClientDC.SetROP2(R2_NOT);
ClientDC.MoveTo(m_PointOrigin);
ClientDC.LineTo(m_PointOld);
ClientDC.SetROP2(R2_COPYPEN);
ClientDC.MoveTo(m_PointOrigin);
ClientDC.LineTo(point);
}
CView::OnLButtonUp(nFlags,point);
}
错误在这一句:m_ClassName = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, 0, (HBRUSH)::GetStockObject-j ect(WHITE_BRUSH), 0);
报错:1>c:\users\john\documents\visual studio 2012\projects\minidraw\minidraw\minidrawview.cpp(53): error C2065: “j”: 未声明的标识符
1>c:\users\john\documents\visual studio 2012\projects\minidraw\minidraw\minidrawview.cpp(53): error C2146: 语法错误: 缺少“)”(在标识符“ect”的前面)
1>c:\users\john\documents\visual studio 2012\projects\minidraw\minidraw\minidrawview.cpp(53): error C2059: 语法错误:“)”
鼠标放在“j”上提示“未定义标识符“j”” 鼠标放在“ect”上提示应输入“)”
4 个解决方案
#1
-j ect这里多了个空格?
#2
书上有空格啊,去掉空格是未定义标识符“ject”
#3
GetStockObject-j ect 改为 GetStockObject
怀疑是印刷错误或者是到了一行的末端,一个单词占正好被隔断中间加了连接符-
怀疑是印刷错误或者是到了一行的末端,一个单词占正好被隔断中间加了连接符-
#4
我去,这也行。。。
#1
-j ect这里多了个空格?
#2
书上有空格啊,去掉空格是未定义标识符“ject”
#3
GetStockObject-j ect 改为 GetStockObject
怀疑是印刷错误或者是到了一行的末端,一个单词占正好被隔断中间加了连接符-
怀疑是印刷错误或者是到了一行的末端,一个单词占正好被隔断中间加了连接符-
#4
我去,这也行。。。