adding menubar and toolbar to frame Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
anna
Earned a small fee
Earned a small fee
Posts: 23
Joined: Thu Nov 20, 2008 11:00 am

adding menubar and toolbar to frame

Post by anna »

im trying to create an acrobat plug-in.....which i did...
...here acrobat frame is the main frame....
from its menu items i select wxwidget frame.....

Code: Select all

MyFrame *frame = new MyFrame((wxFrame *)mainFrame, _T("wxWidgets Frame"));
	
	// Show the frame
	frame->Centre(wxBOTH);
    frame->Show(true);

.... (below) is the frame code.....


Code: Select all

/********************
frame.cpp

 - wxWidgets - frame

*********************************************************************/

#include "wx/app.h"
#include "wxInit.h"
#include "dialogs.h"


// My frame constructor
MyFrame::MyFrame(wxWindow *parent,const wxString& title)
       : wxFrame(parent, wxID_ANY, title)
{
	CreateStatusBar();
    	SetStatusText( "Welcome to wxWindows!" );

}

MyFrame::~MyFrame()
{

}


void MyFrame::OnClose(wxCloseEvent& event)
{
	Show(false);
	Destroy();	
}


BEGIN_EVENT_TABLE(MyFrame, wxFrame)
	EVT_CLOSE(MyFrame::OnClose)
	END_EVENT_TABLE()
adding status bar to frame was easy.....

now how do i add menubars....menuitems.... toolbar to it?
framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer »

Hi.

You should look at the samples.
But just as a quick help, you should use
wxFrame::SetMenuBar()
to add a menu bar. Just create a new menu like

Code: Select all

wxMenuBar * pMenuBar = new wxMenuBar;
pMenu = new wxMenu();
pMenu->Append(1, ("E&xit"));
pMenuBar->Append(pMenu);
pFrame->SetMenuBar(pMenuBar);
For toolbars just create a new toolbar and set it with wxFrame::SetToolBar().

But you will learn more if you look at the samples provided.

Regards
Software is like sex,
It's better when it's free.
~Linus Torvalds
chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern »

Hi,

Try this code:

Code: Select all

class MyFrame : public wxFrame 
{
	private:
	
	protected:
		wxStatusBar* m_statusBar1;
		wxMenuBar* MenuBar;
		wxMenu* menu1;
		wxMenu* menu2;
		wxToolBar* Toolbar;
		
		// Virtual event handlers, overide them in your derived class
		virtual void ToolClicked( wxCommandEvent& event ){ event.Skip(); }
		
	
	public:
		MyFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
		~MyFrame();
	
};


MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	m_statusBar1 = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
	MenuBar = new wxMenuBar( 0 );
	menu1 = new wxMenu();
	wxMenuItem* menuItem1;
	menuItem1 = new wxMenuItem( menu1, wxID_ANY, wxString( wxT("Open") ) , wxEmptyString, wxITEM_NORMAL );
	menu1->Append( menuItem1 );
	
	menu1->AppendSeparator();
	
	wxMenuItem* menuItem2;
	menuItem2 = new wxMenuItem( menu1, wxID_ANY, wxString( wxT("Save") ) , wxEmptyString, wxITEM_NORMAL );
	menu1->Append( menuItem2 );
	
	MenuBar->Append( menu1, wxT("File") );
	
	menu2 = new wxMenu();
	MenuBar->Append( menu2, wxT("Edit") );
	
	this->SetMenuBar( MenuBar );
	
	Toolbar = this->CreateToolBar( wxTB_HORIZONTAL, wxID_ANY ); 
	Toolbar->AddTool( wxID_ANY, wxT("tool"), wxNullBitmap, wxNullBitmap, wxITEM_NORMAL, wxEmptyString, wxEmptyString );
	Toolbar->Realize();
	
	
	// Connect Events
	this->Connect( wxID_ANY, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( MyFrame::ToolClicked ) );
}

MyFrame::~MyFrame()
{
	// Disconnect Events
	this->Disconnect( wxID_ANY, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( MyFrame::ToolClicked ) );
}
Chris
anna
Earned a small fee
Earned a small fee
Posts: 23
Joined: Thu Nov 20, 2008 11:00 am

Post by anna »

i tried the code... it works...
thanks....

can u tell me easier way to generate code...
i mean drag n drop.... to create all the GUI..
with wxWidgets?
chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern »

Alexis
Earned a small fee
Earned a small fee
Posts: 11
Joined: Wed Jul 02, 2008 12:24 pm

Alternate IDE with integrated GUI builder (wxSmith)

Post by Alexis »

anna
Earned a small fee
Earned a small fee
Posts: 23
Joined: Thu Nov 20, 2008 11:00 am

wxWidget tools

Post by anna »

there r other tools too... ive checked...

Open Tools:

wxFormBuilder, wxDev-C++, Code::Blocks, wxGlade, XRCed, VisualWX

Available Proprietary Tools:

wxDesigner, DialogBlocks, wxForms, uiVersalBuilder

but i want the code to be developed in WINDOWS
and later run in MAC OSX without much change...

So which one should i use... do suggest
chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern »

My top ones are: Open Source - wxFormBuilder, Commercial - DialogBlocks.

What you probably need is a "turn key" solution and I suggest you to go with DialogBlocks as it supports a lot of wx classes. I prefer wxFormBuilder because it produces simpler code but it's not as "heavy" as DialogBlocks (which BTW is made by wxWidgets creator).

Chris
Post Reply