难!难! vc6 中编程问题

sunjing 2000-02-17 02:26:00
问:
如何编写一个对话框(DIALOG)程序,在对话框中可以实现如下功能:
对话框中有一个窗口,用户只需要在窗口中拖动鼠标,就可以
在窗口中动态地生成矩形框 ??
...全文
306 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ad 2000-02-18
  • 打赏
  • 举报
回复
其实MFC中有一个类CRectTracker可实现画矩形,
例如:
...::OnLButtonDown(UINT nFlags, CPoint point)
{
//...
CRectTracker tracker();
tracker.m_sizeMin = CSize(0,0);
tracker.TrackRubberBand(this, point, true);
tracker.m_rect.NormalizeRect();
//
}

具体的使用可查看有关CRectTracker的帮助信息。
本人以CRectTracker的源码为蓝本写了一个任意多边形的tracker,有兴趣的朋友可以联络dzm_xy@cmmail.com。
Eros 2000-02-17
  • 打赏
  • 举报
回复
重载一个CStatic类,响应OnDraw(),OnLbuttonDown(),OnMouseMove(),OnLbuttonUp()就可以了
szyifan 2000-02-17
  • 打赏
  • 举报
回复
只要在对话框中的窗口(估计是RICH编辑框)中捕捉鼠标的MouseMove或MoveClick消息,然后在消息响应函数中实现画图的功能。
snowhust 2000-02-17
  • 打赏
  • 举报
回复
用MFC生成一个DIALOG,在class CAnswerDlg : public CDialog中加入
public:
BOOL flag;//标记鼠标左键是否按下
POINT point1;//记录按下鼠标的位置
在answerDlg.cpp中利用classwizard加入以下代码:
void CAnswerDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// 鼠标按下并记录位置
flag=TRUE;
point1=point;
CDialog::OnLButtonDown(nFlags, point);
}

void CAnswerDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// 鼠标抬起
flag=FALSE;
CDialog::OnLButtonUp(nFlags, point);
}

void CAnswerDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// 鼠标按下则画矩形
if(flag)
{
CRect rect,rect1,rect2,rect3,rect4,client;
GetClientRect(&client);
//将所绘的矩形框周围刷新以避免出现重影
rect1.top=0;
rect1.left=0;
rect1.right=client.Width();
rect1.bottom=point1.y;
rect2.top=0;
rect2.left=0;
rect2.right=point1.x;
rect2.bottom=client.Height();
rect3.top=point1.y;
rect3.left=point.x;
rect3.right=client.Width();
rect3.bottom=client.Height();
rect4.top=point.y;
rect4.left=point1.x;
rect4.right=client.Width();
rect4.bottom=client.Height();
InvalidateRect(rect1,TRUE);
InvalidateRect(rect2,TRUE);
InvalidateRect(rect3,TRUE);
InvalidateRect(rect4,TRUE);
//随着鼠标的移动绘制矩形框
CDC *pDC=GetDC();
rect.top=point1.y;
rect.right=point.x;
rect.left=point1.x;
rect.bottom=point.y;
pDC->Rectangle(rect);
}
CDialog::OnMouseMove(nFlags, point);
}

eel 2000-02-17
  • 打赏
  • 举报
回复
你好:
在对话框类MyDlg中定义两个CPoint 变量pot1,pot2来储存矩形两点,即要画矩形的起始点与终点,定义一个整型变量che来判断鼠标是否按下,重载
ON_WM_PAINT()消息,在它对应的函数OnPaint()中加入如下代码:
MyDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
dc.MoveTo(pot1.x,pot1.y);
dc.LineTo(pot2.x,pot1.y);
dc.LineTo(pot2.x,pot2.y);
dc.LineTo(pot1.x,pot2.y);
dc.LineTo(pot1.x,pot1.y);

}

在对话框对应的类中加入如下消息处理函数:
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
相应加入如下代码:

void MyDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
che=1;
pot1=point;
}

void My::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(che==1)
{
che=0;
pot2=point;
Invalidate();
}
}

void My::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(che==1)
{
pot2=point;
Invalidate();

}
}




beni 2000-02-17
  • 打赏
  • 举报
回复
矩形框吗?简单!
CPoint bp;
void CDlgDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
bp=point;
CDialog::OnLButtonDown(nFlags, point);
}

void CDlgDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(nFlags==MK_LBUTTON&&point!=bp)
{
Invalidate();
UpdateWindow();
CDC* pDC=GetDC();
pDC->MoveTo(bp);
pDC->LineTo(point.x,bp.y);
pDC->LineTo(point.x,point.y);
pDC->LineTo(bp.x,point.y);
pDC->LineTo(bp.x,bp.y);
ReleaseDC(pDC);
}
CDialog::OnMouseMove(nFlags, point);
}

void CDlgDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
bp=CPoint(0,0);
CDialog::OnLButtonUp(nFlags, point);
}
WHQ 2000-02-17
  • 打赏
  • 举报
回复
鼠标拖动的消息是容易捕获的——左键按下时,标记拖开始,左键释放时拖结束——如果是要画矩形,则在窗口类中加一个数组记录各矩形的对角,每一个拖动就在数组中添一项,如果要画窗口,则直接创建一窗口就成了。
OnLButtonDown(UINT nFlags, CPoint pt)
{
m_bDrag = true;
m_FirstPoint = pt;
}

OnLButtonUp(UINT nFlags, CPoint Pt)
{
new CWnd;
CWnd.Create(...)

new CRect(m_FirstPoint, Pt);
m_arrRect.Add(CRect); // 在OnPaint中画出所有矩形
InvalidRect(TRUE);
}
}
xenogear 2000-02-17
  • 打赏
  • 举报
回复
好像问题不难解决, 将具体问题描述的清楚一些. 看不大清楚的说.
Sniper 2000-02-17
  • 打赏
  • 举报
回复
矩形框是什么?控件还是一个简单的矩形图形?

16,470

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