A Mozilla-like about box.

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
zoom
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Oct 22, 2008 3:23 pm
Location: France

A Mozilla-like about box.

Post by zoom » Sat Oct 25, 2008 1:16 pm

Because i needed an about box and those i found was not wonderful, i created a class that provides to me a well-rounded about box.

You'll find below the piece of code. Images are not provided, but i embedded them by using the very nice bin2c software.

Code: Select all

/**********************************************************************
 * Description:     aboutDialog header
 * Author(s):       zoom
 * Last modif.:     23/10/08
 * Licence:         linkware, just put a reference to askorn.free.fr
*********************************************************************/

#ifndef _CLASS_ABOUTDIALOG_H_
#define _CLASS_ABOUTDIALOG_H_

#include <wx/bitmap.h>
#include <wx/statline.h>
#include <wx/mstream.h>

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#define wxGetBitmapFromMemory(name) _wxGetBitmapFromMemory( name ##_png, sizeof( name ## _png) )


#include "blank.cpp" /*The embedded white background*/
#include "backgr.cpp"/*The embedded background picture */
#include "img_cachee2.cpp"/*The embedded easteregg picture*/

#include "version.h"/*C::B Autoversionning plugin creates this*/

//Some vars
//wxString wsAppName = wxT("Mascott");
wxString wsAppMaker = _("CompanyName");
wxString wsAppCopyDate = _("2008");

/*inline fonction*/
inline wxBitmap _wxGetBitmapFromMemory( const unsigned char *data, int length)
{
    wxMemoryInputStream is( data, length);
    return wxBitmap( wxImage( is, wxBITMAP_TYPE_ANY, -1), -1);
}


enum
{
    ID_ABOUT_WXBUTTONOK = 4101,
    ID_ABOUT_WXBUTTONREGISTER = 4102,

};


//My aboutDialog class
class
aboutDialog : public wxDialog
{
public:
    	aboutDialog(wxWindowID id,  bool bRegistering = false, bool bEasterEgg = false);
	void OnClose( wxCommandEvent& event );
    	void OnBoutonOK( wxCommandEvent& event );


private:
	DECLARE_EVENT_TABLE();
        bool bIsRegistered;
	wxString wsRegisterMessage;


};

