imedghar
asked on
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_A bout, _T("&About...\tF1"), _T("Show about dialog"));
menuFile->Append(Minimal_Q uit, _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(wxCommandE vent& WXUNUSED(event))
{
// TRUE is to force the frame to close
Close(TRUE);
}
void MyFrame::OnAbout(wxCommand Event& 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);
}
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,
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_A
menuFile->Append(Minimal_Q
// 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(wxCommandE
{
// TRUE is to force the frame to close
Close(TRUE);
}
void MyFrame::OnAbout(wxCommand
{
wxString msg;
msg.Printf( _T("ModPlan.\n")
_T("Project (PG463) at Dortmund university"), NULL);
wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);
}
in your wxFrame class construcor add this:
//ToolBar
CreateToolBar(wxNO_BORDER| wxHORIZONT AL|wxTB_FL AT, -1);
wxToolBar *toolBar = GetToolBar();
toolBar->SetMargins( 2, 2 );
toolBar->AddTool(tool1, wxBitmap::wxBitmap(_T("tes t1.xpm"), wxBITMAP_TYPE_XPM), wxNullBitmap, false, 0, -1, (wxObject *) NULL, _T("New file"));
toolBar->AddSeparator();
toolBar->Realize();
//ToolBar
CreateToolBar(wxNO_BORDER|
wxToolBar *toolBar = GetToolBar();
toolBar->SetMargins( 2, 2 );
toolBar->AddTool(tool1, wxBitmap::wxBitmap(_T("tes
toolBar->AddSeparator();
toolBar->Realize();
ASKER
Hi Dariuzk,
thanks for your help, but there is something else, which doesnt work:
it gives Error bei PATH="/opt/wx/2.5/bin:.:$P ATH" . 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.
thanks for your help, but there is something else, which doesnt work:
it gives Error bei PATH="/opt/wx/2.5/bin:.:$P
I take this line away , it works and gives this Dialogsmessage:
Can´t load bitmap ´wxBITMAP_STD_COLOURS´from
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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,
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:.:$P
// ==========================
// 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_A
menuFile->Append(Minimal_Q
// 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|
GetToolBar()->SetMargins( 2, 2 );
//wxToolBar *toolBar = new wxToolBar();
GetToolBar()->AddTool(tool
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(wxCommandE
{
// TRUE is to force the frame to close
Close(TRUE);
}
void MyFrame::OnAbout(wxCommand
{
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(wxCom
{
if (event.GetSelection() > -1)
{
wxString str;
str.Printf(_T("This is tool number %d"), event.GetSelection());
SetStatusText(str);
}
else
SetStatusText(_T(""));
}