Guidance Forums / wxWidgets (wxWindows) in C++ / newbie in wxdevcpp, are there any tut's or doc's ?

Search 搜索
Home Home

Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. newbie in wxdevcpp, are there any tut's or doc's ?
Posted by: 2004-12-16 04:11:53

i am a newbie in wxdevcpp, are there any tut's or doc's ?

thx magicslider
Message2. Re: newbie in wxdevcpp, are there any tut's or doc's ?
Posted by: 2004-12-17 08:54:23
I haven't seen an tutorials other than searching the web and experimenting.  If you are familiar with Other IDE's, then this one is a breeze because it is similar to all other IDE's out there.

To Create a project, just do file->new->project and it will pretty much configure everything from that point once you choose a project type.

I prefer wxWindows (ver 2.4.2).  If you want to dink around, download the 2.4.2 devpak and add the following to a project.  It is a simple bouncing ball project and shows how to create device contexts, bitmaps and masks.

// File: __basic__.h
#ifndef __BASIC___H
#define __BASIC___H

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"

// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------

// the application icon (under Windows and OS/2 it is in resources)
#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
    #include "mondrian.xpm"

// main.h
#ifndef MAIN_H
#define MAIN_H
#include "__basic__.h"
#include "myCanvas.h"
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------

// Define a new application type, each program should derive a class from wxApp
class MyApp : public wxApp
    // override base class virtuals
    // ----------------------------

    // this one is called on application startup and is a good place for the app
    // initialization (doing it here and not in the ctor allows to have an error
    // return: if OnInit() returns false, the application terminates)
    virtual bool OnInit();

// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
    // ctor(s)
    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
            long style = wxDEFAULT_FRAME_STYLE);
    // event handlers (these functions should _not_ be virtual)
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
    int dx, dy;
    myCanvas *mc;
    wxTimer myTimer;
    void OnTimer(wxTimerEvent& event);

    // any class wishing to process wxWindows events must use this macro

// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------

// IDs for the controls and the menu commands
    // menu items
    Minimal_Quit = 1,

    // it is important for the id corresponding to the "About" command to have
    // this standard value as otherwise it won't be handled properly under Mac
    // (where it is special and put into the "Apple" menu)
    Minimal_About = wxID_ABOUT,
    // Timer Functions
    Timer_ID = -99999,
      // 1000 = 1 second, 100 = 1/10th
    TimerMS = 1

// myCanvas.h
#ifndef MYCANVAS_H
#define MYCANVAS_H
#include "__basic__.h"

#define CANVASX 640
#define CANVASY 480
#define PPUX 32
#define PPUY 32
#define UX ( CANVASX / PPUX )
#define UY ( CANVASY / PPUY )

// Define a new frame type: this is going to be our main frame
class myCanvas : public wxScrolledWindow
    // ctor(s)
    myCanvas(wxWindow *win);
    wxBitmap SetBlankBitmap(void);
    wxBitmap DrawIT(void);
    wxMask bmpMask;
    void SetY( int py );
    void SetX( int py );
    int GetX( void );
    int GetY( void );
    int y;
    int x;
    wxBitmap myBmp;
    void OnPaint(wxCommandEvent& event);
    void OnLeftDown(wxMouseEvent& event);

// main.cpp
#include "main.h"
#include "myCanvas.h"

// ----------------------------------------------------------------------------
// event tables and other macros for wxWindows
// ----------------------------------------------------------------------------

// the event tables connect the wxWindows events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
    EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
    EVT_MENU(Minimal_About, MyFrame::OnAbout)
    EVT_TIMER(Timer_ID, MyFrame::OnTimer)

// Create a new application object: this macro will allow wxWindows to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also declares the accessor function
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
// not wxApp)

// ============================================================================
// implementation
// ============================================================================

// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------

// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
    // create the main application window
    MyFrame *frame = new MyFrame(_T("Minimal wxWindows App"),
                                 wxPoint(50, 50), wxSize(660, 560));

    // and show it (the frames, unlike simple controls, are not shown when
    // created initially)

    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned FALSE here, the
    // application would exit immediately.
    return TRUE;

// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------

// frame constructor: Setup a timer object too
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
       : wxFrame(NULL, -1, title, pos, size, style), myTimer(this, Timer_ID)
    // Start the timer object with pre-defined time in milli-seconds
    // Add a new Canvas object to the frame
    mc = new myCanvas(this);
    // Set the coordinates and the Delta for the Bitmap and Motion
    dx = mc->GetX() % 10 + 1;
    dy = mc->GetY() % 10 + 1;
    // set the frame icon

    // create a menu bar
    wxMenu *menuFile = new wxMenu;

    // the "About" item should be in the help menu
    wxMenu *helpMenu = new wxMenu;
    helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("Show about dialog"));
    menuFile->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));

    // now append the freshly created menu to the menu bar...
    wxMenuBar *menuBar = new wxMenuBar();
    menuBar->Append(menuFile, _T("&File"));
    menuBar->Append(helpMenu, _T("&Help"));

    // ... and attach this menu bar to the frame
