From $ROOTSYS/tutorials/gui/guiWithCINT.C

// A simple example of entering  CINT commands and having the CINT output in a 
// ROOT GUI application window. 
// An editable combo box is used as a CINT prompt, a text view widget displays 
// the command output.
// Author: Ilka Antcheva   06/07/2007

#include <iostream>
#include <TApplication.h>
#include <TRint.h>
#include <TROOT.h>
#include <TSystem.h>
#include <TGTextEntry.h>
#include <TGTextView.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TString.h>
#include <TGComboBox.h>
#include <Getline.h>

class IDList {

private:
   Int_t fID;  //create widget Id(s)

public:
   IDList() : fID(0) {}
   ~IDList() {}
   Int_t GetUnID(void) { return ++fID; }
};

class MyApplication : public TGMainFrame {

private:
   TGTextButton        *fExit;
   IDList               fIDs;
   TGComboBox          *fComboCmd;   // CINT command combobox
   TGTextBuffer        *fCommandBuf; // text buffer in use 
   TGTextEntry         *fCommand;    // text entry for CINT commands
   TGTextView          *fTextView;   // display CINT output
   TString              fName;       // name of temp created file
public:
   MyApplication(const TGWindow *p, UInt_t w, UInt_t h);
   virtual ~MyApplication();

   void DoExit();
   void DoEnteredCommand();

   ClassDef(MyApplication, 0)
};
                          
MyApplication::MyApplication(const TGWindow *p, UInt_t w, UInt_t h) 
   : TGMainFrame(p, w, h)   
{
   SetCleanup(kDeepCleanup);
   
   Connect("CloseWindow()", "MyApplication", this, "DoExit()");
   DontCallClose();

   TGHorizontalFrame *fHL2 = new TGHorizontalFrame(this, 70, 100);
   AddFrame(fHL2, new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5));
   TGLabel *fInlabel = new TGLabel(fHL2, "CINT Prompt:");
   fHL2->AddFrame(fInlabel, new TGLayoutHints(kLHintsCenterY));

   TGLabel *fOutlabel = new TGLabel(this, "Output Window:");
   AddFrame(fOutlabel);

   fCommandBuf = new TGTextBuffer(256);
   fComboCmd = new TGComboBox(fHL2, "", fIDs.GetUnID());
   fCommand = fComboCmd->GetTextEntry();
   fComboCmd->Resize(450, fCommand->GetDefaultHeight());
   fHL2->AddFrame(fComboCmd, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 20,0,0,0));

   TString hist(Form("%s/.root_hist", gSystem->UnixPathName(gSystem->HomeDirectory())));
   FILE *fhist = fopen(hist.Data(), "rt");
   if (fhist) {
      char histline[256];
      while (fgets(histline, 256, fhist)) {
         histline[strlen(histline)-1] = 0; // remove trailing "\n"
         fComboCmd->InsertEntry(histline, 0, -1);
      }
      fclose(fhist);
   }

   Pixel_t backpxl;
   gClient->GetColorByName("#c0c0c0", backpxl);
   fTextView = new TGTextView(this, 500, 94, fIDs.GetUnID(), kFixedWidth | kFixedHeight);
   fTextView->SetBackground(backpxl);
   AddFrame(fTextView, new TGLayoutHints(kLHintsExpandX));
   TGHorizontalFrame *fHL3 = new TGHorizontalFrame(this, 70, 150, kFixedWidth);
   fExit = new TGTextButton(fHL3, "&Exit", fIDs.GetUnID());
   fExit->Connect("Clicked()", "MyApplication", this, "DoExit()");
   fHL3->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX));
   AddFrame(fHL3, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));

   SetWindowName("GUI with CINT Input/Output");
   MapSubwindows();
   Resize(GetDefaultSize());
   MapWindow();
   fCommand->Connect("ReturnPressed()", "MyApplication", this, "DoEnteredCommand()");
   fName = Form("%soutput.log", gSystem->WorkingDirectory());
};

MyApplication::~MyApplication()
{
   // Destructor.
   
   Cleanup();
}

void MyApplication::DoExit()
{
   // Close application window.
   
   gSystem->Unlink(fName.Data());   
   gApplication->Terminate();
}

void MyApplication::DoEnteredCommand()
{
   // Execute the CINT command after the ENTER key was pressed.

   const char *command = fCommand->GetTitle();
   TString prompt;
   
   if (strlen(command)) {
      // form temporary file path
      prompt = ((TRint*)gROOT->GetApplication())->GetPrompt();
      FILE *cintout = fopen(fName.Data(), "a+t");
      if (cintout) {
         fputs(Form("%s%s\n",prompt.Data(), command), cintout);
         fclose(cintout);
      }
      gSystem->RedirectOutput(fName.Data(), "a");
      gROOT->ProcessLine(command);
      fComboCmd->InsertEntry(command, 0, fIDs.GetUnID());
      Gl_histadd((char *)command);
      gSystem->RedirectOutput(0);
      fTextView->LoadFile(fName.Data());
      if (fTextView->ReturnLineCount() > 10)
         fTextView->SetVsbPosition(fTextView->ReturnLineCount());
      fCommand->Clear();
   } else {
      printf("No command entered\n");
   }
   fTextView->ShowBottom();
}

