SOL9 Sample: SolOperatingSystemViewer

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// 2015/12/20

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

#include <sol\ImageList.h>
#include <sol\FileVersionDialog.h>

#include <sol/COMInitializer.h>
#include <sol/Locale.h>

#include <sol/wmi/SWbemQueryOperatingSystem.h>


#include "resource.h"

namespace SOL {

/**
 * SolOperatingSystemViewer class
 */
class SolOperatingSystemViewer :public ApplicationView {

private:
  //Inner class starts.
  class SolSWbemQueryOperatingSystem : public SWbemQueryOperatingSystem {
  public:
    SolSWbemQueryOperatingSystem() 
    :SWbemQueryOperatingSystem("*")
    {
    }
    
    virtual void display(PropertyView& listv)
    {
      listv.clear();
      
      for (long i = 0; i< getObjectSetCount(); i++) {
        StringT<wchar_t> name;
        // Get a list of Name="Value" pair.
        getObjectText(i, name);
        StringTokenizerT<wchar_t> tokenizer((const wchar_t*)name);
        tokenizer.clearSeparator();
        tokenizer.addSeparator((wchar_t)'\n');
        while(tokenizer.hasMoreToken()) {
          StringT<wchar_t> line;
          //Get a line ended with a newline from the object text 'name'.
          tokenizer.getToken(line);
          if (line.getLength() > 1) {
          // Split the property of the format 'name=value' to name and value by using WcharProperty.
            WcharProperty property(line);
            //property.dump();
            listv.addLast(property.getName(), property.getValue());
          }
        }
      }
    }
    
  };
  //Inner class ends.
    
  PropertyView    propv;
  FileVersionDialog fileVersion;

  ImageList imageList;

public:
  /**
   * Constructor
   */
  SolOperatingSystemViewer(Application& applet, const char* name, Args& args)
  :ApplicationView(applet, name, 
      args.set(XmNbackground, (ulong)(COLOR_BTNFACE+1)) )
  {
    Args ar;

    ar.reset();
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle,  (ulong)WS_BORDER|LVS_REPORT);
    propv.create(this, "", ar);  
    //propv.setBkColor(RGB(240,240,255));

    fileVersion.create(this);

    addCallback(XmNmenuCallback, IDM_OS_PROPERTY, this, 
        (Callback)&SolOperatingSystemViewer::showProperty, NULL);
    addCallback(XmNmenuCallback, IDM_EXIT, this, 
        (Callback)&SolOperatingSystemViewer::exit, NULL);
    addCallback(XmNmenuCallback, IDM_VERSION, this, 
        (Callback)&SolOperatingSystemViewer::version, NULL);

    addEventHandler(WM_SIZE, this, 
        (Handler)&SolOperatingSystemViewer::size, NULL);
    addEventHandler(WM_CLOSE, this, 
        (Handler)&SolOperatingSystemViewer::close, NULL);
  
    HINSTANCE hInst = getInstanceHandle();
    HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SOL));
    send(WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
    send(WM_SETICON, ICON_BIG, (LPARAM)hIcon);


    restorePlacement();
  }


public:
  /**
   * WM_SIZE eventhandler.
   */
  long size(Event& event)
  {
    LPARAM l = event.getLParam();
    propv.reshape(0, 0, LOWORD(l),  HIWORD(l));
    
    return 0;
  }

public:
  long close(Event& event)
  {
    savePlacement();
    return defaultProc(event);
  }


public:
  /**
   * File menu [Scan Cdrom] callback.
   */
  void showProperty(Action& action)
  {
    try {
      //1 Create an instance of SolSWbemQueryOperatingSystem thread specifying select item "*" (All items).
      SolSWbemQueryOperatingSystem query;

      //2 Start the query thread.
      query.start();

      //3 Wait a completion of the query thread
      query.wait();
    
      //4 Display the text of ObjectSet queried.
      query.display(propv);
      
    } catch (Exception& ex) {
      caught(ex);
    }
  }

public:
  /**
   * File menu [Version] callback.
   */
  void version(Action& action)
  {
    fileVersion.popupAt(action);
  }


};

}


/////////////////////////////////////////////////
//  Program entry point.
void  Main(int argc, char** argv)
{
  const char* appClass = "SolOperatingSystemViewer";

  try {
    Application applet(appClass, argc, argv);

    Args args;
    SolOperatingSystemViewer viewer(applet, appClass, args);
    viewer.realize();

    applet.run();
  } catch (...) {

  }
}


Last modified: 1 Feb 2017

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