#endif // wxUSE_MENUS

    // create a status bar just for fun (by default with 1 pane only)
    SetStatusText(_T("Welcome to wxWindows!"));
#endif // wxUSE_STATUSBAR


    delete mc;      // Destroy the Canvas
    myTimer.Stop(); // Stop the timer

// event handlers

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
    // TRUE is to force the frame to close

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
    wxString msg;
    msg.Printf( _T("This is the About dialog of the minimal sample.\n")
                _T("Welcome to %s"), wxVERSION_STRING);

    wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);

void MyFrame::OnTimer(wxTimerEvent& event)
    static int i = 460;     // Starting Y coordinate
    if (i < 0)              // Reset (i) when it is ltz to bottom of canvas
       i = 460;
       // Replace the old Bitmap with a blank one
       mc->RefreshRect(wxRect(wxPoint(mc->GetX(), mc->GetY()), wxSize( 40, 40 )));
       // and draw a new one, setting Y coordinate to i
       if (mc->GetX() < 0 || mc->GetX() >= CANVASX)
         dx = - dx;
	  if (mc->GetY() < 0 || mc->GetY() >= CANVASY)
         dy = - dy;
      mc->SetX(mc->GetX() + dx);
      mc->SetY(mc->GetY() + dy);
      mc->RefreshRect(wxRect(wxPoint(mc->GetX(), mc->GetY()), wxSize( 40, 40 )));


// myCanvas.cpp
#include "myCanvas.h"

// Macro to Capture Events
BEGIN_EVENT_TABLE(myCanvas, wxScrolledWindow)

// Define a new canvas for us to draw and paint on
// Derive from Scrolled window class
myCanvas::myCanvas(wxWindow *win)
        : wxScrolledWindow( win
                           ,wxSize(CANVASX, CANVASY)
                           ,wxHSCROLL | wxVSCROLL
    // Setup the Scroll Rate and attach bars
    // to our canvas
    SetScrollbars(PPUX, PPUY, UX, UY);
    // This draws all of our initial bitmaps

// Some functions to return the coordinate
// values of where the bitmap is located
void myCanvas::SetX(int px) { x = px; }
void myCanvas::SetY(int py){ y = py; }
int myCanvas::GetX(void) { return x; }
int myCanvas::GetY(void) { return y; }

// Redraw the bitmap at some specified coordinates
void myCanvas::OnPaint(wxCommandEvent& event)
    wxPaintDC dc(this);                         // Create a device context
    PrepareDC(dc);                              // We must call prepare
                                                // or scrolling doesn't
                                                // work right
    dc.DrawBitmap(myBmp, GetX(), GetY(), true); // Draw the bitmap on the canvas

// Draw a bitmap using internal functions
// of the wxDC Class
wxBitmap myCanvas::DrawIT()
    wxMemoryDC mdc;             // Setup a context
    myBmp=wxBitmap(40, 40);     // Intialize a bitmap object
    mdc.SelectObject(myBmp);    // Select the object into the DC
    bmpMask=wxMask(myBmp, wxColour(0,0,0)); // Masking
    mdc.DrawCircle(20, 20, 20); // Draw a Circle (Ctr: 20,20 : Radus: 20)
    return myBmp;               // Return the finished bitmap

// Blank Bitmap
wxBitmap myCanvas::SetBlankBitmap()
    wxMemoryDC mdc;             // Setup a context
    myBmp=wxBitmap(40, 40);     // Intialized a bitmap object
    mdc.SelectObject(myBmp);    // Select the object into the DC
    return myBmp;               // Return the blank bitmap

void myCanvas::OnLeftDown(wxMouseEvent& event)
  wxMessageBox(_T("Click"), _T("Click"), wxOK | wxICON_INFORMATION, this);
Message3. Re: newbie in wxdevcpp, are there any tut's or doc's ?
Posted by: NinjaNL 2005-01-26 05:54:49
Currently I have written a simple beginners tutorial Beginning with wx-DevCpp which outlines using wx-DevCpp to create a simple minimal sample with toolbar and common dialogs.

Thanks to upCASE for hosting it, feel free to check it out and give me your feedback.

Should anyone require any further explanation feel free to contact me.

The tutorial is here
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
© Fri 2024-7-19  Guidance Laboratory Inc. Hits:0