//----------------------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------------------
aboutDialog::aboutDialog(wxWindowID id, bool bRegistering, bool bEasterEgg)
                  : wxDialog(NULL,id,_("About AppName"),wxDefaultPosition, wxSize(300,425), wxDEFAULT_DIALOG_STYLE,wxT("myAboutFrame"))
{
    //Your product is registered?
    bIsRegistered = true;

    //Init all image handlers...
    wxInitAllImageHandlers();

    //Load white bg
    wxStaticBitmap *mySBBlank = new wxStaticBitmap(this, -1, wxGetBitmapFromMemory( blank ), wxPoint(0,-8));

    //Load bg picture
    wxStaticBitmap *mySBBackGround = new wxStaticBitmap(this, -1, (bEasterEgg) ? wxGetBitmapFromMemory( img_cachee2 ) : wxGetBitmapFromMemory( backgr ), wxPoint(0,-20));

    //Write the application name
    wxStaticText *myAppName = new wxStaticText(this, -1, _("AppName"), wxPoint(12,150), wxSize(200,40), 0, wxT("myAppName"));
    myAppName->SetFont(wxFont(28, wxSWISS, wxBOLD, wxFONTFLAG_ANTIALIASED, false, wxT("Arial")));
    myAppName->SetBackgroundColour( wxT("WHITE") );
    myAppName->SetForegroundColour( wxColour( 220, 0, 0 ) );

    //Create version string
    wxString wsAppVersion2;
    wsAppVersion2.Printf(_("version %.2f%s"), AutoVersion::UBUNTU_VERSION_STYLE, AutoVersion::STATUS_SHORT);

    //Write the app version
    wxStaticText *myAppVersion = new wxStaticText(this, -1, wsAppVersion2, wxPoint(15,myAppName->GetPosition().y+35), wxSize(200,40), 0, wxT("myAppVersion"));
    myAppVersion->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxFONTFLAG_ANTIALIASED, false, wxT("Arial")));
    myAppVersion->SetBackgroundColour( wxT("WHITE") );
    myAppVersion->SetForegroundColour( wxColour( 200, 200, 200 ) );

    //Write text about copyrights... or anything you want
    wxStaticText *myAppCopyright = new wxStaticText(this,
                                                    -1,
                                                    _("© ") + wsAppCopyDate + _(" ") + wsAppMaker + _(". All rights reserved.\nBla Bla Bla www.wxwidgets.org."),
                                                    wxPoint(myAppVersion->GetPosition().x,myAppVersion->GetPosition().y+40),
                                                    wxSize(200,100),
                                                    0,
                                                    wxT("myAppCopyright"));
    myAppCopyright->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxFONTFLAG_ANTIALIASED, false, wxT("Arial")));
    myAppCopyright->Wrap((int)(this->GetSize().x-2*15));
    myAppCopyright->SetBackgroundColour( wxT("WHITE") );
    myAppCopyright->SetForegroundColour( wxColour( 0, 0, 0 ) );

    wxString wsAppInfo;
    wsAppInfo.Printf(_("Build %d"), AutoVersion::BUILDS_COUNT);

    //Write build info
    wxStaticText *myAppInfo = new wxStaticText(this, -1, wsAppInfo + _(" (Windows; Unicode; Windows NT 5.1; Fr; wxWidgets 2.8.8)"), wxPoint(myAppVersion->GetPosition().x,myAppCopyright->GetPosition().y+70), wxSize(20,100), 0, wxT("myAppInfo"));
    myAppInfo->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxFONTFLAG_ANTIALIASED, false, wxT("Arial")));
    myAppInfo->Wrap((int)(this->GetSize().x-2*15));
    myAppInfo->SetBackgroundColour( wxT("WHITE") );
    myAppInfo->SetForegroundColour( wxColour( 0, 0, 0 ) );

    //Static line
    wxStaticLine *myStaticLine = new wxStaticLine(this, -1, wxPoint(0,this->GetSize().y-78), wxSize(this->GetSize().x,2), wxLI_HORIZONTAL, wxT("staticLine"));

    //Button 'OK'
	wxButton *myButtonOK = new wxButton(this, ID_ABOUT_WXBUTTONOK, _("OK"), wxPoint(this->GetSize().x-70-15,this->GetSize().y-50-15), wxSize(70,23), 0, wxDefaultValidator, wxT("myBOK"));
	myButtonOK->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

    //You wish to register your product
    if( bRegistering )
    {
        //Button 'Enregistrer'=>'Register'
        wxButton *myButtonRegister = new wxButton(this, ID_ABOUT_WXBUTTONREGISTER, _("&Enregistrer..."), wxPoint(10,this->GetSize().y-50-15), wxSize(80,23), 0, wxDefaultValidator, wxT("myBREGISTER"));
        myButtonRegister->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

        //Si le produit est immatriculé on affiche la clef/If the product is registered we display its key
        //(bIsRegistered) ? myButtonRegister->Disable() : myButtonRegister->Enable();

        if( bIsRegistered )
        {
            wsRegisterMessage = _("3O30-P399-TYR8-xxxx");
            myButtonRegister->Disable();
        }
        else //Sinon on demande de l'enregistrer
        {
            wsRegisterMessage = _("PLEASE REGISTER!");
            myButtonRegister->Enable();
        }

        //Write user info
        wxStaticText *myAppUser = new wxStaticText(this, -1, _("UserID: Wixy Jets - Key: ") + wsRegisterMessage, wxPoint(myAppInfo->GetPosition().x,myStaticLine->GetPosition().y-14), wxSize(20,100), 0, wxT("myAppUser"));
        myAppUser->SetFont(wxFont(7, wxSWISS, wxNORMAL,wxFONTFLAG_ANTIALIASED, false, wxT("Courier New")));
        //myAppUser->Wrap((int)(this->GetSize().x-2*15));
        myAppUser->SetBackgroundColour( wxT("WHITE") );
        myAppUser->SetForegroundColour( wxColour( 0, 0, 0 ) );
    }

}
//---------------------------------------------------------------------------------------------------------
void
aboutDialog::OnClose( wxCommandEvent& WXUNUSED(event) )
{
	Close(TRUE);
}


//---------------------------------------------------------------------------------------------------------
void
aboutDialog::OnBoutonOK( wxCommandEvent& WXUNUSED(event) )
{
	Close(TRUE);
}
//---------------------------------------------------------------------------------------------------------
#endif
See below the rendering:

Image

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver » Thu Nov 20, 2008 1:30 pm

Wow !!! This seems to be very pretty ;)

It will test it ASAP ! Thanks and great work !

Just few questions by reading your code:

- Is there a way to get dynamically these information:
OS Version : Windows;
WxWidgets version: Unicode;
OS Version ID: Windows NT 5.1;
Langage: Fr;
wxWdigets build: wxWidgets 2.8.8

Is there a way to retrieve some of these information dynamically ?

- What is AutoVersion:: and how to use it / find information about it, particulary AutoVersion::BUILDS_COUNT ?

Thanks
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

zoom
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Oct 22, 2008 3:23 pm
Location: France

Post by zoom » Sat Dec 06, 2008 12:48 pm

Hi Muetdhiver (are you French: Muet d'Hiver), sorry for the late (I saw your private message).
About getting dynamically these information i have two answers: yes and no :D

YES:
I think 'OS Version' and 'WxWidgets version' could be got by using this code:

Code: Select all

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__WXMAC__)
        wxbuild << _T("-Mac");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}
This code is provided 'as is' by Code::Blocks, but I don't use it.

The 'OS Version ID' could be taken by using this wxwidget function: wxGetOsDescription() which returns a wxString.

