之前写了一篇博文,是一种画矩形的方法,但是今天介绍的方法比之前的要好一些,总结出来方便自己,方便需要的小伙伴们。。。。。。
直接上代码:
在头文件中写如下代码
protected:
HICON m_hIcon;
CPoint m_ptbegin;
CPoint m_ptEnd;
BOOL m_blBtnDown;
CDC m_dcMemory;
在实现文件中:
void CModifyRectDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//GetCursorPos(&point);
CWnd *pWnd = GetDlgItem(IDC_STATIC);
CDC *pDC = pWnd->GetDC();
CRect rcClient1;
GetCursorPos(&point);
pWnd->ScreenToClient(&point);
pWnd->GetClientRect(&rcClient1);
if(point.x> rcClient1.left&&point.x <rcClient1.right&&point.y <rcClient1.bottom&&point.y> rcClient1.top)//限制点击位置
{
//ClipCursor(&rcClient);
m_blBtnDown = TRUE;
m_ptbegin = point;
// pWnd->GetWindowRect(&rcClient);
//ScreenToClient(&point);
CBitmap oBitmap;
oBitmap.CreateCompatibleBitmap(pDC, rcClient1.Width(), rcClient1.Height());//创建一个与原来相同的对象
if (m_dcM