• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

绘图基础--鼠标移动画点

绘图基础--鼠标移动画点


 

// draw1.cpp

#include <afxwin.h>

// Define the application class
class CApp : public CWinApp
{
public:
	virtual BOOL InitInstance();
};

CApp App;  

// define the window class
class CWindow : public CFrameWnd
{ 
public:
	CWindow(); 
	afx_msg void OnMouseMove(UINT,CPoint);
	DECLARE_MESSAGE_MAP()
};

// The window's constructor
CWindow::CWindow()
{ 
	Create(NULL, "Drawing Tests", 
		WS_OVERLAPPEDWINDOW,
		CRect(0,0,250,250)); 
}

// The messahe map
BEGIN_MESSAGE_MAP( CWindow, CFrameWnd )
	ON_WM_MOUSEMOVE()	
END_MESSAGE_MAP()

// Handle mouse movement
void CWindow::OnMouseMove(UINT flag, 
	CPoint mousePos)
{
	//按住鼠标左键移动时,画点
	if (flag == MK_LBUTTON)
	{
		CClientDC dc(this);
		dc.SetPixel(mousePos,RGB(0,0,255));  //蓝色
		//dc.SetPixel(mousePos,RGB(rand()%256,rand()%256,rand()%256));
	}

	//按住鼠标右键移动时,擦除点
    if (flag == MK_RBUTTON)
	{
		CClientDC dc(this);
		dc.SetPixel(mousePos,RGB(255,255,255));	 //白色
	}
}

// Init the application
BOOL CApp::InitInstance()
{
	m_pMainWnd = new CWindow();
	m_pMainWnd->ShowWindow(m_nCmdShow);
	m_pMainWnd->UpdateWindow();
	return TRUE;
}


 

 

posted @ 2013-09-22 20:43  Class Xman  阅读(313)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3