我可以在MFC GroupBox中使用鼠标事件吗? [英] Can I use mouse event in MFC GroupBox?

查看:151
本文介绍了我可以在MFC GroupBox中使用鼠标事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MFC CDialog创建MS Paint程序.我在创建画布时遇到问题.我不想直接在CDialog上绘制.我想在CDialog上放一些东西作为绘画画布.我的意思是,我想在白色画布上画线.我尝试了以下方法.
1.我使用mousemove事件并在CDialog上使用笔.我可以在CDialog上绘画.但是我不想直接在CDialog上绘制.
2.我在CDialog上创建了GroupBox用作画布.通过使用CRect,我用白色填充了GroupBox.当时那个矩形是用白色上色的.这就是我所需要的.然后,我使用mousemove事件和笔在GroupBox上绘制.但是,我不能在白色矩形上画线.我看不到任何画的线.
3.我基于CStatic类创建了GroupBox类.使用OnEraseBkgnd(CDC * pDC)事件,用白色填充GroupBox.然后,我在其中添加OnMouseMove,OnLButtonDown事件来处理鼠标事件.然后,我将该类添加到CDialog中.但是,问题是鼠标事件不适用于GroupBox.我说的对吗?

总而言之,我的要求是创建一个绘画画布并在其上绘制.但是我不知道该怎么做.有人可以给我指导吗?谢谢高级.

I would like to create MS Paint program by using MFC CDialog. I have problem in creating paint canvas. I don''t want to draw directly on CDialog. I would like to put something on CDialog as a paint canvas. I mean, I would like to draw lines on white canvas. I tried the following methods.
1. I used mousemove events and pen on CDialog. I can draw and paint on CDialog. But I don''t want to draw directly on CDialog.
2. I created GroupBox on CDialog to use as a canvas. By using CRect, I filled the GroupBox by white color. At that time, that rectangle was colored by white. It is what I need. Then, I use mousemove events and pen to draw on GroupBox. But, I can''t draw lines on white rectangle. I can''t see any lines that I draw.
3. I created GroupBox Class based on CStatic Class. Use OnEraseBkgnd(CDC* pDC) event, to fill GroupBox with white color. Then I add OnMouseMove, OnLButtonDown events there to handle mouse events. Then I added that class to CDialog. But, the problem is mouse events don''t work for GroupBox. Am I right?

Summarizing, my requirement is to create a paint canvas and draw on it. But I don''t know how to do it. Could anyone give me guidelines on it? Thanks in advanced.

推荐答案

我尝试了几种方法后得到了解决方案.我的解决方案如下.
通过使用优化校准创建画布.通过覆盖OnEraseBkgnd事件在优化校准中填充颜色.
将优化校准控件设置为透明"True",并通知"True".然后,覆盖优化校准的鼠标事件.最后,我可以获得MS颜料,例如画布和绘图功能.
谢谢大家对我的问题的思考.
I got the solution after trying several ways. My solution is as follow.
Create a canvas by using Picture Control. Fill color in Picture Control by overwriting OnEraseBkgnd event.
Set Picture Control Properties as Transparent "True", and Notify "True". Then, overwrite mouse events of Picture Control. Finally, I can get MS paint like canvas and drawing features.
Thanks all for thinking on my problem.


可能最灵活的选择就是简单地基于CWnd创建控件.我认为可行的另一个选择是基于CButton创建一个类. CButton肯定会响应用户输入,您可以将其平放以隐藏它是按钮的事实.
Probably the most flexible option is simply to create a control based on CWnd. Another option that I think will work is to create a class based on CButton. CButton certainly responds to user inputs, and you could draw it flat to hide the fact that it is a button.


这篇关于我可以在MFC GroupBox中使用鼠标事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