15,979
社区成员
发帖
与我相关
我的任务
分享
#include<afxwin.h>
#include<math.h>
class CMyWnd:public CFrameWnd
{
BOOL m_bIsDraw;
CRect m_rectFrame;
public:
CMyWnd();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
};
BEGIN_MESSAGE_MAP(CMyWnd,CFrameWnd)
ON_WM_PAINT()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
CMyWnd::CMyWnd()
{
m_rectFrame.SetRect(10, 10, 100, 100);
}
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
if(m_bIsDraw)
{
dc.FrameRect(m_rectFrame, &CBrush(RGB(255, 0, 0)));
}
}
class CMyApp:public CWinApp
{
public:
BOOL InitInstance();
};
BOOL CMyApp::InitInstance()
{
CMyWnd *pFrame=new CMyWnd;
pFrame->Create(0,_T("title")/*,WS_SYSMENU*/);
pFrame->ShowWindow(m_nCmdShow);
this->m_pMainWnd=pFrame;
return TRUE;
}
CMyApp ThisApp;
void CMyWnd::OnMouseMove(UINT nFlags, CPoint point)
{
m_rectFrame.PtInRect(point)?m_bIsDraw = true : m_bIsDraw = false;
InvalidateRect(m_rectFrame);
CFrameWnd::OnMouseMove(nFlags, point);
}