SOL9 Sample: ProcessListView

SOL9 2.0 Samples

1 Screenshot


2 Source code

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



// SOL++2000

#include <sol\ApplicationView.h>
#include <sol\ListView.h>
#include <sol\Profile.h>
#include <sol\Font.h>
#include <sol\Stdio.h>
#include <sol\StringList.h>
#include <sol\ListView.h>

#include <sol\ProcessInfo.h>
#include <sol\ProcessList.h>
#include <sol/SystemImageList.h>
#include <sol/FileInfo.h>

#include "resource.h"


#define WM_LISTUP  (WM_USER+2008)

namespace SOL {

class ProcessListView :public ApplicationView {

private:
  ListView  listView;

  ProcessList  plist;
  ImageList imageList;
  int        iconId;

public:
  /**
   * Constructor
   */
  ProcessListView(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name, args)
  {
    Args ar;

    ar.reset();
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle, (ulong)LVS_REPORT);
    listView.create(this, NULL, ar);

    ListViewColumn items[] = {
      {_T("ProcessName"),   LVCFMT_LEFT, 240},
      {_T("ProcessID"),       LVCFMT_RIGHT,   130},
      {_T("NumberOfThreads"), LVCFMT_RIGHT, 130},

      {_T("ParentProcessID"),   LVCFMT_RIGHT, 130},
    };

    listView.setColumn(items, CountOf(items));
    imageList.create(16, 16, ILC_COLOR32|ILC_MASK, 
      10, 5);
    HINSTANCE hInst = applet.getInstance();
    iconId = imageList.addIcon(LoadIcon(hInst, 
        MAKEINTRESOURCE(IDI_PROCESS_ICON) ));
    listView.setImageList(&imageList, LVSIL_SMALL);
    //listView.setImageList(&imageList, LVSIL_NORMAL);

    add(listView);

    addCallback(XmNmenuCallback, IDM_REFRESH, this,
      (Callback)&ProcessListView::refresh, NULL);


    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&ProcessListView::exit, NULL);

    addCallback(XmNmenuCallback, IDM_VERSION, this,
      (Callback)&ProcessListView::version, NULL);

    addEventHandler(WM_LISTUP, this, 
      (Handler)&ProcessListView::listUp, NULL);

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

    restorePlacement();

    post(WM_LISTUP, 0, 0);
  }

private:
  void refresh(Action& action)
  {
    post(WM_LISTUP, 0, 0);
  }


private:
  void version(Action& action)
  {
    showMessageDialog(_T("Version"),
      _T("ProcessListView Version 1.0.0.3\r\nCopyright(C) 2009 Antillia.com"),
      MB_OK|MB_ICONINFORMATION);
  }

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

private:
  long listUp(Event& event) 
  {  
    listView.clear();

    plist.listUp();

    ListEntry* ptr = plist.getEntry();
    while (ptr) {
      ProcessInfo* info = (ProcessInfo*)ptr->getObject();
      int n = 0;
      if (info) {
        TCHAR id[80];
        _stprintf_s(id, CountOf(id), _T("0x%08x"), info->getProcessId());
        
        TCHAR pid[80];
        _stprintf_s(pid, CountOf(pid), _T("0x%08x"), info->getParentProcessId());

        TCHAR threads[80];
        _stprintf_s(threads, CountOf(threads), _T("%d"), 
          info->getThreadsCount());

        const TCHAR* items[4];
        items[0] = info->getName();
        items[1] = id;
        items[2] = threads;
        items[3] = pid;//

        listView.insertLineWithIcon(n, items, CountOf(items), iconId);
        n++;
      }
      ptr = ptr ->getNext();
    }
    return 0;    
  }

};

}

// ProcessListView Main
void  Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();

  try {
    Application applet(name, argc, argv);
    
    Args args;
    args.set(XmNclassStyle, 0);
    ProcessListView listView(applet, name, args);
    listView.realize();

    applet.run();

  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  }
}

Last modified: 1 Feb 2017

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