SOL9 Sample: Console

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * Console.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



// SOL++2000 
// 2000.02.18

#include <sol\ApplicationView.h>
#include <sol\ScrolledText.h>

#include <sol\DesktopWindow.h>
#include <sol\Profile.h>
#include <sol\MessageFont.h>
#include <sol\Paintdc.h>
#include <sol\Stdio.h>
#include <sol\ClientDC.h>

// 1997.07.19
#include <sol\Mutex.h>
#include "resource.h"

namespace SOL {

class Console :public ApplicationView {
private:

  Profile  profile;
  MessageFont   font;
  ScrolledText sctext;
  

public:

  Console(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name, args)
  {
    Args ar;

    font.create(9);

    ar.reset();
    sctext.create(this, NULL, ar);
    // Add sctext to the default layout manager.
    add(&sctext);

    sctext.limitText(32000); 
    sctext.setFont(&font);
    sctext.addCallback(XmNmaxTextCallback, this, 
      (Callback)&Console::clear, NULL);
    
    addCallback(XmNmenuCallback, ID_CLEAR, this, 
      (Callback)&Console::clear, NULL);
    addCallback(XmNmenuCallback, ID_EXIT, this, 
      (Callback)&Console::exit, NULL);

    addEventHandler(WM_CLOSE, this, 
      (Handler)&Console::close, NULL);

    DesktopWindow desktopw;
    desktopw.setProp(_T("SCROLLED_TEXT"), (HANDLE)sctext.getWindow());

    restorePlacement();
  }


private:
  long close(Event& event)
  {
    DesktopWindow desktopw;
    desktopw.removeProp(_T("SCROLLED_TEXT"));
    savePlacement();
    return defaultProc(event);
  }

private:
  void  clear(Action& action) { 
    sctext.setText(_T("")); 
  }

};

}

// Console Main
void Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();
  try {
    Application applet(name, argc, argv);
    
    // 1997.07.19
    HWND hwnd = FindWindow(name, name);
    if(hwnd == NULL) {
      Mutex mutex(NULL, TRUE, name);

      if(mutex.wait() == WAIT_OBJECT_0) {
    
        Args args;
        //args.set(XmNclassName, appClass);
        Console console(applet, name, args);
        console.realize();
        applet.run();
      }
    } else {
      SetForegroundWindow(hwnd);
    }
  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  } 
}


Last modified: 1 Feb 2017

Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.