如何使用 MFC 以编程方式更改 ActiveX 控件的属性?
我在我的MFC项目中添加了一个activex控件,我没有使用对话框编辑器来添加该控件,我只是使用MFC为该控件生成一个包装类,并在包装类中调用“create”成员来创建但是
class CMyView
{
CCalendar m_ctl;
//other members.....
}
int CMyView::OnCreate
{
m_ctl.create("",WS_CHILD|WS_VISIBLE,this,CRect(50,50,100,100));
//.....
}
我发现包装类没有为我提供更改控件属性的方法,所以如果我想以编程方式更改控件的属性,我该怎么办?我可以通过包装类来实现这一点吗?或者完全可以通过编程来完成吗?或者只能通过对话框编辑器来完成?谢谢。
I added a activex control to my MFC project, I don't use the dialog editor to add the control, I just used MFC to generate a wrapper class for the control, and call the "create" member in the wrapper class to create the control programmatically, the code is more or less like:
class CMyView
{
CCalendar m_ctl;
//other members.....
}
int CMyView::OnCreate
{
m_ctl.create("",WS_CHILD|WS_VISIBLE,this,CRect(50,50,100,100));
//.....
}
But I found that the wrapper class provide no way for me to change the control's property, so if I want to change the control's property programmatically, what should I do? Can I achieve this through a wrapper class? Or can it be done programmatically at all? Or is it only can be done via a dialog editor? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,如果您通过类向导创建包装器,则包装器仅包含函数。
要更改属性(即变量),您可以在表单或对话框中实例化 ActiveX,并且可以在属性窗口中修改属性值。
如果您想在运行时执行此操作,可以右键单击 ActiveX 对象,然后单击添加变量。您将看到它还将为该对象创建包装类。此类将自动包含 activex 的 getter 和 setter,在新生成的头文件中可见。
如果您已经为您的 activex 创建了一个包装类,它可能不起作用,请在新项目中尝试此操作。然后您可以将生成的 .cpp 和 .h 文件复制到您自己的项目中。
Yes, wrapper only includes functions, if you create it via class wizard.
To change properties, i.e. variables, you could instantiate ActiveX in a form or a dialog and you would have the ability to modify values of properties in properties window.
If you want to do it on-the-run, you can right click to activeX object and then click on add variable. You will see that it will also create wrapper class for the object. This class will automatically include getters and setters for the activex, visible in the newly generated header file.
If you have already created a wrapper class for your activex, it may not work, try this in a fresh project. You can then copy generated .cpp and .h files to your own project afterwards.