Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Comments
Garth J Lancaster 1-Nov-15 18:32pm    
PJ - I dont know if this is any good to you - I did a quick search using the terms Tom/Archer/CWnd/CCtrlView and this came up http://www.codeguru.com/cpp/w-d/doc_view/controlviews/article.php/c3259/Turn-Any-CWndDerived-Control-Class-into-a-View.htm - at least the download works
PJ Arends 1-Nov-15 18:56pm    
Thanks. I will look into it tonight when I get back home.
PJ Arends 2-Nov-15 11:13am    
Looks like I am going to have to rewrite my control to make this work. All my public functions have to be handled via the SendMessage() API, not through the class instance function calls as I do now. Oh well, looks like I have coding to do.

1 solution

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.
 
Share this answer
 
Comments
PJ Arends 2-Nov-15 14:22pm    
I had tried that already, but you made me relook at it. My mistake was calling the CView::OnSetFocus() after calling SetFocus on my control.

Sometimes I can be such a dough head.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900