資源簡介
VC 實現(xiàn)窗口狀態(tài)欄顯示鼠標(biāo)坐標(biāo)信息的方法,這是個完整的代碼實例 ,在VC6.0環(huán)境下可編譯源代碼并運行看效果,具體效果請參見測試截圖。可在窗體的狀態(tài)欄內(nèi)顯示設(shè)備坐標(biāo)和邏輯坐標(biāo)的X/Y信息,變量ID_SEPARATOR用來顯示設(shè)備坐標(biāo)系下的鼠標(biāo)位置,ID_SEPARATOR用來顯示邏輯坐標(biāo)系下的鼠標(biāo)位置。return m_bkBrush; 作為約定,返回背景色對應(yīng)的刷子句柄。
代碼片段和文件信息
//?ChildView.cpp?:?implementation?of?the?CChildView?class
//?download?by?http://www.codefans.net
#include?“stdafx.h“
#include?“color.h“
#include?“ChildView.h“
#include?“MainFrm.h“
#ifdef?_DEBUG
#define?new?DEBUG_NEW
#undef?THIS_FILE
static?char?THIS_FILE[]?=?__FILE__;
#endif
int?MyGlobal;
/////////////////////////////////////////////////////////////////////////////
//?CChildView
CChildView::CChildView()
{
m_ptMouse?=?CPoint(00);??//?Initialize?the?m_ptMouse
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildViewCWnd?)
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//?CChildView?message?handlers
BOOL?CChildView::PreCreateWindow(CREATESTRUCT&?cs)?
{
if?(!CWnd::PreCreateWindow(cs))
return?FALSE;
cs.dwExstyle?|=?WS_EX_CLIENTEDGE;
cs.style?&=?~WS_BORDER;
cs.lpszClass?=?AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS?
::LoadCursor(NULL?IDC_ARROW)?HBRUSH(COLOR_WINDOW+1)?NULL);
return?TRUE;
}
void?CChildView::OnPaint()?
{
CPaintDC?dc(this);?//?device?context?for?painting
//?TODO:?Add?your?message?handler?code?here
//?Demonstrate?how?to?access?the?global?variable.
MyGlobal?=?9999;
CColorApp?*?pApp?=?(CColorApp?*)AfxGetApp();
pApp->MyGlobal?=?8888;
//?Display?some?prompt?text.
dc.TextOut(2020“It?demonstrates?message?relection?of?WM_CTLCOLOR.?please?see?About?Dialog?“);
dc.TextOut(2040“It?demonstrates?the?path?of?GDI.“);
dc.TextOut(2060“It?demonstrates?how?to?add?a?global?variable.“);
dc.TextOut(2080“It?demonstrates?the?MAP_MODE?of?GDI?and?displays?the?coordinate?of?mouse?in?status?bar.“);
//?I?will?draw?a?rectangle?with?a?sin()?edge.
dc.BeginPath();
CRect?rectTemp(200200500400);
DrawSpecialRect(dc?rectTemp);
dc.EndPath();
CBrush?MyBrush?(RGB(2550255));
CBrush?*?OldBrush?=?(CBrush?*)?dc.Selectobject(&MyBrush);
dc.StrokeAndFillPath();
dc.Selectobject(OldBrush);
//?I?will?draw?a?cross?line?of?new?coordinate.
CRect?rect;
GetClientRect(rect);
dc.MoveTo(0?rect.Height()/2);
dc.LineTo(rect.Width()?rect.Height()/2);
dc.MoveTo(rect.Width()/2?0);
dc.LineTo(rect.Width()/2?rect.Height());
//?Do?not?call?CWnd::OnPaint()?for?painting?messages
}
void?CChildView::DrawSpecialRect(CPaintDC?&dc?CRect?rect)
{
CPoint?pt1?pt2?pt3?pt4;
pt1?=?rect.TopLeft();
pt2?=?pt1?+?CSize(rect.Width()?0);
pt3?=?rect.BottomRight();
pt4?=?pt1?+?CSize(0?rect.Height());
dc.MoveTo(pt1);
DrawSinLine(dc?pt1?pt2);
dc.LineTo(pt3);
dc.LineTo(pt4);
dc.LineTo(pt1);
}
void?CChildView::DrawSinLine(CPaintDC?&dc?CPoint?pt1?CPoint?pt2)
{
//?Note:?(pt1.y?==?pt2.y)?&&?(pt2.x?>?pt1.x)
//?I?will?draw?the?line?with?1000?points?in?two?circle?of?sin();
double?step?=?double(pt2.x?-?pt1.x)?/?1000;
double?x?y;
for?(x?=?0;?x?<=?1000;?x++)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4221??2009-09-22?18:42??codesc.net\abbeyclrdemo\ChildView.cpp
?????文件???????1563??2002-12-21?18:18??codesc.net\abbeyclrdemo\ChildView.h
?????文件??????24084??2009-09-22?18:39??codesc.net\abbeyclrdemo\color.aps
?????文件???????1963??2003-05-08?17:53??codesc.net\abbeyclrdemo\COLOR.CLW
?????文件???????4615??2009-09-22?18:42??codesc.net\abbeyclrdemo\COLOR.CPP
?????文件???????4464??2002-11-04?13:53??codesc.net\abbeyclrdemo\COLOR.DSP
?????文件????????535??2002-08-31?16:41??codesc.net\abbeyclrdemo\COLOR.DSW
?????文件???????1408??2009-09-22?18:42??codesc.net\abbeyclrdemo\COLOR.H
?????文件???????8919??2002-12-15?20:14??codesc.net\abbeyclrdemo\COLOR.RC
?????文件???????1097??2009-09-22?18:42??codesc.net\abbeyclrdemo\ColorEdit.cpp
?????文件???????1151??2002-08-31?17:42??codesc.net\abbeyclrdemo\ColorEdit.h
?????文件???????3068??2009-09-22?18:42??codesc.net\abbeyclrdemo\MainFrm.cpp
?????文件???????1714??2002-12-21?17:20??codesc.net\abbeyclrdemo\MainFrm.h
?????文件???????5494??2002-12-22?14:17??codesc.net\abbeyclrdemo\PROGRAM.TXT
?????文件???????3534??2002-08-31?16:41??codesc.net\abbeyclrdemo\ReadMe.txt
?????文件???????1078??2002-08-31?16:41??codesc.net\abbeyclrdemo\RES\COLOR.ICO
?????文件????????397??2002-08-31?16:41??codesc.net\abbeyclrdemo\RES\COLOR.RC2
?????文件????????682??2002-12-15?20:04??codesc.net\abbeyclrdemo\RESOURCE.H
?????文件????????245??2009-09-22?18:42??codesc.net\abbeyclrdemo\StdAfx.cpp
?????文件???????1111??2002-11-23?15:52??codesc.net\abbeyclrdemo\StdAfx.h
?????目錄??????????0??2015-07-13?23:08??codesc.net\abbeyclrdemo\RES
?????目錄??????????0??2015-07-13?23:08??codesc.net\abbeyclrdemo
?????目錄??????????0??2015-07-13?23:08??codesc.net
-----------?---------??----------?-----??----
????????????????71343????????????????????23
評論
共有 條評論