📄 rj030413view.cpp
字号:
// RJ030413View.cpp : implementation of the CRJ030413View class
//
#include "stdafx.h"
#include "RJ030413.h"
#include "RJ030413Doc.h"
#include "RJ030413View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//.......................................................................
#include"ComctlDlg.h"
/////////////////////////////////////////////////////////////////////////////
// CRJ030413View
IMPLEMENT_DYNCREATE(CRJ030413View, CView)
BEGIN_MESSAGE_MAP(CRJ030413View, CView)
//{{AFX_MSG_MAP(CRJ030413View)
ON_COMMAND(ID_MENU_FORE, OnMenuFore)
ON_COMMAND(ID_MENU_FONT, OnMenuFont)
ON_COMMAND(ID_MENU_BACK, OnMenuBack)
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_TEST_COMCTL, OnTestComctl)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
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()
/////////////////////////////////////////////////////////////////////////////
// CRJ030413View construction/destruction
CRJ030413View::CRJ030413View()
{
// TODO: add construction code here
/////////////////////////////////////////////////////////////////////////////
m_ForeColor=0;
m_BackColor=0xFFFFFF;
m_Font.CreateStockObject(SYSTEM_FONT);
m_bDragging=false;
m_hCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);
/////////////////////////////////////////////////////////////////////////////////
}
CRJ030413View::~CRJ030413View()
{
}
BOOL CRJ030413View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CRJ030413View drawing
void CRJ030413View::OnDraw(CDC* pDC)
{
CRJ030413Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//............................................................................
//CComDlgDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
int x,y;
TEXTMETRIC tm;
CFont *PoldFont;
PoldFont=pDC->SelectObject(&m_Font);
pDC->SetTextColor(m_ForeColor);
pDC->SetBkColor(m_BackColor);
x=80,y=80;
pDC->TextOut(x,y,"欢迎光临!");
pDC->GetTextMetrics(&tm);
y=y+tm.tmHeight+tm.tmExternalLeading;
pDC->TextOut(x,y,"2005.6!");
pDC->SelectObject(PoldFont);
////..................................................................................
for(int i=0;i<pDoc->m_nCoins;i++)
{
int y=400-10*i;
pDC->Ellipse(400,y,500,y-30);
pDC->Ellipse(400,y-10,500,y-35);
}
//..........................................................................
CString strCoins;
CStatusBar * pStatus=(CStatusBar *)AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR);
if(pStatus)
{
strCoins.Format("硬币:%d",pDoc->m_nCoins);
pStatus->SetPaneText(1,strCoins);
}
//...............................................................................
int nIndex=pDoc->GetNumLines();
TRACE("nIndex1=%d\n",nIndex);
while(nIndex--)
{
TRACE("nIndex2=%d\n",nIndex);
pDoc->GetLine(nIndex)->DrawLine(pDC);
}
//.......................................................................
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
CBitmap Bitmap;
Bitmap.LoadBitmap(IDB_MYBITMAP);
CBitmap *pOldBitmap=MemDC.SelectObject(&Bitmap);
BITMAP bm;
Bitmap.GetObject(sizeof(BITMAP),&bm);
pDC->BitBlt(320,80,bm.bmWidth,bm.bmHeight,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBitmap);
//.......................................................................
}
/////////////////////////////////////////////////////////////////////////////
// CRJ030413View printing
BOOL CRJ030413View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CRJ030413View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CRJ030413View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CRJ030413View diagnostics
#ifdef _DEBUG
void CRJ030413View::AssertValid() const
{
CView::AssertValid();
}
void CRJ030413View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CRJ030413Doc* CRJ030413View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRJ030413Doc)));
return (CRJ030413Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRJ030413View message handlers
void CRJ030413View::OnMenuFore()
{
// TODO: Add your command handler code here
CColorDialog dlg;
if(dlg.DoModal()==IDOK)
{
m_ForeColor=dlg.GetColor();
Invalidate();
}
}
void CRJ030413View::OnMenuFont()
{
// TODO: Add your command handler code here
CFontDialog dlg;
if(dlg.DoModal()==IDOK)
{
LOGFONT LF;
dlg.GetCurrentFont(&LF);
m_ForeColor=dlg.GetColor();
m_Font.DeleteObject();
m_Font.CreateFontIndirect(&LF);
Invalidate();
}
}
void CRJ030413View::OnMenuBack()
{
// TODO: Add your command handler code here
CColorDialog dlg;
if(dlg.DoModal()==IDOK)
{
m_BackColor=dlg.GetColor();
Invalidate();
}
}
void CRJ030413View::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
//................................................................
CMenu menuPopup;
if(menuPopup.CreatePopupMenu())
{
menuPopup.AppendMenu(MF_STRING,ID_COIN_ADD,"增加硬币\tCtrl+A");
menuPopup.AppendMenu(MF_STRING,ID_COIN_SUB,"减少硬币\tCtrl+B");
menuPopup.AppendMenu(MF_STRING,ID_TEST_COMCTL,"画圆");
menuPopup.AppendMenu(MF_STRING,ID_MENU_FONT,"字体");
menuPopup.TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
}
//..................................................................
}
void CRJ030413View::OnTestComctl()
{
// TODO: Add your command handler code here
//。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
CComctlDlg dlg;
if(dlg.DoModal()!=IDOK)
return;
Invalidate();
UpdateWindow();
CClientDC dc(this);
CPen penNew,*ppenOld;
penNew.CreatePen(PS_SOLID,dlg.m_nLineWt,RGB(225,20,50));
ppenOld=dc.SelectObject(&penNew);
dc.Ellipse(500,200,500+2*dlg.m_nRadius,200+2*dlg.m_nRadius);//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
dc.SelectObject(ppenOld);
//..............................................................................
}
void CRJ030413View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//.........................................................................
SetCapture();
::SetCursor(m_hCross);
m_ptOrigin=point;
m_bDragging=TRUE;
//.........................................
CView::OnLButtonDown(nFlags, point);
}
void CRJ030413View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//........................................................................
if(m_bDragging)
{
m_bDragging=false;
ReleaseCapture();
}
//.................................................................
CView::OnLButtonUp(nFlags, point);
}
void CRJ030413View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//......................................................................
if(m_bDragging)
{
CRJ030413Doc *pDoc=GetDocument();
ASSERT_VALID(pDoc);
pDoc->AddLine(m_ptOrigin,point);
CClientDC dc(this);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
m_ptOrigin=point;
}
//.....................................................................
CView::OnMouseMove(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -