Win32 MVC Template Implementation

I am currently working on a win32 application, and I think I should use the MVC pattern. Now, according to the template, the code that handles user interaction must be in the controller so that I can update the model and / or view accordingly. But in Win32, does this mean that my windowProc should be in the controller? It seems a little strange to me, I would create a window and all the UI stuff, and then subclass wndProc in the controller. On the other hand, if I do not, I will need a controller instance in the view so that I can handle the model. I am pretty sure that is NOT the way to go.

If someone can point me in the right direction, it will be great!

Thanks.

+4
source share
3 answers

The code that handles user interaction is a representation. The controller "sticks together" a model with a view (simply said). The window procedure definitely belongs to the graphical interface, that is, part of the view. From this graphical interface you will generate events that the controller will catch, call the model and respond to them.

+3
source

The MFC Document / View model is an attempt at midfield MVC. If you are thinking about using MFC, you can use the CView class to represent the view (duh!) And the class derived from CDocument to represent the model. Unfortunately, MFC is not really trying to keep the controller functionality separate from the model or view.

In the SDI Doc / View application, the event-related nature of the Windows GUI makes it gracefully easy to put some controller functions into the view - and most of the code created by the wizard in MFC does this.

In the MDI application, there are several views for each model, and obviously, it is wrong for any of them to be a controller, so the temptation is to put the controller logic in a document class or in a frame window ... but it’s easy to add a new one class to control the controller and use it to transfer domain logic. However, plumbing this class in the MFC is a battle, and most people do not seem to be bothered. The easiest approach is to simply consider the document as a model and controller rolled into one.

This is for MFC (which, despite its many shortcomings), still remains one of the most productive platforms for writing Windows-based graphics applications only in C ++. If you do not need MFC or you need an infrastructure that supports multiple platforms, you may already have better MVC support - see this article with MVC support in Qt, for example.

0
source

The problem may be with your level of abstraction.

Let's say you had the same data model and controls as how to change it, and you wanted to change the whole interface from win32 to HTML. All this bit of the interface is a view.

Now you can even have several models and controllers, say, for domain data and how the application is currently being viewed.

Controllers often must exist outside the lifetime of a certain part of the view.

0
source

All Articles