// sample program to illustrate an event-driven GUI #include #include "event.h" // ********************************************************************** // file menu // ********************************************************************** class FileMenu : public VertMenu { public: MenuData *md; // menu item linked list FileMenu (); ~FileMenu () { delete md; }; virtual int ProcessKey ( char ch ); }; // set menu items and display menu FileMenu::FileMenu () : VertMenu (3, 3, 12, 7, 1) { md=new MenuData; md->AddItem (new MenuItem ("Open")); md->AddItem (new MenuItem ("-------")); md->AddItem (new MenuItem ("Exit")); InitMenu (md); } // process arrows and hotkeys int FileMenu::ProcessKey ( char ch ) { switch (ch) { case 'e' : case 'E' : return 2; case 'O' : case 'o' : anApp->OpenWindow (new MessageWindow ("Not yet implemented")); return 0; case 13 : switch (Position) // process ENTER { case 0 : anApp->OpenWindow (new MessageWindow ("Not yet implemented")); return 0; case 2 : return 2; default : return 0; } default : VertMenu::ProcessKey (ch); // process arrows return 0; } } // ********************************************************************** // main menu // ********************************************************************** class TopMenu : public HorzMenu { public: MenuData *md; // menu item linked list TopMenu (); ~TopMenu () { delete md; }; virtual int ProcessKey ( char ch ); }; // set menu item and display menu TopMenu::TopMenu () : HorzMenu (1, 1, 80, 3, 1) { md=new MenuData; md->AddItem (new MenuItem ("File")); md->AddItem (new MenuItem ("Help")); md->AddItem (new MenuItem ("About")); InitMenu (md); }; // process arrows and hotkeys int TopMenu::ProcessKey ( char ch ) { switch (ch) { case 'f' : case 'F' : anApp->OpenWindow (new FileMenu); return 0; case 'h' : case 'H' : anApp->OpenWindow (new MessageWindow ("no HELP available")); return 0; case 'a' : case 'A' : anApp->OpenWindow (new MessageWindow ("Windows Demonstration program")); return 0; case 13 : switch (Position) // process ENTER { case 0 : anApp->OpenWindow (new FileMenu); return 0; case 1 : anApp->OpenWindow (new MessageWindow ("no HELP available")); return 0; default : anApp->OpenWindow (new MessageWindow ("Windows Demonstration program")); return 0; } default : HorzMenu::ProcessKey (ch); // process arrows return 0; } } // ********************************************************************** // main program body // ********************************************************************** void main () { // create application kernel Application MyApp; // make initial windows MyApp.OpenWindow (new BWindow (1, 4, 80, 24, 1)); MyApp.OpenWindow (new StatusLine (25, "Window Demonstration :: Event-driven programming :: H. Suleman :: 1996")); MyApp.OpenWindow (new TopMenu); // start main event-processing loop MyApp.Run (); }