Click here to Skip to main content
Click here to Skip to main content

Hello World with the VCF

, 4 Jun 2002
Rate this:
Please Sign up or sign in to vote.
A Hello World example to introduce the Visual Component Framework.

About the Visual Component Framework

The Visual Component Framework was inspired by the ease of use of environments like NeXTStep's Interface Builder, Java IDE's like JBuilder, Visual J++, and Borland's Delphi and C++ Builder. I wanted a generic C++ class framework I could use to build apps quickly and visually (when designing GUIs), as well as having the core of the framework be as cross platform as possible. The Visual Component Framework is an Open Source project, so feel free to grab and use it if you think it might be useful. If you're really adventuresome, you can volunteer to help develop it, making it even better, especially in tying it into the VC++ environment as an add-in. For more information on either the project, helping out, or just browsing the doxygen generated documentation, please go to the VCF project on Source Forge here, or the project website. The code is available from CVS (follow the how-to here for setting up CVS on Windows), or a tar.gz file in files section of the project.

Introduction

This article will explain the very basics of creating a Hello World application with the Visual Component Framework. The Visual Component Framework (VCF) is designed to be a free, open, modern C++ framework, that while currently only runs on Win32, is architected to be relatively easy to port to other platforms, particularly Linux and Mac OSX. It is easy to use, and has an API similar to Java. With that said, let's get the ball rolling!

This simple application will demonstrate creating a VCF::Application instance and displaying a main window, with "Hello World" in its caption bar.

The simplest full VCF application, in other words, one that uses the Application class as its starting point, as opposed to just using certain pieces of it, needs only a few lines of code in a standard C main function, like the following:

int main(int argc, char *argv[])
{
    Application app;

    Application::appMain( argc, argv );
}

Those two lines of code are all that is needed to create your app instance on the stack, and then start the app running by calling the static Application::appMain() function. If you are using the VCF Application class features, like we are here, then there can only be one instance of an Application derived class for the running process, much like the restrictions that apply to MFC's CWinApp. Once you have this instance, it is necessary to start the app up by calling Application::appMain() function, passing in the number of arguments and the argument array of strings. This is processed internally and calls the application's initRunningApplication() and then the run loop, which starts the message pump up. From there on in, you are processing Windows messages.

Well, this by itself is not that interesting, so let's add a window.

int main(int argc, char *argv[])
{
    Application app;

    Window* mainWindow = new Window();

    Application::appMain( argc, argv );
}

This creates our new window on the heap. This is the preferred way of creating most objects in the VCF, with a few exceptions. Next, we need to set the application's main window. In doing this, the application is able to register itself as a listener to the Windows window events (via a call to addWindowListener()), and will be notified when the window closes itself. At this point, the application will in turn terminate itself cleanly and shut down. Failure to do this will prevent the application of being notified to close correctly, and it will not be able to free up the heap based memory for the Window object.

int main(int argc, char *argv[])
{
    Application app;

    Window* mainWindow = new Window();

    app.setMainWindow( mainWindow );

    Application::appMain( argc, argv );
}

Well, this is still pretty boring, so let's set the window's caption and then display it.

int main(int argc, char *argv[])
{
    Application app;

    Window* mainWindow = new Window();

    app.setMainWindow( mainWindow );

    mainWindow->setCaption( "Hello World" );

    mainWindow->show();

    Application::appMain( argc, argv );
}

And there you have it: a window will magically display itself, with a caption that reads "Hello World". The caption is set via the setCaption() method, and the window is made visible via the show() method. Alternatively, we could have made the window visible by calling the setVisible() with a true bool value.

Most of this was pretty easy, with the only odd thing the missing WinMain(). This is circumvented by setting some custom linker settings: in the output section of the project setting's Link tab, you specify mainCRTStartup as the Entry-point symbol, and make sure your /subsystem flag is set to /subsystem:windows, not /subsystem:console. With this set, you can go about your merry way and still use main() just like normal.

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

Share

About the Author

Jim Crafton
Software Developer (Senior)
United States United States
Currently working on the Visual Component Framework, a really cool C++ framework. Currently the VCF has millions upon millions upon billions of Users. If I make anymore money from it I'll have to buy my own country.

Comments and Discussions

 
GeneralMy Vote of " 1 " Pinmemberaljodav19-Nov-09 10:35 
GeneralNo mention of #include PinsussAnonymous5-Nov-04 2:27 
GeneralRe: No mention of #include PinmemberJim Crafton5-Nov-04 10:50 
GeneralNice work !!! Pinsussink958318-Mar-04 16:32 
GeneralRe: Nice work !!! PinmemberJim Crafton19-Mar-04 18:40 
GeneralShould have being better... PinmemberPaul Selormey4-Jun-02 19:07 
GeneralRe: Should have being better... PinmemberJim Crafton5-Jun-02 4:54 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 5 Jun 2002
Article Copyright 2002 by Jim Crafton
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid