MFC CWnd在MDI / SDI CView中派生控件 [英] MFC CWnd derived control in a MDI/SDI CView

查看:116
本文介绍了MFC CWnd在MDI / SDI CView中派生控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CWnd派生的自定义控件,我想放在MFC SDI视图窗口中。



我首先尝试了一种简单的方法,如 http://www.codeproject.com/Articles/313/Using -the并网控制-IN-A-文档 - 视图 - 框架。基本上派生一个CView类并使我的控​​件成为CView类的成员。适用于所有人,但输入焦点。 GetFocus()始终返回CView窗口而不是我的控件。这最终会禁用我控制的部分,所以不是我真正需要的。



然后我尝试从CCtrlView派生一个类,如http://www.developer.com/net/cplus/article.php/627681/推导-的CWnd类从 - CCtrlView.htm 。现在我知道这将是这样做的正确方法,但是因为这篇文章是15岁,下载和图像不再适用于它。我知道我错过了一些东西,但我无法弄清楚它是什么。代码不会调用我的CWnd类的构造函数,因此我的所有成员变量都未初始化,因此应用程序崩溃。



是否有人有一些工作示例代码,或者一些链接,显示如何使用 CCtrlView 来做我想要的事情?

I have a CWnd derived custom control that I want to place in an MFC SDI view window.

I first tried the easy way as described in http://www.codeproject.com/Articles/313/Using-the-Grid-Control-in-a-Doc-View-framework. Basicly deriving a CView class and making my control a member of the CView class. Works great for all but the input focus. GetFocus() always returns the CView window and not my control. This ends up disabling parts of my control so not really what I need.

I then tried deriving a class from CCtrlView as described in http://www.developer.com/net/cplus/article.php/627681/Deriving-CWnd-classes-from-CCtrlView.htm. Now I know this would be the proper way of doing it, but as the article is 15 years old the download and images no longer work for it. I know I am missing something but I can not figure out what it is. The code does not call my CWnd class' constructor so all my member variables are uninitialized and the app crashes as a result.

Does anyone have some working sample code, or a link to some, that shows how to use CCtrlView to do what I want?

推荐答案

引用:我首先尝试了http://www.codeproject.com/Articles/313/Using-the-Grid-Control-in-a-Doc-View-framework中描述的简单方法。基本上派生出一个CView类并进行控制CView类的一个成员。除了输入焦点之外,它可以很好地工作.GetFocus()总是返回CView窗口而不是我的控件。这最终会禁用我控制的部分而不是我真正需要的东西。



如果这是您唯一的问题,请覆盖CView :: SetFocus以将输入焦点传递给您的控件。
Quote: "I first tried the easy way as described in http://www.codeproject.com/Articles/313/Using-the-Grid-Control-in-a-Doc-View-framework. Basicly deriving a CView class and making my control a member of the CView class. Works great for all but the input focus. GetFocus() always returns the CView window and not my control. This ends up disabling parts of my control so not really what I need."

If that is your only problem, override the CView::SetFocus to pass the input focus down to your control.


这篇关于MFC CWnd在MDI / SDI CView中派生控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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