NO:(or perhaps because I don't know how to do that ) :oops:
I write myself the language and wxWdigets build.

ABOUT AUTOVERSION:

It's a very nice plugin for code::blocks that provides a header ('version.h') with the current version of your software.

And thanks for your interest. :wink:

zoom
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Oct 22, 2008 3:23 pm
Location: France

Post by zoom » Sun Dec 07, 2008 11:08 am

There is a mistake within what I said.
I write myself the language and wxWdigets build.
I found how to get the wxWidgets build. Use:

Code: Select all

wxVERSION_STRING
For me, this wxString is wxWidgets 2.8.8.

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver » Fri Dec 12, 2008 8:33 am

Hi !!!

Thanks for your answer. I will test this as soon as posible !
If I have new questions I will send you a new MP !

On pourrait d'ailleurs parler en Francais, en effet :) !!
C'est rare ici bas !
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver » Tue Jan 27, 2009 5:14 pm

I used your code !!
It has a pretty nice look:

Image

Again thanks !
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Post by orbitcowboy » Thu Jan 29, 2009 10:15 pm

Muetdhiver wrote:I used your code !!
It has a pretty nice look:

Image

Again thanks !
Is it possible to share your code with us? It looks very good. I am asking, because i need something similar in my project.

Thanks in advance.

Regards

Orbitcowboy

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Post by Muetdhiver » Sun Feb 01, 2009 7:50 pm

Hello orbitcowboy. I just used the code provided by zoom. There is not big differences. Here is the code:

HEADER:

Code: Select all

/**********************************************************************
 * Description:     aboutDialog header
 * Author(s):       zoom
 * Last modif.:     23/10/08
 * Licence:         linkware, just put a reference to askorn.free.fr
*********************************************************************/

#ifndef _CLASS_ABOUTDIALOG_H_
#define _CLASS_ABOUTDIALOG_H_

#include <wx/bitmap.h>
#include <wx/statline.h>
#include <wx/mstream.h>

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

enum
{
    ID_ABOUT_WXBUTTONOK = 4101,
    ID_ABOUT_WXBUTTONREGISTER = 4102,
};


//My aboutDialog class
class
aboutDialog : public wxDialog
{
public:
        aboutDialog(wxWindowID id,  bool bRegistering = false, bool bEasterEgg = false);
        void OnClose( wxCommandEvent& event );
        void OnBoutonOK( wxCommandEvent& event );


private:
        DECLARE_EVENT_TABLE();
        bool bIsRegistered;
        wxString wsRegisterMessage;
};

#endif
BODY

Code: Select all

#include "stdafx.h"
#include "AboutDialog.h"
#include "TVersion.h"

BEGIN_EVENT_TABLE(aboutDialog, wxDialog)
	EVT_BUTTON		( ID_ABOUT_WXBUTTONOK,				aboutDialog::OnBoutonOK )
END_EVENT_TABLE()

//----------------------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------------------
aboutDialog::aboutDialog(wxWindowID id, bool bRegistering, bool bEasterEgg)
                  : wxDialog(NULL,id,_S(TLang::Get("about")),wxDefaultPosition, wxSize(300,425), wxDEFAULT_DIALOG_STYLE )
{
    //Your product is registered?
    bIsRegistered = true;

    //Load white bg
    wxImage loc_o_blank_image = wxImage( _T( "Images/About_Blank.jpg" ), wxBITMAP_TYPE_JPEG);
    (void*) new wxStaticBitmap(this, -1, wxBitmap( loc_o_blank_image ), wxPoint(0, 138));

    //Load bg picture
    wxImage loc_o_background_image = wxImage( _T( "Images/About_Background.jpg" ), wxBITMAP_TYPE_JPEG);
    (void*) new wxStaticBitmap(this, -1, wxBitmap( loc_o_background_image ), wxPoint(0,0));

    //Write the application name
    wxStaticText *myAppName = new wxStaticText(this, -1, _S(TVersion::Get_Program_Name()), wxPoint(12,150), wxSize(200,40), 0 );
    myAppName->SetFont(wxFont(28, wxSWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxT("Arial")));
    myAppName->SetBackgroundColour( wxT("WHITE") );
    myAppName->SetForegroundColour( wxColour( 220, 0, 0 ) );

    //Write the app version
    wxStaticText *myAppVersion = new wxStaticText(this, -1, _S(TVersion::Get_Version_Long()), wxPoint(15,myAppName->GetPosition().y+35), wxSize(200,40), 0);
    myAppVersion->SetFont(wxFont(8, wxSWISS, wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL, false, wxT("Arial")));
    myAppVersion->SetBackgroundColour( wxT("WHITE") );
    myAppVersion->SetForegroundColour( wxColour( 120, 120, 120 ) );

    //Write text about copyrights... or anything you want
    wxStaticText *myAppCopyright = new wxStaticText(this,
                                                    -1,
                                                    _("© ") + _S(TVersion::Get_Program_Dates()) + _(" - ") + _S(TVersion::Get_Program_Owner()) + _S(TLang::Get("copyright")),
                                                    wxPoint(myAppVersion->GetPosition().x,myAppVersion->GetPosition().y+40),
                                                    wxSize(200,100),
                                                    0,
                                                    wxT("myAppCopyright"));
    myAppCopyright->SetFont(wxFont(8, wxSWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Arial")));
    myAppCopyright->Wrap((int)(this->GetSize().x-2*15));
    myAppCopyright->SetBackgroundColour( wxT("WHITE") );
    myAppCopyright->SetForegroundColour( wxColour( 0, 0, 0 ) );

    // Retrieve OS and version info:
    wxString wxBuild ;
    #if defined(__WXMSW__)
        wxBuild << _T("Windows");
    #elif defined(__WXMAC__)
        wxBuild << _T("Mac");
    #elif defined(__UNIX__)
        wxBuild << _T("Linux");
    #endif

    #if wxUSE_UNICODE
        wxBuild << _T("; Unicode build");
    #else
        wxBuild << _T("; ANSI build");
    #endif // wxUSE_UNICODE
    wxBuild << _T("; ") << wxGetOsDescription() << _T("; ") << _S(TLang::Get_Instance().Get_Language()) << _T("; ") << wxVERSION_STRING ;

    //Write build info
    wxStaticText *myAppInfo = new wxStaticText(this, -1, wxBuild, wxPoint(myAppVersion->GetPosition().x,myAppCopyright->GetPosition().y+125), wxSize(20,100), 0);
    myAppInfo->SetFont(wxFont(8, wxSWISS, wxFONTSTYLE_NORMAL, wxNORMAL, false, wxT("Arial")));
    myAppInfo->Wrap((int)(this->GetSize().x-2*15));
    myAppInfo->SetBackgroundColour( wxT("WHITE") );
    myAppInfo->SetForegroundColour( wxColour( 0, 0, 0 ) );

    //Static line
    wxStaticLine *myStaticLine = new wxStaticLine(this, -1, wxPoint(0,this->GetSize().y-78), wxSize(this->GetSize().x,2), wxLI_HORIZONTAL, wxT("staticLine"));

    //Button 'OK'
        wxButton *myButtonOK = new wxButton(this, ID_ABOUT_WXBUTTONOK, _("OK"), wxPoint(this->GetSize().x-70-15,this->GetSize().y-50-15), wxSize(70,23), 0, wxDefaultValidator, wxT("myBOK"));
        myButtonOK->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

    //You wish to register your product
    if( bRegistering )
    {
        //Button 'Enregistrer'=>'Register'
        wxButton *myButtonRegister = new wxButton(this, ID_ABOUT_WXBUTTONREGISTER, _("&Enregistrer..."), wxPoint(10,this->GetSize().y-50-15), wxSize(80,23), 0, wxDefaultValidator, wxT("myBREGISTER"));
        myButtonRegister->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

        //Si le produit est immatriculé on affiche la clef/If the product is registered we display its key
        //(bIsRegistered) ? myButtonRegister->Disable() : myButtonRegister->Enable();

        if( bIsRegistered )
        {
            wsRegisterMessage = _("3O30-P399-TYR8-xxxx");
            myButtonRegister->Disable();
        }
        else //Sinon on demande de l'enregistrer
        {
            wsRegisterMessage = _("PLEASE REGISTER!");
            myButtonRegister->Enable();
        }

        //Write user info
        wxStaticText *myAppUser = new wxStaticText(this, -1, _("UserID: Wixy Jets - Key: ") + wsRegisterMessage, wxPoint(myAppInfo->GetPosition().x,myStaticLine->GetPosition().y-14), wxSize(20,100), 0, wxT("myAppUser"));
        myAppUser->SetFont(wxFont(7, wxSWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Courier New")));
        //myAppUser->Wrap((int)(this->GetSize().x-2*15));
        myAppUser->SetBackgroundColour( wxT("WHITE") );
        myAppUser->SetForegroundColour( wxColour( 0, 0, 0 ) );
    }

}
//---------------------------------------------------------------------------------------------------------
void
aboutDialog::OnClose( wxCommandEvent& WXUNUSED(event) )
{
        Close(TRUE);
}


//---------------------------------------------------------------------------------------------------------
void
aboutDialog::OnBoutonOK( wxCommandEvent& WXUNUSED(event) )
{
        Close(TRUE);
}
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

zoom
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Oct 22, 2008 3:23 pm
Location: France

Post by zoom » Fri Feb 13, 2009 9:22 am

Thanks for using my code muetdhiver. Your about-box looks very nice! 8)

Post Reply