首页 > 代码库 > PopupMenus
PopupMenus
1 //PopupMenus.cpp 2 3 4 #include "vcf/ApplicationKit/ApplicationKit.h" 5 #include "vcf/ApplicationKit/CommandButton.h" 6 #include "vcf/ApplicationKit/DefaultMenuItem.h" 7 8 using namespace VCF; 9 10 11 class PopupMenusWindow : public Window {12 public:13 PopupMenusWindow() {14 setCaption( "PopupMenus" ); 15 16 CommandButton* cb = new CommandButton();17 cb->setBounds( 20, 20, 100, 30 );18 add( cb );19 20 cb->ButtonClicked += new ClassProcedure1<Event*,PopupMenusWindow>(this, &PopupMenusWindow::btnClick, "btnClick" );21 22 EventHandler* eh = new ClassProcedure1<Event*,PopupMenusWindow>(this, &PopupMenusWindow::onMenuItemClicked, "onMenuItemClicked" );23 24 25 PopupMenu* popupMenu = new PopupMenu( this );26 MenuItem* root = popupMenu->getRootMenuItem();27 28 setPopupMenu( popupMenu );29 30 for (int i=1;i<=10;i++ ) {31 MenuItem* item = 32 new DefaultMenuItem( Format("Context Menu Item %d") % i, root,popupMenu );33 item->MenuItemClicked += getCallback( "onMenuItemClicked" );34 }35 36 }37 38 virtual ~PopupMenusWindow(){};39 40 void btnClick( Event* e ) {41 PopupMenu* popupMenu = new PopupMenu( this );42 43 MenuItem* root = popupMenu->getRootMenuItem();44 45 46 for (int i=1;i<=10;i++ ) {47 MenuItem* item = 48 new DefaultMenuItem( Format("Menu Item %d") % i, root,popupMenu );49 item->MenuItemClicked += getCallback( "onMenuItemClicked" );50 }51 52 Point pt(20, 50);53 popupMenu->popup( &pt );54 55 removeComponent( popupMenu );56 popupMenu->free();57 }58 59 void onMenuItemClicked( Event* e ) {60 MenuItem* item = (MenuItem*)e->getSource();61 Dialog::showMessage( Format("Menu item \"%s\" clicked!") % item->getCaption() );62 }63 };64 65 66 67 68 class PopupMenusApplication : public Application {69 public:70 71 PopupMenusApplication( int argc, char** argv ) : Application(argc, argv) {72 73 }74 75 virtual bool initRunningApplication(){76 bool result = Application::initRunningApplication();77 78 Window* mainWindow = new PopupMenusWindow();79 setMainWindow(mainWindow);80 mainWindow->setBounds( 100.0, 100.0, 500.0, 500.0 );81 mainWindow->show();82 83 return result;84 }85 86 };87 88 89 int main(int argc, char *argv[])90 {91 Application* app = new PopupMenusApplication( argc, argv );92 93 Application::main();94 95 return 0;96 }
PopupMenus
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。