資源簡介
基于vs2008,采用vc++編寫的一款簡單的MFC 文本編輯器。

代碼片段和文件信息
//?ChildView.cpp?:?CChildView?類的實(shí)現(xiàn)
//
#include?“stdafx.h“
#include?“Typer.h“
#include?“ChildView.h“
#ifdef?_DEBUG
#define?new?DEBUG_NEW
#endif
//?CChildView
CChildView::CChildView()
{
caretPos.x?=?1;
caretPos.y?=0;
cursor??=?AfxGetApp()->LoadStandardCursor(IDC_IBEAM);
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildView?CWnd)
ON_WM_PAINT()
ON_WM_SETFOCUS()
ON_WM_KILLFOCUS()
ON_WM_LBUTTONUP()
ON_WM_CHAR()
ON_WM_SETCURSOR()
ON_WM_KEYDOWN()
ON_WM_SIZE()
END_MESSAGE_MAP()
//?CChildView?消息處理程序
BOOL?CChildView::PreCreateWindow(CREATESTRUCT&?cs)?
{
if?(!CWnd::PreCreateWindow(cs))
return?FALSE;
cs.dwExstyle?|=?WS_EX_CLIENTEDGE;
cs.style?&=?~WS_BORDER|WS_VISIBLE|WS_MAXIMIZE;
cs.lpszClass?=?AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS?
::LoadCursor(NULL?IDC_ARROW)?reinterpret_cast(COLOR_WINDOW+1)?NULL);
return?TRUE;
}
void?CChildView::OnPaint()?
{
CPaintDC?dc(this);?//?用于繪制的設(shè)備上下文
//?不要為繪制消息而調(diào)用?CWnd::OnPaint()
}
//取得視圖工作區(qū)的輸入焦點(diǎn)
void?CChildView::OnSetFocus(CWnd?*pOldWnd)
{
CWnd::OnSetFocus(pOldWnd);
::CreateCaret(*this(HBITMAP)NULL120);
SetCaretPos(caretPos);
ShowCaret();
}
//失去輸入焦點(diǎn)
void?CChildView::OnKillFocus(CWnd*?pNewWnd)
{
CWnd::OnKillFocus(pNewWnd);
//隱藏光標(biāo)
HideCaret();
//刪除文本光標(biāo)
DestroyCaret();
}
//放開鼠標(biāo)左鍵
void?CChildView::OnLButtonUp(UINT?nFlags?CPoint?point)
{
CWnd::OnLButtonUp(nFlagspoint);
caretPos?=?point;
//將光標(biāo)移到鼠標(biāo)所單擊的位置
SetCaretPos(caretPos);
}
//輸入文字
void?CChildView::OnChar(UINT?nChar?UINT?nRepCnt?UINT?nFlags)
{
GetClientRect(rect);
nWidth?=?rect.Width();
if(nChar!=VK_BACK?&&?nChar!=VK_RETURN)
{
CWnd::OnChar(nCharnRepCntnFlags);
TCHAR?str[2];
CSize?size;
CSize?size2;
str[0]?=?(TCHAR)nChar;
str[1]?=?0;
HideCaret();
CClientDC?dc(this);
size?=?dc.GetTextExtent(str1);//計(jì)算字符串在屏幕上的長寬點(diǎn)數(shù)
size2?=?dc.GetTextExtent(str1)?+dc.GetTextExtent(str1);
if(caretPos.x?>=nWidth?)
{
caretPos.y?+=?size.cy;
caretPos.x?=?1;
}
dc.TextOut(caretPos.xcaretPos.ystr);
caretPos.x?+=?size.cx;
SetCaretPos(caretPos);
ShowCaret();
}
}
BOOL?CChildView::OnSetCursor(CWnd*?pWnd?UINT?nHitTest?UINT?message)
{
BOOL?bCursor;
bCursor?=?CWnd::OnSetCursor(pWndnHitTestmessage);
if((bCursor==FALSE)&&(nHitTest==HTCLIENT))
{
SetCursor(cursor);
}
return?bCursor;
}
//鍵盤消息函數(shù)
void?CChildView::onkeydown(UINT?nChar?UINT?nRepCnt?UINT?nFlags)
{
GetClientRect(rect);
nWidth?=?rect.Width();
TCHAR?str[2];
CSize?size;
CSize?size2;
str[0]?=?(TCHAR)‘?‘;
str[1]?=?0;
HideCaret();
CClientDC?dc(this);
//計(jì)算字符串在屏幕上的長寬點(diǎn)數(shù)
size?=?dc.GetTextExtent(str1);
size2?=?dc.GetTextExtent(str1)?+dc.GetTextExtent(str1);
switch(nChar)
{
case?VK_BACK:
if(caretPos.x?<=?0)
{
caretPos.x?=?nWidth?;
caretPos.y?-=?size.cy;
}
caretPos.x?-=?size2.cx?;
dc.TextOut(caretPos.xcaretPos.yL“??“);
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-07-05?20:18??Typer\
?????文件????????3898??2012-07-05?17:02??Typer\ChildView.cpp
?????文件?????????858??2012-07-05?16:06??Typer\ChildView.h
?????文件???????????1??2006-11-20?16:11??Typer\ClassDiagram1.cd
?????目錄???????????0??2012-07-05?20:18??Typer\Debug\
?????文件????????5998??2012-07-05?17:02??Typer\Debug\BuildLog.htm
?????文件???????35204??2012-07-05?17:02??Typer\Debug\ChildView.obj
?????文件???????34821??2012-07-05?16:06??Typer\Debug\MainFrm.obj
?????文件??????????65??2012-07-05?17:02??Typer\Debug\mt.dep
?????文件??????466146??2012-07-05?12:15??Typer\Debug\stdafx.obj
?????文件????????1196??2012-07-05?12:15??Typer\Debug\Typer.exe.em
?????文件????????1260??2012-07-05?12:15??Typer\Debug\Typer.exe.em
?????文件????????1120??2012-07-05?17:02??Typer\Debug\Typer.exe.intermediate.manifest
?????文件???????35074??2012-07-05?16:06??Typer\Debug\Typer.obj
?????文件????25100288??2012-07-05?12:15??Typer\Debug\Typer.pch
?????文件???????25564??2012-07-05?12:15??Typer\Debug\Typer.res
?????文件??????912384??2012-07-05?17:02??Typer\Debug\vc90.idb
?????文件?????2174976??2012-07-05?17:02??Typer\Debug\vc90.pdb
?????文件????????2513??2012-07-05?15:42??Typer\MainFrm.cpp
?????文件?????????834??2012-07-05?10:22??Typer\MainFrm.h
?????文件????????2947??2012-07-05?10:22??Typer\ReadMe.txt
?????目錄???????????0??2012-07-05?20:18??Typer\res\
?????文件?????????481??2012-07-05?10:22??Typer\Resource.h
?????文件?????????598??2003-07-24?09:52??Typer\res\Toolbar.bmp
?????文件???????21630??2003-07-24?09:52??Typer\res\Typer.ico
?????文件?????????361??2012-07-05?10:22??Typer\res\Typer.rc2
?????文件?????????136??2012-07-05?10:22??Typer\stdafx.cpp
?????文件????????1796??2012-07-05?10:22??Typer\stdafx.h
?????文件????????1030??2012-07-05?10:22??Typer\targetver.h
?????文件???????63408??2012-07-05?12:12??Typer\Typer.aps
?????文件????????2587??2012-07-05?12:13??Typer\Typer.cpp
............此處省略4個(gè)文件信息
評(píng)論
共有 條評(píng)論