[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

wxToolBar in wxwindows

Hi,
I´m programming an editor but with own toolbar (not these from windows), but I dont Know how to create an empty toolbar, and how to add Bitmaps to my own toolbar !!

Thank you in advance for your help.
here is the programm (written with DevC++) wher I have only a menu bar:

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

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

// 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"
#endif

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

// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
    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);

private:
    DECLARE_EVENT_TABLE()
};


// IDs for the controls and the menu commands
enum
{
    // menu items
    Minimal_Quit = 1,
    Minimal_About = wxID_ABOUT
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
    EVT_MENU(Minimal_About, MyFrame::OnAbout)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

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


// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
    // create the main application window
    MyFrame *frame = new MyFrame(_T("ModPlan Workbench"),
                                 wxPoint(50, 50), wxSize(650, 540));
    frame->Show(TRUE);
    return TRUE;
}

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

// frame constructor
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
       : wxFrame(NULL, -1, title, pos, size, style)
{


#if wxUSE_MENUS
    // create a menu bar
    wxMenu *menuFile = new wxMenu;
    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
    SetMenuBar(menuBar);
#endif // wxUSE_MENUS

//CreateMyToolbar();
    wxToolBar *toolBar = new wxToolBar();

// ??????????????????

#if wxUSE_STATUSBAR
    // create a status bar just for fun (by default with 1 pane only)
    CreateStatusBar(2);
    SetStatusText(_T("Welcome to ModPlan Workbech!"));
#endif // wxUSE_STATUSBAR
}


// event handlers

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

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    wxString msg;
    msg.Printf( _T("ModPlan.\n")
                _T("Project (PG463) at Dortmund university"), NULL);

    wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);
}
0
imedghar
Asked:
imedghar
  • 3
1 Solution
 
DariuzkCommented:
Hi  imedghar,

here is your toolbar example:


#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

// 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"
#endif

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

// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
    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);
    void OnToolEnter(wxCommandEvent& event);

private:
    DECLARE_EVENT_TABLE()
};


// IDs for the controls and the menu commands
enum
{
    // menu items
    Minimal_Quit = 1,
    Minimal_About = wxID_ABOUT,
    tool1
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
    EVT_MENU(Minimal_About, MyFrame::OnAbout)
    EVT_TOOL(tool1, MyFrame::OnToolEnter)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

PATH="/opt/wx/2.5/bin:.:$PATH"
// ============================================================================
// implementation
// ============================================================================


// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
    // create the main application window
    MyFrame *frame = new MyFrame(_T("ModPlan Workbench"),
                                 wxPoint(50, 50), wxSize(650, 540));
    frame->Show(TRUE);
    return TRUE;
}

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

// frame constructor
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
       : wxFrame(NULL, -1, title, pos, size, style)
{


#if wxUSE_MENUS
    // create a menu bar
    wxMenu *menuFile = new wxMenu;
    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
    SetMenuBar(menuBar);
#endif // wxUSE_MENUS

#if wxUSE_TOOLBAR
//CreateMyToolbar();
     // Create the toolbar
  CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, -1);//ID_TOOLBAR);
  GetToolBar()->SetMargins( 2, 2 );
  //wxToolBar *toolBar = new wxToolBar();
  GetToolBar()->AddTool(tool1, wxBitmap::wxBitmap(_T("test1.xpm"), wxBITMAP_TYPE_XPM), wxNullBitmap, false, 0, -1, (wxObject *) NULL, _T("New file"));
  GetToolBar()->AddSeparator();
  GetToolBar()->Realize();
  //  SetToolBar(toolBar);

// ??????????????????
#endif // wxUSE_TOOLBAR

#if wxUSE_STATUSBAR
    // create a status bar just for fun (by default with 1 pane only)
    CreateStatusBar(2);
    SetStatusText(_T("Welcome to ModPlan Workbech!"));
#endif // wxUSE_STATUSBAR
}


// event handlers

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

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    wxString msg;
    msg.Printf( _T("ModPlan.\n")
                _T("Project (PG463) at Dortmund university"), NULL);

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

void MyFrame::OnToolEnter(wxCommandEvent& event)
{
  if (event.GetSelection() > -1)
  {
    wxString str;
    str.Printf(_T("This is tool number %d"), event.GetSelection());
    SetStatusText(str);
  }
  else
    SetStatusText(_T(""));

}
0
 
DariuzkCommented:
in your wxFrame class construcor add this:
//ToolBar
       
      CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, -1);
        wxToolBar    *toolBar  = GetToolBar();
      toolBar->SetMargins( 2, 2 );
      toolBar->AddTool(tool1, wxBitmap::wxBitmap(_T("test1.xpm"), wxBITMAP_TYPE_XPM), wxNullBitmap, false, 0, -1, (wxObject *) NULL, _T("New file"));
      toolBar->AddSeparator();
      toolBar->Realize();
0
 
imedgharAuthor Commented:
Hi Dariuzk,

thanks for your help, but there is something else, which doesnt work:
it gives Error bei  PATH="/opt/wx/2.5/bin:.:$PATH"  . what do you mean with it ??
I take this line away , it works and gives this Dialogsmessage:
Can´t load bitmap ´wxBITMAP_STD_COLOURS´from resources! Check .rc file !!!

so Ichecked the Toolbar_private.rc file (generated from devC++) , and there is:
// THIS FILE WILL BE OVERWRITTEN BY DEV-C++!
// DO NOT EDIT!
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "Toolbar.ico"

I hope some one can help me with this. Thanks in advance.
0
 
DariuzkCommented:
PATH="/opt/wx/2.5/bin:.:$PATH" <- this is just bad paste, delete this line
_T("test1.xpm"), wxBITMAP_TYPE_XPM <- chnge this (I am in linux and I am using xpm picture test1.xpm)
_T("<your bmp picture file name>"), wxBITMAP_TYPE_BMP <- to this  
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now