I am building an app with two MFC classes descended from CDialog.
Probably by the end of it, I am going to have 5 or 6 CDialogs (in a
tabbed window). I have spent quite some time adding custom painting
to the first of them. All of them, in the end, are going to have this
same custom painting going on.
The thing to do then would be to make an intermediate class, MyDialog,
descended from CDialog, with the custom painting in the OnPaint()
method, then derive the 5 or 6 dialogs from that, so I am not
repeating and maintaining the custom painting code in all of my
dialogs.
Theoretically this is very simple ... I create a class MyDialog, then
change the parent class of my dialogs from CDialog to MyDialog, then
transfer the custom OnPaint() method from the dialogs to MyDialog, so
the children all inherit it.
But this doesn't seem to work in a project built on MFC. I tried
creating MyDialog by hand. I've been programming in C++ for years,
this part is simple enough. The CDialog constructor stymies me a
little ... the auto-generated version calls the parent with
CDialog(AppDialog1::IDD, pParent), where IDD is an enum generated with
the resource ID of the dialog. If I'm doing it by hand, I don't have
this, so I try the alternate constructor, CDialog(). This compiles,
but I don't know if this is going to be a problem.
Then I try to change AppDialog1 to subclass from MyDialog. So the
only change is I change the superclass from CDialog to MyDialog.
Now it doesn't compile, I get "error C2143: syntax error : missing ';'
before 'constant'", the error is in the header file at this line:
"class AppDialog1.1 : public MyDialog". I renamed AppDialog1 to
AppDialog1.1 so I could work on it without messing up AppDialog1,
which works ... is an x.x naming convention a problem?
So I have no idea what that means.
So I try creating MyDialog in the visual builder. It gives me a
warning because I am not building it from a visually-created class, so
it won't have an ID. Well I can't see a way around that, so OK.
When I try to compile it, I get an error (more or less predictably)
because in the enum, IDD is defined as "UNKNOWN ID" or something, so
again I change the constructor from CDialog(MyDialog::IDD, pParent) to
CDialog().
Now it compiles OK. So I try to create a subclass, AppDialog1.1,
which descends from MyDialog
Again I get the same error:
"error C2143: syntax error : missing ';' before 'constant'"
And again I have no idea what exactly that is supposed to mean.
Is this just impossible? Can I not mix my own classes with MFC
classes this way?
I am wondering if anybody has done something similar. The errors are,
as far as I can guess, happening in macros or something that are
generated by MFC. It is basically impossible to debug these.
Maybe if I build AppDialog1.1 in the visual builder ... but then it
won't allow me to choose a base class of my own, only from the MFC
classes. Another dead end.
--
Joe Cosby
http://www.yqcomputer.com/
It is difficult to produce a television documentary that is both incisive and probing when every twelve minutes one is interrupted by twelve dancing rabbits singing about toilet paper.
- Rod Serling
:: Currently listening to Poor Poor Pitiful Me, 1978, by Warren Zevon, from "Warren Zevon"