Senin, 20 Mei 2013

Xathrya Sabertooth

Xathrya Sabertooth


First wxWidget Program

Posted: 20 May 2013 03:07 AM PDT

After learning some wxWidgets basic, lets open new article for discussing a simple application.

In this article we will cover a basic in creating a wxWidget frame and show how to display an icon. Next we will create a simple example demonstrating usage of an event. Finally, we will see, how widgets communicate in wxWidgets applications.

A simple application

First we create the very basic wxWidgets program.

/** filename: simple.h **/
#include <wx/wx.h>

class Simple : public wxFrame
{
public:
Simple(const wxString& title);

};

/** filename: simple.cpp **/
#include "simple.h"

Simple::Simple(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150))
{
Centre();
}

/** filename: main.h **/
#include <wx/wx.h>

class MyApp : public wxApp
{
public:
virtual bool OnInit();
};

/** filename: main.cpp **/
#include "main.h"
#include "simple.h"

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
Simple *simple = new Simple(wxT("Simple"));
simple->Show(true);

return true;
}

a

Getting Started with wxWidgets

Posted: 20 May 2013 03:02 AM PDT

People who are completely new to wxWidgets would normally follow the steps illustrated below.

WxGettingStartedRoadmap

In this article we will set our environment for developing a wxWidget application.

Installing wxWidgets and Setting up IDE

When developing application using wxWidget, we can choose whether use helping from IDE or not. For an overview of IDEs that have been reported to work with wxWidgets, you can see the list of IDEs on wxWidgets site.

We won’t cover installation of any IDE in this section, but I would recommend you to install one.

Your main guide for compiling wxWidgets should be the installation instructions : Look in <code-base-dir>/docs/.

On Windows

<to be continued>

On Linux

Getting Started

Before getting started, make sure you have installed all necessary build tools, including g++ and autotools. You will also need gtk+ library.

It is recommended to use at least GTK+ 2.2.3, and some features are only available when using more recent version, like GTK+ 2.8.

Building and Installation

Download the wxWidget source archive from http://www.wxwidgets.org/downloads/. The latest development is recommended, and when writing this article, the latest version is version 2.9.4.

You will need to call configure to configure the compilation setting. It is also recommended to enable unicode support for wxWidgets.

  ./configure --enable-unicode  

However, if you want to compile wxWidgets on a 64-bit version of Linux in such a way that the library can be linked to both statically and dynamically, then you want to add the -fPIC flag to the configure call. That is done in the following way:

  ./configure --enable-unicode CFLAGS="-fPIC" CXXFLAGS="-fPIC"  

The options you pass to configure at this point will determine what build you get.

–enable-unicode makes a Unicode build
–with-opengl enables OpenGL support
–disable-shared builds static libs instead of shared ones
–prefix=[...] makes wxWidgets be installed in another location than default /usr/local

A list of all possible options can be seen using ./configure –help command.

If it stops saying it can’t find a package, install it (with -dev packages if any) and run configure again. When it is done without errors, you are ready to build. When the build is done, and if no error occured, you can now install it. You also need root privileges to install it.

  make  make install  

Enter your password as needed. wxWidgets will be installed in /usr/local/

On some systems it is also necesary to run sudo ldconfig at this point.

Compile an Application

The tool wx-config allows you to quickly build wxWidgets apps

  g++ `wx-config --cppflags` `wx-config --libs` widgetTest.cpp  

wx-config –cppflags returns flags necessary to compilation, wx-config –libs returns flags necessary to linking. This little example has a single file so both are used at the same time but in a bigger project compiling and linking will most likely be two different steps. (How to use g++ is beyond the scope of this document)

For more information, see article Wx-Config.

On Mac OS

<to be continued>

Tidak ada komentar:

Posting Komentar