Nondynamic Doc/View Architecture Usage in MFC - c++

I have a problem in which there is bunch of data that will be displayed in two different ways and they should always be synchronized with data . Logically i thought of exploiting the Doc/View architecture on which mfc is based .
However The usage of MFC Doc/View architecture imposes the dynamic creation of document , view class by the Framework which is sth i don't want since i have to create the views myself within tab controls and DockablePane . Is there a workaround which let me take benefit of the Doc/View archiecture so i can create a view and corresponding document without the usage of dynamic creation by frameowrk ? sth like the qt's model/view technology !

What you want can be done within the MFC doc/view framework. It just takes more study. You can prevent MFC from creating a view at new document by passing NULL as the view class to AddDocTemplate. Then you can create views where you like using MFC's dynamic creation, specifically the CreateObject method. See the MFC source code for CSplitterWnd::CreateView as an example.

Yes, you can create two different views of the same document. If you always want both, the method MFC supports the most directly is a window with a static splitter, so you have one view in each pane of the splitter.
It's not (at all) clear what dynamic creation has to do with any of this though.

Related

MFC Tabbed Views

I need a basic on how to declare/implement and use the CTabView class for an MFC SDI. I have searched in vain for samples and reference. I assume because MFC is not the most current foundation information is hard to find on certain topics, anything about tabs in particular. How declare an create the tabbed view object? When using add/delete view in the control, is the control creating the view or adding a tab to a view that is already created. Moving and Sizing? Truly appreciate any help. Need native C++ in this app, so answers that tell me how much easier in C# with a different foundation do not help.
Simply derive your view class from CTabView.
You can add as many tabs as you need by calling:
AddView(RUNTIME_CLASS(CMyView),_T("Tab1"));
AddView(RUNTIME_CLASS(CMyView),_T("Tab2"));
AddView(RUNTIME_CLASS(CMyView),_T("Tab3"));
You can also customize the location and other things of tab control by calling:
GetTabControl().SetLocation(CMFCBaseTabCtrl::LOCATION_BOTTOM);
GetTabControl().ModifyTabStyle(CMFCTabCtrl::STYLE_3D_ONENOTE);
GetTabControl().EnableTabDocumentsMenu(TRUE);
GetTabControl().EnableActiveTabCloseButton(TRUE);
GetTabControl().EnableTabSwap(TRUE);
from int CMyTabView::OnCreate(LPCREATESTRUCT lpCreateStruct)

Is document/view architecture in MFC basically a Model/View/Controller pattern but without the controller?

Is the document/view architecture in MFC really a Model/View/Controller pattern without the controller part?
I'm studying MFC and I simply love it to bits. I know is somewhat outdated and somewhat bit more difficult to use, but I discovered that it gives me so much more power and performance gain when compared to QT.
Am I correct to think of the MFC doc/view model as simply MVC without the Controller part?
The Model/View/Controler has the following components:
Model
View: responsible to show the model to the user
Controller: responsible to get user input and translate it in operations on the model
MFC's Document/View has only 2 components:
The document, which is in fact our model
The View, which has the responsibility to show the Document AND interpret the user's commands. So it is the view+controller (refer to section Variants in this MSDN article)
Let's look at it:
The view contains UI code, both for rendering the data and for taking input from the user.
The document contains the serialization code.
From that perspective, there's just a separation between UI and a backend. However, there's more, because you can have multiple different views on the same document. You could also use the document to just provide data storage and put any actual program logic into the view. In particular when you only effectively use a single view per document, it is easy to blur the separation in practice.
In summary, I wouldn't say the MVC controller part is missing but that it's merged with the MVC view parts into the MFC view.

Creating tabbed document interfaces in Qt Designer?

I am trying to write a program that will use a tabbed document interface (TDI) like seen in Notepad++ or most web browsers. I know how to build GUIs using Qt Designer, and code in Qt C++ (after a few days of playing around).
I have created an example of what each page widget will look like using Designer, and now I want to add the ability to create and testroy tabs at runtime, each containing a unique instance of the page widget. However, I have no idea how to do this without adding a class that extends QWidget, and building the page widget with code. I could go down this route, but I'm sure there must be a better way of creating a TDI; but I can't find any tutorials or examples of how to do this.
Does anyone have any suggestions?
For creating tab interfaces you should look into QTabWidget.
It is a container widget included in Qt Designer which automatically handles operations on tabs. It has several build in methods for manipulating its tabs and theirs contents.
Each page of QTabWidget is handled separately and can have different layouts and functionality.
If you want to include several different objects to one page assign a layout to it and then assign the objects to the layout.

cpp graphical menu

I am making a new graphical menu interface for a project I am making. I don't want to use the menu system provided by windows APIs and want to make one from scratch.
My question is, what is the best method for setting up the structure?
I'm thinking I will need a menu item object, each of which will have to have their own item array list, etc...
Is it considered sloppy to have recursive coding like that? (Ie an object which contains objects of itself, which contains objects of itself, etc...)
I'm thinking I can give the item object a draw interface which checks itself to see if it has an item array that is not null. If it does, it executes the draw command all the way down, thereby giving me a menu with (for my purposes) unlimited submenu level
In my opinion your approach is fine. In nearly all UI frameworks, views contain views as subviews after all.
But the thing is that writing drawing code is too much work for small projects I think. I would consider using a UI framework such as QT and use its view mechanism as a starting point. You can write your own Menu class which will be a subclass of generic View class in the framework.

Native CheckedListBox?

In .NET land, there's the tremendously useful System.Windows.Forms.CheckedListBox class.
What is the equivalent in Windows Common Controls land? (if any)
Turn a list view into one with checkboxes. If you want it similar to a ListBox, only use 1 column.
ListView_SetExtendedListViewStyle (handle, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
Almost identical UI can be developed with the List View control by using item state images.
But selection management and other functionalities need to be implemented manually.
This article might be of interest for you. In short windows allows quite easily to implement checkboxes in Listbox and combobox through custom drawing and messaging.