On Thursday 14 March 2002 13:02, you wrote:
> I have a newbie question.
> I have built a Fox GUI Class myClass like the examples provided with the
> library (example: "Calculator"). My main program creates an Application,
> then sends it to myClass (which extends FXMainWindow). Then the main
> program calls application->create() and application->run()
> Works great. Widgets respond to messages, etc.
> However, I would like to turn my class myClass into a Widget. How can I do
> this? I have consulted the crappy documentation on the Fox Website but it
> leaves a lot of holes.
I thank you for this glowing compliment. It really encourages me
to answer your questions when you lead in a question like that...... :-)
> Please can someone send me a .h & .cpp files of a VERY VERY simple widget
> that they created? My widget is simply a FXVertical frame called vertFrame
> with some subframes/buttons on it.
> Here are some specific questions I have:
> 1) What class should myClass extend? Currently it extends FXMainWindow.
> Should I be extending FXComposite?
Obviously, the widget which looks closest to the one you want to create.
If you want to make a kind of layout manager, you'd subclass it from FXPacker.
If you want to do any OpenGL drawing, I'd subclass from FXGLCanvas or FXGLViewer.
All widgets can be subclassed. Its one of the fundamental reasons you'd want to
> 2) What argument should myClass's constructor take? An FXWindow of some
> type I assume. Right?
If myClass is a kind of widget, you'd want to pass in a parent widget,
layout flags, and possibly some coordinates x,y,w,h, and possibly padding (margins).
Most FOX widgets have:
Widget(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)
As argument list. Note that all except parent p can use the C++ default parameter
concept, and thus need often not be specified explicitly by the programmer.
Since its not possible to have widgets w/o parents, you'd want to hide certain
constructors, lest they be called by accident by an unsuspecting developer:
Widget& operator=(const Widget&);
[And no implementation of these!].
Furthermore, for deserialization of widgets it is necessary to have a
In the typical implementation, you'd initialize the member variables (technically,
only those members which are not read in from FXStream need to be initialized; but
it can't hurt to initialize them all).
> 3) How should I place my vertFrame onto the argument received in the
Your constructor should pass arguments to its base class; for example:
FXLabel::FXLabel(FXComposite* p,const FXString& text,FXIcon* ic,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):
FXLabel passes some of the arguments to FXFrame. Other arguments pertain to FXLabel
itself and are used to initialize member data.
> 4) Should my Main program create both the FXApp and the FXMainWindow and
> then send the FXMainWindow to myClass's constructor?
Yes, please refer to the many sample programs; you will always
need FXApp, and create an FXMainWindow. Look at button.cpp for