Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. MVC for MFC

MVC for MFC

Scheduled Pinned Locked Moved The Lounge
12 Posts 7 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NormDroid
    wrote on last edited by
    #1

    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?

    N A J C 4 Replies Last reply
    0
    • N NormDroid

      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?

      N Offline
      N Offline
      NormDroid
      wrote on last edited by
      #2

      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! :(( :(( :(( :((

      C N S 3 Replies Last reply
      0
      • N NormDroid

        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?

        A Offline
        A Offline
        Anders Molin
        wrote on last edited by
        #3

        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!"

        1 Reply Last reply
        0
        • N NormDroid

          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?

          J Offline
          J Offline
          Jim Crafton
          wrote on last edited by
          #4

          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

          N 1 Reply Last reply
          0
          • N NormDroid

            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! :(( :(( :(( :((

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • N NormDroid

              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! :(( :(( :(( :((

              N Offline
              N Offline
              Neville Franks
              wrote on last edited by
              #6

              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

              N 1 Reply Last reply
              0
              • N NormDroid

                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?

                C Offline
                C Offline
                Chris Hafey
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • N NormDroid

                  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! :(( :(( :(( :((

                  S Offline
                  S Offline
                  Stephen Kellett
                  wrote on last edited by
                  #8

                  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.

                  N 1 Reply Last reply
                  0
                  • N Neville Franks

                    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

                    N Offline
                    N Offline
                    NormDroid
                    wrote on last edited by
                    #9

                    Neville You've obviously been down same path as me, not many MFC developers write doc/view or large document centric applications and thats it's a subject that's not touched on very much.

                    1 Reply Last reply
                    0
                    • S Stephen Kellett

                      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.

                      N Offline
                      N Offline
                      NormDroid
                      wrote on last edited by
                      #10

                      IsKindOf - oh Stephen I'm puking, which MS programmer come up with that one?

                      1 Reply Last reply
                      0
                      • J Jim Crafton

                        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

                        N Offline
                        N Offline
                        NormDroid
                        wrote on last edited by
                        #11

                        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

                        J 1 Reply Last reply
                        0
                        • N NormDroid

                          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

                          J Offline
                          J Offline
                          Jim Crafton
                          wrote on last edited by
                          #12

                          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

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups