#include #include using namespace wkgl; /////////////////////////////////////////////////////////////////////////////// ///Prototypes BOOL onNew(MenuItem* item, UINT message); //New menuitem callback BOOL onSave(MenuItem* item, UINT message);//Save menuitem callback BOOL onExit(MenuItem* item, UINT message);//Exit menuitem callback void createMenu( MenuBar& mbar ); //Create Menubar function /////////////////////////////////////////////////////////////////////////////// ///Global components MultilineEdit* me; //Edit window /////////////////////////////////////////////////////////////////////////////// ///Main function WPARAM main() { Window win( "Menu Bar Test" ); //Create the menu bar me = new MultilineEdit( 0, 0, 0, 0 ); //Create the edit window MenuBar mbar( &win ); //Create the menu bar createMenu( mbar ); //Add the menu items win.setMenuBar( &mbar ); //Set the menu bar win.add( me ); //Add the edit window win.show(); //Show the window //Set the edit window to the size of the window me->setSize( win.getWidth(), win.getHeight() ); //Start processing WPARAM param = win.beginMessageLoop(); //Delete the edit window delete me; return param; } /////////////////////////////////////////////////////////////////////////////// ///Create the menu for the menu bar void createMenu( MenuBar& mbar ) { Menu *menu = new Menu( "&File" ); //Create sub-menu called File MenuItem* mi = new MenuItem( "&New" ); //Create a menu item called New mi->addMenuCallBack( onNew ); //Set its callback menu->append( mi ); //Append to the sub-menu mi = new MenuItem( "&Save" ); //Create a menu item called Save mi->addMenuCallBack( onSave ); //Set its callback menu->append( mi ); //Append to the sub-menu mi = new MenuItem( "E&xit" ); //Create a menu item called Exit mi->addMenuCallBack( onExit ); //Set its callback menu->append( mi ); //Append it to the sub-menu mbar.append( menu ); //Append the sub-menu to the menu bar } /////////////////////////////////////////////////////////////////////////////// ///Callback for "New" menu item BOOL onNew(MenuItem* item, UINT message) { //Set the edit window's text to \0 which //in effect empties the window me->setText( "" ); return TRUE; } /////////////////////////////////////////////////////////////////////////////// ///Callback for "Save" menu item BOOL onSave(MenuItem* item, UINT message) { static char text[256]; //Text buffer //Display the save file dialog char *fname = showSaveFileDlg( me->getParent() ); //If the user pressed OK if ( fname != NULL ) { me->getText( text, 256 ); //Get the edit window's text ofstream fout( fname ); //Open the file the user selected //Make sure it is open if ( fout.is_open() ) fout << text; //Output the edit window's text fout.close(); //Close the file delete[] fname; //Delete the file name } return TRUE; } /////////////////////////////////////////////////////////////////////////////// ///Callback for "Exit" menu item BOOL onExit(MenuItem* item, UINT message) { //Quit the application. Window::quitApp(); return TRUE; }