MVC for MFC
-
I've been programming Windows for a long time now and I'm finally sick to death of the Doc/View architecture of MFC - pointers to the Mainframe, app, doc, drives me crazy, I seem to be doing the same things over and over again to compensate for the inadequacies that the Doc/View has. Get a pointer to this so I do that - garbage - not OOP at all. Q: Does anybody know of a Model/View/Controller for MFC - Freeware? NOT stingray. If not can we develop one between ourselves?
-
I've been programming Windows for a long time now and I'm finally sick to death of the Doc/View architecture of MFC - pointers to the Mainframe, app, doc, drives me crazy, I seem to be doing the same things over and over again to compensate for the inadequacies that the Doc/View has. Get a pointer to this so I do that - garbage - not OOP at all. Q: Does anybody know of a Model/View/Controller for MFC - Freeware? NOT stingray. If not can we develop one between ourselves?
Bit late now, but anybody learning MFC finds the same problem "I'm in a palette window how do I get a pointer to the friggin' document to notify the views I've changed a color" Norm: Oh well what ya do is: CMainframe* pFrameWnd = static_cast(AfxGetMainWnd()); CMyDocument* pDoc static_castGetActiveDocument()); pDoc->UpdateAllViews(...,...,...); Every bloody time and make sure you have RTTI enabled eh? No wonder there are so many VB programmers around! :(( :(( :(( :((
-
I've been programming Windows for a long time now and I'm finally sick to death of the Doc/View architecture of MFC - pointers to the Mainframe, app, doc, drives me crazy, I seem to be doing the same things over and over again to compensate for the inadequacies that the Doc/View has. Get a pointer to this so I do that - garbage - not OOP at all. Q: Does anybody know of a Model/View/Controller for MFC - Freeware? NOT stingray. If not can we develop one between ourselves?
What about WTL? I don't know if it does what you need, but personally, I'm planning to take a closer look at it sometime soon... My problem is that I spend less than 5% of my time writing GUI, and I really don't like MFC. - Anders Money talks, but all mine ever says is "Goodbye!"
-
I've been programming Windows for a long time now and I'm finally sick to death of the Doc/View architecture of MFC - pointers to the Mainframe, app, doc, drives me crazy, I seem to be doing the same things over and over again to compensate for the inadequacies that the Doc/View has. Get a pointer to this so I do that - garbage - not OOP at all. Q: Does anybody know of a Model/View/Controller for MFC - Freeware? NOT stingray. If not can we develop one between ourselves?
Well I don't mean to toot the old VCF horn again, but what about the VCF ? If you're sick of MFC then why not use it ? It has pretty complete MVC, and whatever is missing would gladly be put in place. Also You could judt use a part of VCF or even just rip off the MVC parts of it. Just a thought ! check it out at http://sourceforge.net/projects/vcf or http://vcf.sourceforge.net
-
Bit late now, but anybody learning MFC finds the same problem "I'm in a palette window how do I get a pointer to the friggin' document to notify the views I've changed a color" Norm: Oh well what ya do is: CMainframe* pFrameWnd = static_cast(AfxGetMainWnd()); CMyDocument* pDoc static_castGetActiveDocument()); pDoc->UpdateAllViews(...,...,...); Every bloody time and make sure you have RTTI enabled eh? No wonder there are so many VB programmers around! :(( :(( :(( :((
So you provide a helper function like GetDocument is provided for the view - I don't see why that's a big deal ? What is MVC ? Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
-
Bit late now, but anybody learning MFC finds the same problem "I'm in a palette window how do I get a pointer to the friggin' document to notify the views I've changed a color" Norm: Oh well what ya do is: CMainframe* pFrameWnd = static_cast(AfxGetMainWnd()); CMyDocument* pDoc static_castGetActiveDocument()); pDoc->UpdateAllViews(...,...,...); Every bloody time and make sure you have RTTI enabled eh? No wonder there are so many VB programmers around! :(( :(( :(( :((
I agree this is all a right royal pane. I assume your pallete window is not a view, but needs to notify certain views that they need updating. I'd probably hide this in a function in CMainFrame and call that from the pallete window. Or even set up a WM_USERnn message handler in CMainFrame and use AfxGetMainWnd()->SendMessage(). You also need to take the Document Template into account, if you have multiple templates. My programmers editor ED for Windows makes heavy use of the MFC DocView architecture and I have had to bend over backwards in places to get the all of right things happening. One of the biggest problems is getting all the message routing and focus/window activation to work properly when you have windows/controls other than the views themselves. ED also uses Stingray OTPRO, but I don't and wouldn't use their MVC architecture. I don't have too many (any?) nice things to say about Stngray. A fairly major shortcoming of the MFC MVC (model-view-controller) is that it doesn't have the "controller", and instead bundles this in with the view. Suffice to say that this is inadequate for my needs, so I had to implement my own controller. Another problem is the difficulty in using CView's in things like Docked Windows. Having said all that I wouldn't want use anything but a MVC architecture in an application like ED for Windows. I'd also be very interesting in seeing any other MVC implementations on Windows. I did look briefly at Jim Craftons VCF but from memory I was already too far down the track with MFC. Neville Franks, Author of ED for Windows. Version 4.01 just released, with a C++ Class View that actually works. www.getsoft.com
-
I've been programming Windows for a long time now and I'm finally sick to death of the Doc/View architecture of MFC - pointers to the Mainframe, app, doc, drives me crazy, I seem to be doing the same things over and over again to compensate for the inadequacies that the Doc/View has. Get a pointer to this so I do that - garbage - not OOP at all. Q: Does anybody know of a Model/View/Controller for MFC - Freeware? NOT stingray. If not can we develop one between ourselves?
MVC is a design pattern, not a framework. We have applied MVC to our MFC based application on our more complex components with great success. Here is what we are doing: 1) The controller class is derived from CWnd. This class has message handlers for the various windows events it is interested in. It forwards the OnPaint() handler to the view class. 2) The view class has a virtual Paint() method taking a CDC&. All the code to render the view is contained in this class 3) The model class contains methods for querying state as well as performing certain actions. It aggregates and uses other classes that contain the business logic. All three classes have various virtual methods that subclassses can override to specialize behavior. We do not use MVC for everything, dialogs are usually simple enough to handle the model/view/controller logic in one class. We do not use the MFC doc/view for anything. Hope this helps... Chris Hafey
-
Bit late now, but anybody learning MFC finds the same problem "I'm in a palette window how do I get a pointer to the friggin' document to notify the views I've changed a color" Norm: Oh well what ya do is: CMainframe* pFrameWnd = static_cast(AfxGetMainWnd()); CMyDocument* pDoc static_castGetActiveDocument()); pDoc->UpdateAllViews(...,...,...); Every bloody time and make sure you have RTTI enabled eh? No wonder there are so many VB programmers around! :(( :(( :(( :((
And of course the code Norm has suggested doesn't work if your object can also be instantiated as an OLE/COM server. In which case you are down to (if you are lucky enough) to using virtual methods, and if you are not lucky enough doing a *VOMIT* IsKindOf() on the object and doing the appropriate thing with the pointer based on whether it really is a CFrameWnd or a CSomethingOrOtherOLEServerThisThatTheOtherObject. Just lurve that OOD. Stephen Stephen Kellett -- C++/Java/Win NT/Unix variants Memory leaks/corruptions/performance/system problems. UK based. Problems with RSI/WRULD? Contact me for advice.
-
I agree this is all a right royal pane. I assume your pallete window is not a view, but needs to notify certain views that they need updating. I'd probably hide this in a function in CMainFrame and call that from the pallete window. Or even set up a WM_USERnn message handler in CMainFrame and use AfxGetMainWnd()->SendMessage(). You also need to take the Document Template into account, if you have multiple templates. My programmers editor ED for Windows makes heavy use of the MFC DocView architecture and I have had to bend over backwards in places to get the all of right things happening. One of the biggest problems is getting all the message routing and focus/window activation to work properly when you have windows/controls other than the views themselves. ED also uses Stingray OTPRO, but I don't and wouldn't use their MVC architecture. I don't have too many (any?) nice things to say about Stngray. A fairly major shortcoming of the MFC MVC (model-view-controller) is that it doesn't have the "controller", and instead bundles this in with the view. Suffice to say that this is inadequate for my needs, so I had to implement my own controller. Another problem is the difficulty in using CView's in things like Docked Windows. Having said all that I wouldn't want use anything but a MVC architecture in an application like ED for Windows. I'd also be very interesting in seeing any other MVC implementations on Windows. I did look briefly at Jim Craftons VCF but from memory I was already too far down the track with MFC. Neville Franks, Author of ED for Windows. Version 4.01 just released, with a C++ Class View that actually works. www.getsoft.com
-
And of course the code Norm has suggested doesn't work if your object can also be instantiated as an OLE/COM server. In which case you are down to (if you are lucky enough) to using virtual methods, and if you are not lucky enough doing a *VOMIT* IsKindOf() on the object and doing the appropriate thing with the pointer based on whether it really is a CFrameWnd or a CSomethingOrOtherOLEServerThisThatTheOtherObject. Just lurve that OOD. Stephen Stephen Kellett -- C++/Java/Win NT/Unix variants Memory leaks/corruptions/performance/system problems. UK based. Problems with RSI/WRULD? Contact me for advice.
-
Well I don't mean to toot the old VCF horn again, but what about the VCF ? If you're sick of MFC then why not use it ? It has pretty complete MVC, and whatever is missing would gladly be put in place. Also You could judt use a part of VCF or even just rip off the MVC parts of it. Just a thought ! check it out at http://sourceforge.net/projects/vcf or http://vcf.sourceforge.net
Jim If you could 'slice' off your MVC component and make *more* generic this would almost definitely be an option, and if it could slot this into a standard MFC app. all the better, I'll take a look at this tomorrow. I, as well as a lot of other developers/compines have too much investment in MFC to just convert to VCF. While I feel you've done a great job with VCF, as I've said before I can't see any software house/company moving to a non-commerical library such as VCF - please don't take this as critism or personal. Regards Norm
-
Jim If you could 'slice' off your MVC component and make *more* generic this would almost definitely be an option, and if it could slot this into a standard MFC app. all the better, I'll take a look at this tomorrow. I, as well as a lot of other developers/compines have too much investment in MFC to just convert to VCF. While I feel you've done a great job with VCF, as I've said before I can't see any software house/company moving to a non-commerical library such as VCF - please don't take this as critism or personal. Regards Norm
I partially agree with you (though I have had a couple of smaller consulting shops express interest in the framework once it hits 1.0), but what about the switch to all hte new .NET stuff ? Over and over I have seen people complain about brain dead MFC problems on these lists, complain about the lack of a visual tool to write the UI's for and still work in standard C++. VCF addresses all of this, it's relatively simple to use (certainly much easier than MFC, and arguably just as easy as the .NET classes), its open, it's free, and it I even have the VCF Builder residing inside of Dev Studio (at home, I still need to connect in some Dev Studio events) as an add-in. Isn't it a fact that at some point MFC will be abandoned ? If not by MS themselves (which surely seems the case with the new .NET stuff), then by developers themselves. If this is true doesn't it behoove all of us to look at things to take it's place ? But anyways, ranting aside :), I wil look into it, maybe I'll write an article showing how it works in the VCF and someone else may get inspired as well. See ya! Jim