wxWidgets教程(16)——wxMenuBar、wxToolBar与wxStatusBar用法

一、wxMenuBar

1、创建一个菜单栏,代码如下:

	wxMenuBar * m_menubar1 = new wxMenuBar(0);
	wxMenu *m_menu1 = new wxMenu();

	wxMenuItem* m_menuItem1, m_menuItem2, m_menuItem3;

	m_menuItem1 = new wxMenuItem(m_menu1, wxID_ANY, wxString(wxT("MyMenuItem")), wxEmptyString, wxITEM_NORMAL);
	m_menuItem2 = new wxMenuItem(m_menu1, wxID_ANY, wxString(wxT("MyMenuItem")), wxEmptyString, wxITEM_NORMAL);
	m_menuItem3 = new wxMenuItem(m_menu1, wxID_ANY, wxString(wxT("MyMenuItem")), wxEmptyString, wxITEM_NORMAL);

	m_menu1->Append(m_menuItem1);
	m_menu1->Append(m_menuItem2);
	m_menu1->Append(m_menuItem3);

	m_menubar1->Append(m_menu1, wxT("MyMenu"));

	this->SetMenuBar(m_menubar1);

2、右键弹出菜单

	wxMenu * menu = new wxMenu();
	menu->Append(wxID_OPEN, wxT("&Open"));
	menu->AppendSeparator();
	menu->Append(wxID_EDIT, wxT("&Edit"));
	PopupMenu(menu);
3、响应的事件表

EVT_MENU


二、wxToolBar

1、创建一个工具栏,代码如下:

	wxToolBar * toolBar = new wxToolBar(frame, wxID_ANY,wxDefaultPosition,wxDefaultSize,wxTB_HORIZONTAL|wxNO_BORDER);
	wxBitmap bmpOpen(wxImage(wxT("1.png")));
	wxBitmap bmpSave(wxImage(wxT("2.png")));
	toolBar->AddTool(wxID_OPEN, bmpOpen, wxT("Open"));
	toolBar->AddTool(wxID_SAVE, bmpSave, wxT("Save"));
	toolBar->AddSeparator();
	wxComboBox * comboBox = new wxComboBox(toolBar, ID_COMBOBOX);
	toolBar->AddControl(comboBox);
	toolBar->Realize();
	this->SetToolBar(toolBar);


三、wxStatusBar

1、创建一个状态栏,代码如下:

	wxStatusBar * m_statusBar = new wxStatusBar(this,wxID_ANY,wxST_SIZEGRIP);
	this->SetStatusBar(m_statusBar);
	int widths[] = {120,120,-1};
	m_statusBar->SetFieldsCount(WXSIZEOF(widths),widths);
	m_statusBar->SetStatusText(wxT("status text"), 0);
	m_statusBar->SetStatusText(wxT("2017-11-25"), 1);
	// 在状态栏的第三个栏中添加进度条
	wxRect rc;
	m_statusBar->GetFieldRect(2,rc);
	wxGauge * gauge = new wxGauge(m_statusBar,ID_GAUGE,200, wxPoint(rc.x,rc.y),wxSize(rc.width,rc.height),wxGA_HORIZONTAL);
	gauge->SetValue(100);
	gauge->Show(true);

	// 在OnSize中重新设置进度条的宽高
	wxRect rc;
	m_statusBar->GetFieldRect(2, rc);
	gauge->SetSize(wxSize(rc.width, rc.height));













你可能感兴趣的:(wxWidgets)