-
September 24th, 2003, 09:12 AM
#1
Dynamic CFormView ...
How would I go about creating one CFormView with multiple IDD_DIALOG templates.
I know I can use the AddDocTemplate() to add another document/view template, but how would I go about creating on class derived from "CFormView", and make this class use more than one IDD_DIALOG resource template.
eg.
IDD_PROJECT_FORM <- this will be my main dialog resources containing, and edit control, and a richtextctl
IDD_PROJECT_FORM2 <- this will be my second dialog resource, and upon the ID_FILE_NEW message I would "create" the relevant IDD_ form, but then again this form should link to both resources,
the normal enum decleration in the CFormView class ...
public:
//{{AFX_DATA(CXIRCView)
enum{ IDD = IDD_FORM_SERVER };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
could I go and change this enum decleration like follows ->
public:
//{{AFX_DATA(CXIRCView)
enum{ IDD = IDD_FORM_SERVER, IDD2 = IDD_FORMCLIENT };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
and then in the construction pass a variable to the view, I wish to create ? Instead of this ->
/////////////////////////////////////////////////////////////////////////////
// CProjectView construction/destruction
CXIRCView::CProjectView()
: CFormView(CProjectView::IDD)
{
I rather do this ->
/////////////////////////////////////////////////////////////////////////////
// CProjectView construction/destruction
CProjectView::CProjectView(int ViewType)
// this will be removed for generic view/dialog resource : //CFormView(CProjectView::IDD_CurrentView)
{
switch(ViewType)
{
case 0:
IDD_CurrentView = IDD_FORM_SERVER;
break;
case 1:
IDD_CurrentView = IDD_FORM_CLIENT;
break;
default:
break;
}
CFormView(CProjectView::IDD_CurrentView);
}
[b]where IDD_CurrentView will be the ID of the dialog resources to be used, and then I pass this in my construction ... ?
-
September 24th, 2003, 10:30 AM
#2
-
September 24th, 2003, 10:52 AM
#3
You are on the right track, but not entirely ...
What gets explained in that article, is the dynamic creation of controls on a CFormView, I would like to know If have already designed 5 or 6 IDD_FORM (dialogs) ...then How could I call each View in diffrent situations ...
Eg. sometimes I need a view called IDD_FORM_SERVER, to display the server resource created in design view, and the other time, a View called IDD_FORM_CLIENT, which will be called in diffrent situation,
these 2 forms are already create, but how do I call them, as explained in my first article, do I override the construction methos of the CFormView, ... ?
thanx in advance ...
xIRC
-
September 24th, 2003, 02:06 PM
#4
Are all dialog templates the same as far as having the same number of controls, each with the same control id? If not, then any solution you use will have limited use, since it could not have any code that processes the controls in a CFormView-derived class.
Unfortunately, CFormView makes it difficult to do things like this. I have a tab control that has three tabs, all of which are the same. I posted a question asking how to use templates to create a class with code that does the same thing for each of the three dialogs but I could not get it to work. I finally realized that most of the common code could exist in a class that is not derived from CDialog. I pass as a parameter the list control and whatever I need to for the other class. I added my "base" class as a second class to derive from for each of my form dialogs, as in:
Code:
class CTab1Dlg : public CDialog, public CTabBaseDlg {
-
September 24th, 2003, 04:37 PM
#5
Nope ...
No but still it's not one common class that I wish to sub-class what I want to do is ... use 1 class to impliment the code ...
And rather only switch between the diffrent "form style sheets" if I could refer to it as thus ...
So I would have my IDD_FORM_SERVER, which will contain controls for server purposes, and then another IDD_FORM_CLIENT, with a totally diffrent set of controls, BUT I wish to use on class for both "dialog templates or interfaces" if you so wish. Because the code will be generic for both these cases. Since I only use the "skeleton" created by MFC for me, in the CFormView, and I do all my processing of data, with my own little wrapper class I wrote.
So all I actually want to know is instead of creating one class per IDD_FORM_X resource, instead I would like to if I could state it like this "MAP" each IDD_FORM_X resource to the one class created for me by the MFC Wizard, but there will have to be some modifications to the class itself I know this. So instead of adding more DocTemplates for each CFormView class I will have then I'd rather use the standard CFormView created for me, and by creation of each MDI child I will tell the application which "interface" to load, this is why I asked ... if I could over load the CFormView() constructor in my own class, and instead of having to call the default constructor as follows ->
CProjectView::CProjectView()
: CFormView(CProjectView::IDD)
{
I rather do something like this ->
CProjectView::CProjectView(int ViewType)
// this will be removed for generic view/dialog resource : //CFormView(CProjectView::IDD_CurrentView)
{
switch(ViewType)
{
case 0:
IDD_CurrentView = IDD_FORM_SERVER;
break;
case 1:
IDD_CurrentView = IDD_FORM_CLIENT;
break;
default:
break;
}
CFormView(CProjectView::IDD_CurrentView);
}
which will allow for me to load diffrent interfaces, but with the same class, and keeping the code for this class generic ...
I know I can do sub-classing, but that is missing the whole point, I don't wanna sub-class from one form, because no of 'em will have any relation what so ever, thus I want to create code that is generic, in example, when loading data from a database, all textbox fields will always be of type text, ect. Then I just do some processing, stepping through the form, and gathering the req. info., and doing the same processing for each type of control, but the interfaces, and layout and amount of actual controls will never be the same for each resources or template, and some even might have other controls, that other won't even have. All my controls, will always process the same events/things, all edit boxes will always be set to a certain color, and will always make us of the EN_CHANGE event, so I am looping through the form and collecting, all the controls, and "sub-classing" these controls, to a generic wraper class, which will be handling diffrent type of controls' events, ect.
In theory I actually already did do sub-classing, when I use the generic class wrapper that I wrote, all I want to do now is use diffrent resources/templates, but one class, and just "flip" the select interface ? ...
I hope this makes it a bit clearer ... hehe
Thanx in advance...
xIRC
Last edited by xIRC; September 24th, 2003 at 04:48 PM.
-
September 24th, 2003, 07:48 PM
#6
I am sorry but my brain can't hold all that. I hope someone can understand.
-
September 25th, 2003, 01:59 PM
#7
Sorry for cunfusion... hehe
I think I will mange, and as soon as I get this to work I will explain to you how this works
Anyways, got to get coding for now ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|