Advertisement
idsystems

CPP_RAD_Ejercicio31

May 20th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <radc++.h>
  2. /*
  3.     It is suggested that you try understanding Simple Form and Menus examples first
  4.     and then get to this example.
  5.    
  6.     NOTE: This program may crash if file size is larger than 65535 (65.5 kb), becuase
  7.     richtextbox by default accomodates 65535 bytes. Use RichTextBox::setLimit() to accomodate
  8.     number of characters.
  9. */
  10.  
  11. Form form1("Ejemplo Mini NotePad - RAD C++ Ejemplo");
  12.  
  13. Menu menu(form1);
  14. MenuItem __File,__Open,__Save,__Exit,__Help,__About;
  15. RichTextBox txt("", AUTO_ID, 0, 0, 0, 0, form1);
  16.  
  17. FormProcedure form1Proc(FormProcArgs) {
  18.     ON_CLOSE()  Application.close();
  19.  
  20.     ON_COMMAND_BY(__Exit) Application.close();
  21.     ON_COMMAND_BY(__About)
  22.            form1.infoBox("Ejemplo Mini NotePad - RAD C++ 1.2\r\n\r\nby www.radcpp.com");
  23.  
  24.     ON_COMMAND_BY (__Open) {
  25.         if(form1.open()) {                 //yes user selected file
  26.             BinaryData bin;
  27.             bin.loadFile(form1.fileName);  //load selected file
  28.             txt.text = bin.c_str();        //get NULL terminated string only
  29.             bin.clear();                   //release the memory
  30.             form1.caption = form1.fileName;
  31.         }
  32.     }
  33.     ON_COMMAND_BY (__Save) {
  34.         if(form1.save()) {                 //yes user selected file to save
  35.             BinaryData bin;
  36.             String data = txt.text;
  37.             bin.add((UCHAR *)data.c_str(),data.length);         //get NULL terminated string and save to file
  38.             bin.writeFile(form1.fileName);                
  39.             bin.clear();                   //release the memory
  40.             form1.caption = form1.fileName;
  41.         }
  42.     }  
  43.     ON_RESIZE() txt.fitExact();
  44.     return 0;
  45. }
  46.  
  47. rad_main()
  48.         form1.procedure = form1Proc;
  49.         txt.fitExact();
  50.        
  51.         //main menus
  52.         __File = menu.add("&Archivo");
  53.         __Help = menu.add("A&yuda");
  54.        
  55.         //sub-menus tracked  
  56.         __Open = __File.add("&Abrir",AUTO_ID);
  57.         __Save = __File.add("&Guardar",AUTO_ID);
  58.                  __File.addSeparator();
  59.         __Exit = __File.add("&Salida",AUTO_ID);  
  60.         __About = __Help.add("&Acerca de...",AUTO_ID);   
  61.        
  62. rad_end()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement