Sometimes, gentle reader, you may wish
to use the same code in many projects (an honorable and just practice) and for
reasons best left to yourself you choose not to partake in the creation of lib
files and dll’s.
In fact many programmers choose to create a directory and dump classes (the .h and
cpp files), which they think they may use often, and then add the relevant paths to VC++
(Tools->Options->Directories then setting the relevant include and source
directories as necessary). Moreover other programmers like to simply dump a copy
of the .h an .cpp files into the project folder they want to use it in and work
from there. And still others yet like to use the Gallery to
create ogx files. The purpose of this article then, gentle reader, is to elucidate as
to how to take advantage of the Gallery.
Suppose my friend, you have created a most excellent
class that you believe you will want to use in another project. You don’t wish to use dll’s or lib files.
Perhaps each time you need to use it some minor modification may be necessary or
perhaps even you dear reader just simply
want access to the source code in the project without having to go dropping
copies of the source code around into
A very lithesome ion to this problem is provided by using
the Gallery. According to the help files provided by
The Gallery provides a convenient way to add complex code such as components and
ActiveX controls to your project, or to let you reuse previously written
But how do we add our class(es) to this magical Gallery?
Simple my good friend – follow this gentle procedure.
Open the project in which the class of interest already exists.
Open the Workspace (View Menu->Wordspace, or ALT-0)
Click on the root node of the Tree (in this case “MyCoolApp classes”) and there will now be a list of the classes in
the application (see below).
Click on the class of interest (in this case we will use “CMyGroovyClass” and from
the menu displayed choose “Add to Gallery”).
This will now create a nice sparkly new folder in something like
“C:\Program Files\Microsoft Visual Studio\Common\MSDEV98\Gallery” (depending
on where you have VC++ installed).
The folder will have the same name as the project (in this case “MyCoolApp”)
and inside this folder will be a .ogx file with the same name as your class (in this case it will
be My Groovy Class.ogx (see below)
You can share this file with others if you wish. To use it, all they need to do is
either create a similar sub-folder in the Gallery folder and place the .ogx file
into that, or they can drop the file into “Visual C++ Components” folder
(Although it is probably best if they create a new folder).
Now you have added your class to the Gallery, you are now free to use it in
other projects with little effort to you dear reader.
How do I use it?
Open the project you want to add the class to (or start
a new project).
Open the Gallery (Project Menu-> Add to Project->Components and Controls)
From the “Components and Controls Gallery” window that appears, select the folder that holds the .ogx (in this
Then either double click the .ogx file, or select the .ogx file then click
“Insert”, you will now be prompted with the following dialog:
Click “OK”, then close the “Components and Controls Gallery” window. The class will now be
inserted into your project (just like magic but better).
Having passed on my wisdom I am now free to go about my daily business as too are you my dear reader. I hope this has
been enlightening and wish you happiness and heartiness on your quest for perfect
An additional pointer to you all in your journey - You can also add ActiveX controls or
third party components to your projects. Read the MSDN help files for
information on how to do this and for more information on .ogx
Here-in ends the lesson.