如何使用 vc 中的菜单在两次单击之间创建一条线++
我正在尝试创建一个绘画应用程序,其中我使用菜单来显示我可以绘制的形状,并且我添加了一些形状,例如直线、矩形、圆形,但我无法在直线函数中使用 OnLButtonDown 函数,所以我我想知道如何通过不使用 LButtonDown 函数以及在用户单击菜单时创建一条线的任何其他方式在两次单击之间创建一条线,我的示例代码粘贴在下面:
#include<afxwin.h>
#include"resource.h"
class myframe:public CFrameWnd
{
public:
myframe()
{
Create(0,"simple",WS_OVERLAPPEDWINDOW,rectDefault,0,MAKEINTRESOURCE(IDR_MENU1));
}
void shape(int id)
{
CClientDC d(this);
CPen p;
p.CreatePen(PS_SOLID,1,RGB(255,0,0));
d.SelectObject(&p);
switch(id)
{
case 101:
d.MoveTo(100,100);
d.LineTo(200,200);
break;
case 102:
d.Rectangle(10,10,100,200);
break;
case 103:
d.Ellipse(20,20,100,100);
break;
}
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_COMMAND_RANGE(101,103,shape)
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *f;
f=new myframe();
f->ShowWindow(3);
m_pMainWnd=f;
return 1;
}
};
myapp a;
I am trying to create a paint application where in i am using a menu to show the shapes i can draw and i have added some shapes such as line,rectangle,circle but i am unable to use the OnLButtonDown function within the line function so i would like to know how can i create a line between two clicks by not using LButtonDown function and any other way by which i can create a line when user clicks on the menu my sample code is pasted below:
#include<afxwin.h>
#include"resource.h"
class myframe:public CFrameWnd
{
public:
myframe()
{
Create(0,"simple",WS_OVERLAPPEDWINDOW,rectDefault,0,MAKEINTRESOURCE(IDR_MENU1));
}
void shape(int id)
{
CClientDC d(this);
CPen p;
p.CreatePen(PS_SOLID,1,RGB(255,0,0));
d.SelectObject(&p);
switch(id)
{
case 101:
d.MoveTo(100,100);
d.LineTo(200,200);
break;
case 102:
d.Rectangle(10,10,100,200);
break;
case 103:
d.Ellipse(20,20,100,100);
break;
}
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_COMMAND_RANGE(101,103,shape)
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *f;
f=new myframe();
f->ShowWindow(3);
m_pMainWnd=f;
return 1;
}
};
myapp a;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几年前,Microsoft 发布了一个用 MFC 编写的示例应用程序,它正是这样做的。
它称为 Scribble,您可以下载它并按照书面教程进行操作 此处。
完成此操作后,您可以了解如何升级现有 MFC 应用程序以使用新的 Ribbon 用户界面。该教程可在此处获取:更新 MFC Scribble 应用程序
Several years ago, Microsoft published a sample application written in MFC that does exactly this.
It's called Scribble, and you can download it and following along with the written tutorial here.
Once you've done that, you can learn how to upgrade an existing MFC application to use the new Ribbon user interface. That tutorial is available here: Updating the MFC Scribble Application