void guiWithCINT() 
{
   new MyApplication(gClient->GetRoot(),600,300);
}

 guiWithCINT.C:1
 guiWithCINT.C:2
 guiWithCINT.C:3
 guiWithCINT.C:4
 guiWithCINT.C:5
 guiWithCINT.C:6
 guiWithCINT.C:7
 guiWithCINT.C:8
 guiWithCINT.C:9
 guiWithCINT.C:10
 guiWithCINT.C:11
 guiWithCINT.C:12
 guiWithCINT.C:13
 guiWithCINT.C:14
 guiWithCINT.C:15
 guiWithCINT.C:16
 guiWithCINT.C:17
 guiWithCINT.C:18
 guiWithCINT.C:19
 guiWithCINT.C:20
 guiWithCINT.C:21
 guiWithCINT.C:22
 guiWithCINT.C:23
 guiWithCINT.C:24
 guiWithCINT.C:25
 guiWithCINT.C:26
 guiWithCINT.C:27
 guiWithCINT.C:28
 guiWithCINT.C:29
 guiWithCINT.C:30
 guiWithCINT.C:31
 guiWithCINT.C:32
 guiWithCINT.C:33
 guiWithCINT.C:34
 guiWithCINT.C:35
 guiWithCINT.C:36
 guiWithCINT.C:37
 guiWithCINT.C:38
 guiWithCINT.C:39
 guiWithCINT.C:40
 guiWithCINT.C:41
 guiWithCINT.C:42
 guiWithCINT.C:43
 guiWithCINT.C:44
 guiWithCINT.C:45
 guiWithCINT.C:46
 guiWithCINT.C:47
 guiWithCINT.C:48
 guiWithCINT.C:49
 guiWithCINT.C:50
 guiWithCINT.C:51
 guiWithCINT.C:52
 guiWithCINT.C:53
 guiWithCINT.C:54
 guiWithCINT.C:55
 guiWithCINT.C:56
 guiWithCINT.C:57
 guiWithCINT.C:58
 guiWithCINT.C:59
 guiWithCINT.C:60
 guiWithCINT.C:61
 guiWithCINT.C:62
 guiWithCINT.C:63
 guiWithCINT.C:64
 guiWithCINT.C:65
 guiWithCINT.C:66
 guiWithCINT.C:67
 guiWithCINT.C:68
 guiWithCINT.C:69
 guiWithCINT.C:70
 guiWithCINT.C:71
 guiWithCINT.C:72
 guiWithCINT.C:73
 guiWithCINT.C:74
 guiWithCINT.C:75
 guiWithCINT.C:76
 guiWithCINT.C:77
 guiWithCINT.C:78
 guiWithCINT.C:79
 guiWithCINT.C:80
 guiWithCINT.C:81
 guiWithCINT.C:82
 guiWithCINT.C:83
 guiWithCINT.C:84
 guiWithCINT.C:85
 guiWithCINT.C:86
 guiWithCINT.C:87
 guiWithCINT.C:88
 guiWithCINT.C:89
 guiWithCINT.C:90
 guiWithCINT.C:91
 guiWithCINT.C:92
 guiWithCINT.C:93
 guiWithCINT.C:94
 guiWithCINT.C:95
 guiWithCINT.C:96
 guiWithCINT.C:97
 guiWithCINT.C:98
 guiWithCINT.C:99
 guiWithCINT.C:100
 guiWithCINT.C:101
 guiWithCINT.C:102
 guiWithCINT.C:103
 guiWithCINT.C:104
 guiWithCINT.C:105
 guiWithCINT.C:106
 guiWithCINT.C:107
 guiWithCINT.C:108
 guiWithCINT.C:109
 guiWithCINT.C:110
 guiWithCINT.C:111
 guiWithCINT.C:112
 guiWithCINT.C:113
 guiWithCINT.C:114
 guiWithCINT.C:115
 guiWithCINT.C:116
 guiWithCINT.C:117
 guiWithCINT.C:118
 guiWithCINT.C:119
 guiWithCINT.C:120
 guiWithCINT.C:121
 guiWithCINT.C:122
 guiWithCINT.C:123
 guiWithCINT.C:124
 guiWithCINT.C:125
 guiWithCINT.C:126
 guiWithCINT.C:127
 guiWithCINT.C:128
 guiWithCINT.C:129
 guiWithCINT.C:130
 guiWithCINT.C:131
 guiWithCINT.C:132
 guiWithCINT.C:133
 guiWithCINT.C:134
 guiWithCINT.C:135
 guiWithCINT.C:136
 guiWithCINT.C:137
 guiWithCINT.C:138
 guiWithCINT.C:139
 guiWithCINT.C:140
 guiWithCINT.C:141
 guiWithCINT.C:142
 guiWithCINT.C:143
 guiWithCINT.C:144
 guiWithCINT.C:145
 guiWithCINT.C:146
 guiWithCINT.C:147
 guiWithCINT.C:148
 guiWithCINT.C:149
 guiWithCINT.C:150
 guiWithCINT.C:151
 guiWithCINT.C:152
 guiWithCINT.C:153
 guiWithCINT.C:154
 guiWithCINT.C:155
 guiWithCINT.C:156
 guiWithCINT.C:157