?? 1view.cpp
字號(hào):
// 1View.cpp : implementation of the CMy1View class
//
#include "stdafx.h"
#include "1.h"
#include "1Doc.h"
#include "1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy1View
IMPLEMENT_DYNCREATE(CMy1View, CView)
BEGIN_MESSAGE_MAP(CMy1View, CView)
//{{AFX_MSG_MAP(CMy1View)
ON_WM_CREATE()
ON_WM_CHAR()
ON_WM_LBUTTONDOWN()
ON_COMMAND(IDM_FONT, OnFont)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMy1View construction/destruction
CMy1View::CMy1View()
{
// TODO: add construction code here
m_write="";
m_origin=0;
pvs=0;
m_fontname="";
// memset(all,0,100);
// all[1]="";
}
CMy1View::~CMy1View()
{
}
BOOL CMy1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMy1View drawing
void CMy1View::OnDraw(CDC* pDC)
{
CMy1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CString string1;
string1.LoadString(IDS_LIANXI); //加載字符串資源 很多。
pDC->TextOut(420,420,string1);
pDC->BeginPath();// 路徑層用法
CSize sz=pDC->GetTextExtent(string1);
pDC->Rectangle(420,420,420+sz.cx,420+sz.cy);
pDC->EndPath();
//路徑層必用函數(shù)吧
pDC->SelectClipPath(RGN_DIFF); //對(duì)當(dāng)前剪切區(qū)域與路徑層做你要的運(yùn)算 and or xor diff 等
//測(cè)試路徑層作用
for (int j=400;j<500;j+=10)
{
pDC->MoveTo(400,j);
pDC->LineTo(500,j);
pDC->MoveTo(j,400);
pDC->LineTo(j,500);
}
pDC->SelectObject(&m_font);
// pDC->TextOut(100,100,"wewewew/newe");
pDC->GetTextMetrics(&tm); //用當(dāng)前設(shè)備描述表中的字體填充tm
CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);//創(chuàng)建之后默認(rèn)初始化隱藏了 要showcaret
ShowCaret();
CPoint xx;
xx=0;
SetCaretPos(xx);
CRect R;
GetClientRect(&R);
temp=int((R.bottom-R.top)/tm.tmHeight);
for (int i=0;i<temp;i++)
{
pall[i].x=0;
pall[i].y=i*tm.tmHeight;
pDC->TextOut(pall[i].x,pall[i].y,all[i]); //重繪時(shí)把以前的內(nèi)容用新字體重新輸出
// all[i]="";
}
temp=0;
// CString a;
// a.Format("%d",temp);
// MessageBox(a);
}
/////////////////////////////////////////////////////////////////////////////
// CMy1View printing
BOOL CMy1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy1View diagnostics
#ifdef _DEBUG
void CMy1View::AssertValid() const
{
CView::AssertValid();
}
void CMy1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy1Doc* CMy1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy1Doc)));
return (CMy1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMy1View message handlers
int CMy1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
/* // TODO: Add your specialized creation code here
CClientDC dc(this);
// TEXTMETRIC tm;
dc.GetTextMetrics(&tm); //用當(dāng)前設(shè)備描述表中的字體填充tm
CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);//創(chuàng)建之后默認(rèn)初始化隱藏了 要showcaret
// CBitmap bitmap;// 局部的啊 這樣光標(biāo)不可能顯示出來 析構(gòu)了。
// bitmap.LoadBitmap(IDB_BITMAP1);
// CreateCaret(&bitmap);
ShowCaret();
CPoint xx;
xx=0;
SetCaretPos(xx);
CRect R;
::GetClientRect(this->m_hWnd,&R);
temp=int((R.right-R.top)/tm.tmHeight);
for (int i=0;i<temp;i++)
{
all[i]="";
pall[i].x=0;
pall[i].y=i*tm.tmHeight;
}
temp=0;
*/ // 代碼移動(dòng)到初始化那去了
return 0;
}
void CMy1View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.SelectObject(m_font);
// TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
if (0x0d==nChar)
{
all[temp]=m_write;
m_write="";
// pall[temp].y+=tm.tmHeight;
temp+=1;
m_write=all[temp];
}
else if (0x08==nChar)
{
COLORREF col=dc.SetTextColor(dc.GetBkColor());
dc.TextOut(pall[temp].x,pall[temp].y,m_write);
m_write=m_write.Left(m_write.GetLength()-1);
dc.SetTextColor(col);
}
else
{
pvs=temp;
m_write+=nChar;
// CSize sz=dc.GetTextExtent(m_write);
// //SetCaretPos(m_origin.x+sz.cx,m_origin.y); 錯(cuò)了 因?yàn)橐玫谌?直接里面不能計(jì)算
// CPoint pt;
// pt.x=m_origin.x+sz.cx;
// pt.y=m_origin.y;
// SetCaretPos(pt);// 開始寫這里 真der
}
// if (!all[temp].IsEmpty())
// {
CSize sz=dc.GetTextExtent(m_write);
CPoint pt;
pt.x=pall[temp].x+sz.cx;
pt.y=pall[temp].y;
SetCaretPos(pt);
// }
dc.TextOut(pall[temp].x,pall[temp].y,m_write);
//all[temp]=m_write;
all[temp]=m_write;
CView::OnChar(nChar, nRepCnt, nFlags);
}
void CMy1View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// SetCaretPos(point);
//每次要把原來的字符清空
// m_write.Empty();
// m_origin=point;
CClientDC dc(this);dc.SelectObject(m_font);
int height=int(point.y/tm.tmHeight);
int reallyheight;
reallyheight=height*tm.tmHeight;
point.y=reallyheight;// 表示四舍五入的位置
temp=height;
// SetCaretPos(point);
pall[temp].x=0;pall[temp].y=point.y;
//all[pvs]=m_write;
if (!all[temp].IsEmpty())
{
//m_write=all[temp];
CSize sz1=dc.GetTextExtent(all[temp]);
CPoint pt;
pt.x=pall[temp].x+sz1.cx;
pt.y=pall[temp].y;
SetCaretPos(pt);
//SetCaretPos(pall[temp]);
m_write=all[temp];
// m_origin=point;
}
else
temp=pvs;
CView::OnLButtonDown(nFlags, point);
}
void CMy1View::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CClientDC dc(this);
// TEXTMETRIC tm;
dc.GetTextMetrics(&tm); //用當(dāng)前設(shè)備描述表中的字體填充tm
CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);//創(chuàng)建之后默認(rèn)初始化隱藏了 要showcaret
// CBitmap bitmap;// 局部的啊 這樣光標(biāo)不可能顯示出來 析構(gòu)了。
// bitmap.LoadBitmap(IDB_BITMAP1);
// CreateCaret(&bitmap);
ShowCaret();
CPoint xx;
xx=0;
SetCaretPos(xx);
CRect R;
GetClientRect(&R);
temp=int((R.bottom-R.top)/tm.tmHeight);
for (int i=0;i<temp;i++)
{
all[i]=""; //這的代碼也還有用 因?yàn)樗贠nDraw前執(zhí)行
pall[i].x=0; //能起到初始化功能 刪除的話 程序開始第一次調(diào)用ondraw
pall[i].y=i*tm.tmHeight; // 就textout 就出事了
}
temp=0;
}
void CMy1View::OnFont()
{
// TODO: Add your command handler code here
CFontDialog dlg;
if (IDOK==dlg.DoModal())
{
if(m_font.m_hObject)
m_font.DeleteObject();
m_font.CreateFontIndirect(dlg.m_cf.lpLogFont); //用戶選擇字體之后點(diǎn)擊確定就執(zhí)行了 用m_font的函數(shù)獲取字體
m_fontname=dlg.m_cf.lpLogFont->lfFaceName;// 在獲得字體的名字
}
Invalidate();
}
void CMy1View::OnFileSave()
{
// TODO: Add your command handler code here
CString strname;
int count=0;
char hf=13;
char hh=10;
CFileDialog dlg(false,"txt",NULL,OFN_OVERWRITEPROMPT,"Text Files(*.txt)|*.txt|",NULL);
if (IDOK==dlg.DoModal())
{
CFile file(dlg.GetPathName(),CFile::modeCreate | CFile::modeWrite);
for (int i=0;i<=30;i++)
{
if (!all[i].IsEmpty())
{
count++;
}
}
for (i=0;i<count;i++)
{
file.Write(all[i],strlen(all[i]));
file.Write(&hf,1); //換行怎么解決////..這方法估計(jì)很垃圾啊
file.Write(&hh,1);
}
file.Close();
}
}
void CMy1View::OnFileOpen()
{
// TODO: Add your command handler code here
CString strname;
int count=0;
CFileDialog dlg(true,"txt",NULL,OFN_OVERWRITEPROMPT,"Text Files(*.txt)|*.txt|",NULL);
if (IDOK==dlg.DoModal())
{
CFile file(dlg.GetPathName(),CFile::modeCreate|CFile::modeRead);
// 不會(huì)讀入數(shù)據(jù)...
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -