在对话框上画一个任意图形,如何让任意拖动,改变其位置和大小,http://st251256589.blog.163.com/blog/static/164876449201152164849508/,此处介绍了使用CRectTracker类,但是这个矩形是指定的,我希望在程序运行过程中任意画一个图形就可以操作,望高手指点
解决方案 »
- 修改数据库表里的数据
- MFC外观界面 插件
- 急。求助 VC 程序打包工具,撒分!
- 求2次立方图象缩放代码,万分感谢!!
- 请教一个控件类型
- 如何找到Society of Motion Picture and Television Engineers (SMPTE)相关的资料?
- 钩子问题
- 为什么mfc分割窗口CreateStatic(this , 1 , 2)总出错
- 请问高手们,这个该怎么做啊
- ??????请教一个关于SDK程序的问题=》如何隐藏程序(任务栏和Ctrl+Alt+Del下)
- if (!pThread->InitInstance()) 出错
- GDI+ 问题: Image对象转换Bitmap
涉及到‘点 和 线的 点击 测试’
下载 我的 “直线或曲线的点击测试.rar”0 分
http://download.csdn.net/detail/schlafenhamster/4914656
你可以在这个类的巨型里面画任意图形啊,可托大缩小,有什么问题?
void CGuPCDlg::DrawRectangle(CDC *pDC)
{
Graphics graphics(pDC->GetSafeHdc());
Pen pen(RGB(0,0,0),1);
SolidBrush br(Color(60,128,128));
CRect rect;
m_RectTracker.GetTrueRect(&rect);
graphics.DrawRectangle(&pen,rect.left,rect.top,rect.Width(),rect.Height());
graphics.FillRectangle(&br,rect.left,rect.top,rect.Width(),rect.Height());
if (m_IsChosen)
{
m_RectTracker.Draw(pDC);
}}
此处rect是橡皮筋框的大小,怎么转化为客户区的矩形坐标,以便以后重绘时非操作图形在原处重绘,而不是所有的图形都叠加到橡皮框
有个变量 m_rect (?)
鼠标在 其中 一个 就可以 使能 拖动 了
{
CPaintDC pDC(this);
CRect rect;
GetClientRect(&rect);
CMemDC dc(&pDC, &rect);
for (int i=0;i<Sum+2;i++)
{
switch(graph.m_DrawRect[i].DrawType)
{
case 1:
DrawRectangle(&dc,i);
break;
case 2:
DrawSANJ(&dc,i);
break;
case 3:
DrawYZ(&dc,i);
break;
default:
break;
}
}
}// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CGuPCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}void CGuPCDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// if ((point.x>0 && point.y>70)&&(typeID!=0))
// {
m_startrect=TRUE;
if (RectSet==TRUE)
{
Sum++;
graph.m_DrawRect[Sum].DrawType=typeID;
graph.m_DrawRect[Sum].Num=Sum+2;
switch(typeID)
{
case 1:
m_RectTracker.m_rect.SetRect(point.x-20,point.y-20,point.x+50,point.y+50);
break;
case 2:
m_RectTracker.m_rect.SetRect(point.x-20,point.y-20,point.x+20,point.y+20);
break;
case 3:
m_RectTracker.m_rect.SetRect(point.x-20,point.y-30,point.x+20,point.y+50);
break;
}
RectSet=FALSE;
}
m_ptStart=point;
if (m_RectTracker.HitTest(point)<0)
{
CRectTracker tempRectTracker;
CRect rect;
tempRectTracker.TrackRubberBand(this ,point,TRUE);
// SendMessage(WM_LBUTTONUP,NULL,NULL);
tempRectTracker.m_rect.NormalizeRect();
if (rect.IntersectRect(tempRectTracker.m_rect,m_RectTracker.m_rect))
m_IsChosen=TRUE;
else
m_IsChosen=FALSE; }
else
{
CClientDC dc(this);
m_RectTracker.Draw(&dc);
m_RectTracker.Track(this,point,TRUE);
SendMessage(WM_LBUTTONUP,NULL,NULL);
m_IsChosen=TRUE;
Invalidate();
}
graph.m_DrawRect[Sum].mrect=m_RectTracker.m_rect;
// Invalidate();
CDialog::OnLButtonDown(nFlags, point);
}
void CGuPCDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptEnd=point;
if (m_startrect==TRUE)
{
CClientDC dc(this);
// OnPaint();
// m_startrect=FALSE;
RectSet=FALSE;
typeID=0;
}
CDialog::OnLButtonUp(nFlags, point);
}BOOL CGuPCDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
if (pWnd==this&& m_RectTracker.SetCursor(this,nHitTest))
{
return TRUE;
} return CDialog::OnSetCursor(pWnd, nHitTest, message);
}void CGuPCDlg::DrawRectangle(CDC *pDC,int temp1)
{
Graphics graphics(pDC->GetSafeHdc());
Pen pen(RGB(0,0,0),1);
SolidBrush br(Color(60,128,128));
CRect rect1;
rect1=graph.m_DrawRect[temp1].mrect;
m_RectTracker.GetTrueRect(&rect1);
graphics.DrawRectangle(&pen,rect1.left,rect1.top,rect1.Width(),rect1.Height());
graphics.FillRectangle(&br,rect1.left,rect1.top,rect1.Width(),rect1.Height());
if (m_IsChosen)
{
m_RectTracker.Draw(pDC);
}}void CGuPCDlg::DrawSANJ(CDC *pDC, int temp2)
{
Graphics graphics(pDC->GetSafeHdc());
Pen pen(RGB(0,0,0),1);
SolidBrush br(Color(128,128,0));
CRect rect2;
rect2=graph.m_DrawRect[temp2].mrect;
m_RectTracker.GetTrueRect(&rect2);
graphics.DrawEllipse(&pen,rect2.left+5*temp2,rect2.top,rect2.Width(),rect2.Height());
graphics.FillEllipse(&br,rect2.left+5*temp2,rect2.top,rect2.Width(),rect2.Height());
if (m_IsChosen)
{
m_RectTracker.Draw(pDC);
}
}void CGuPCDlg::DrawYZ(CDC *pDC,int temp3)
{
Graphics graphics(pDC->GetSafeHdc());
Pen pen(RGB(0,0,0),1),pen2(RGB(128,128,0),3);
SolidBrush br(Color(128,128,0)),black(Color(0,0,0));
CRect rect3;
rect3=graph.m_DrawRect[temp3].mrect;
m_RectTracker.GetTrueRect(&rect3);
graphics.SetSmoothingMode(SmoothingModeHighQuality);
graphics.DrawEllipse(&pen,rect3.left,rect3.top+6*rect3.Height()/8,rect3.Width(),rect3.Height()/4);
// graphics.FillEllipse(&br,rect3.left,rect3.top+6*rect3.Height()/8,rect3.Width(),rect3.Height()/4);
graphics.DrawRectangle(&pen,rect3.left,rect3.top+rect3.Height()/8,rect3.Width(),3*rect3.Height()/4);
// graphics.FillRectangle(&br,rect3.left,rect3.top+rect3.Height()/8,rect3.Width(),3*rect3.Height()/4);
graphics.DrawEllipse(&pen2,rect3.left,rect3.top,rect3.Width(),rect3.Height()/4);
// graphics.FillEllipse(&black,rect3.left,rect3.top,rect3.Width(),rect3.Height()/4);
if (m_IsChosen)
{
m_RectTracker.Draw(pDC);
}
}
要一个数组 !
//
CRectTracker *ptr=new CRectTracker;
ptr->m_rect=rcElem;
int now=m_rcArray.Add(ptr);
//
int all= m_rcArray.GetSize()
//
CRectTracker* ptmp=(CRectTracker*)m_rcArray[m_uEleHit-1];
m_rcArray.RemoveAt(m_uEleHit-1);
...