Click here to Skip to main content
15,879,490 members
Articles / Programming Languages / C++
Article

The Groovyness of the Gallery

Rate me:
Please Sign up or sign in to vote.
3.67/5 (21 votes)
11 Feb 20033 min read 70.7K   21   14
An article on using the Gallery to resuse classes.

Introduction

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.

A Beginning

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 folders.

A very lithesome ion to this problem is provided by using the Gallery. According to the help files provided by Microsoft™…

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 code.”

But how do we add our class(es) to this magical Gallery?

Simple my good friend – follow this gentle procedure.

  1. Open the project in which the class of interest already exists.

  2. Open the Workspace (View Menu->Wordspace, or ALT-0)

  3. 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).

    The Workspace

  4. Click on the class of interest (in this case we will use “CMyGroovyClass” and from the menu displayed choose “Add to Gallery”).

    Workspace with menu

  5. 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)

  6. gallery directories

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 what?

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?

  1. Open the project you want to add the class to (or start a new project).

  2. Open the Gallery (Project Menu-> Add to Project->Components and Controls)

    Components and Controls

  3. From the “Components and Controls Gallery” window that appears, select the folder that holds the .ogx (in this case MyCoolApp).

  4. Components and Control Gallery

  5. Then either double click the .ogx file, or select the .ogx file then click “Insert”, you will now be prompted with the following dialog:

    Double checking component insertion

  6. Click “OK”, then close the “Components and Controls Gallery” window. The class will now be inserted into your project (just like magic but better).

Look mum, a new class!

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 programming

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 files.

Here-in ends the lesson.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) TMR
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMissing virtuals and windows message option Pin
Vaclav_10-Aug-07 4:53
Vaclav_10-Aug-07 4:53 
AnswerRe: Missing virtuals and windows message option Pin
bryce10-Aug-07 13:48
bryce10-Aug-07 13:48 
GeneralMy ogx-inserted class does not appear in ClassWizard. Pin
Mojo Jojo13-Aug-03 12:04
Mojo Jojo13-Aug-03 12:04 
QuestionHow about DLLs? Pin
PerFnurt11-Jun-03 5:42
PerFnurt11-Jun-03 5:42 
Generalcool! Pin
Gilad Novik17-Feb-03 20:49
Gilad Novik17-Feb-03 20:49 
GeneralRe: cool! Pin
bryce18-Feb-03 13:47
bryce18-Feb-03 13:47 
GeneralDialog boxes Pin
Heywood13-Feb-03 6:51
Heywood13-Feb-03 6:51 
What I would find useful is adding an entire dialog box (dialog resource and class) to the gallery so that a dialog can be added to the project with one button click.

I haven't figured out if it's possible to make the gallery "resource aware"... so that if your class uses a particular resource (icon, dialog, bitmap etc.), that resource is included in the gallery files. Is this possible?


GeneralRe: Dialog boxes Pin
RancidCrabtree18-Feb-03 5:25
RancidCrabtree18-Feb-03 5:25 
GeneralGroovy....Very Groovy... Pin
Kant13-Feb-03 5:15
Kant13-Feb-03 5:15 
QuestionVS.NET version? Pin
Marc Clifton12-Feb-03 14:21
mvaMarc Clifton12-Feb-03 14:21 
AnswerRe: VS.NET version? Pin
bryce12-Feb-03 14:25
bryce12-Feb-03 14:25 
GeneralRe: VS.NET version? Pin
Big Art18-Feb-03 6:57
Big Art18-Feb-03 6:57 
GeneralRe: VS.NET version? Pin
Anonymous19-Feb-03 5:39
Anonymous19-Feb-03 5:39 
GeneralRe: VS.NET version? Pin
Big Art19-Feb-03 12:50
Big Art19-Feb-03 12:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.