LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-05-2013, 10:26 PM   #1
narc
Member
 
Registered: Aug 2004
Location: Montréal
Distribution: Linux from scratch
Posts: 68

Rep: Reputation: 15
wxWidgets menu event not triggered


Hello.

This program cannot be simpler. A menu bar with a menu item and two sub-menus. Sub-menus should simply fire a menu event (in this case a simple output to stdout, it could have been a dialog but I removed it for a simpler example). Everything else works great. I followed pretty much all standard tutorials on the 'net but I don't know what I'm missing here. Can anyone help ?

Using Ubuntu 12.04, standard apt-get'ted g++ and wx-common.

Thanks.

Code:
#include <iostream>
#include <wx/wx.h>

class PtFrame : public wxFrame 
{
	private:
	
	protected:
		wxMenuBar* m_menubar1;
		wxMenu* m_menuConnect;
		wxMenu* m_menuAsServer;
		wxMenu* m_menuAsClient;
		wxStatusBar* m_statusBar1;
	
	public:
		
		PtFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 944,710 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
		~PtFrame();
		void OnConnectServer(wxCommandEvent & event);
		void OnConnectClient(wxCommandEvent & event);

		DECLARE_EVENT_TABLE()
};

enum
{
	ID_MENU_SERVER = 1,
	ID_MENU_CLIENT
};

BEGIN_EVENT_TABLE (PtFrame, wxFrame)
	EVT_MENU ( ID_MENU_SERVER, PtFrame::OnConnectServer)
	EVT_MENU ( ID_MENU_CLIENT, PtFrame::OnConnectClient)
END_EVENT_TABLE()

PtFrame::PtFrame( 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 );
	
	wxBoxSizer* bSizer2;
	bSizer2 = new wxBoxSizer( wxVERTICAL );
	
	this->SetSizer( bSizer2 );
	this->Layout();
	m_menubar1 = new wxMenuBar( 0 );
	m_menuConnect = new wxMenu();
	m_menuAsServer = new wxMenu();
	m_menuConnect->Append( ID_MENU_SERVER, wxT("as Server"), m_menuAsServer );
	
	m_menuAsClient = new wxMenu();
	m_menuConnect->Append( ID_MENU_CLIENT, wxT("as Client"), m_menuAsClient );
	
	m_menubar1->Append( m_menuConnect, wxT("Connect") );

	this->SetMenuBar( m_menubar1 );
	
	m_statusBar1 = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
}

PtFrame::~PtFrame()
{
}

void PtFrame::OnConnectServer( wxCommandEvent& WXUNUSED( event ) )
{
	std::cout << "Server connect" << std::endl;
}

void PtFrame::OnConnectClient( wxCommandEvent& WXUNUSED( event ) )
{
	std::cout << "Client connect" << std::endl;
}

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

IMPLEMENT_APP(wxMyApp);

bool wxMyApp::OnInit()
{
	PtFrame *frame = new PtFrame(NULL, wxID_ANY, wxT("Simple Connection Demo"), wxDefaultPosition, wxSize(350, 250));
	frame->Show(true);
	return true;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] acpi event triggered sleep shuts down twice with USB mouse connected neonsignal Linux - Newbie 1 04-29-2011 07:09 PM
wxwidgets / wxpython drawing problems with onPaint event browny_amiga Programming 5 02-13-2009 01:56 PM
Fire Event from other event in Visual C++ Express Edition chrisliando Programming 1 11-08-2007 05:12 PM
[wxWidgets] how to unfroze the GUI while the event is running? sylvaticus Programming 10 10-24-2006 02:57 PM
java-gnome Menu click event(nothing happens) rmanocha Programming 0 09-18-2004 03:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration