SOL9 Sample: SolWinTree

SOL9 2.0 Samples

1 Screenshot


2 Source code

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



// SOL9/SOL++2000 
// 2000.05.30
// 2008/12/26 Modified to use FileVersioinDialog
// 2008/12/26 Modified class name to SolWinTree from WinTree
// 2008/12/26 Modified to show a window-icon in the window treeview.

#include <sol\ApplicationView.h>
#include <sol\TreeView.h>
#include <sol\FileVersionDialog.h>
#include <sol\ImageList.h>
#include "resource.h"

namespace SOL {

class SolWinTree :public ApplicationView {

private:
  ImageList  imageList;
  int      iconId;
  TreeView  treev;

  FileVersionDialog fileVersion;

private:  
  void  refresh(Action& action) {
    build();    
  }

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

private:  
  void  version(Action& action) 
  {
    fileVersion.popupAt(action);    
  }

private:
  void  build() 
  {
    //2009/11/01
    treev.deleteAllItems();

    TCHAR name[MAX_PATH*2];
    TCHAR title[MAX_PATH*2];
    TCHAR string[MAX_PATH*4];
    HWND desktop = GetDesktopWindow();    
    GetClassName(desktop, name, CountOf(name));
    GetWindowText(desktop, title, CountOf(title));

    _stprintf_s(string, CountOf(string), _T("Window [0X%08X] \"%s\" %s (Desktop)"), desktop, title, name);

    HTREEITEM root = treev.addItem(NULL, TVI_ROOT, string);
    find(root, desktop);    

    treev.sortChildren(root, TRUE);
    treev.expand(root, TVE_EXPAND);
  }

private:
  void  find (HTREEITEM parent, HWND hwnd) 
  {
    HTREEITEM item = (HTREEITEM)TVI_FIRST;

    if (hwnd == NULL) {
      return;
    }
    TCHAR name[MAX_PATH*2];
    TCHAR title[MAX_PATH*2];
    TCHAR string[MAX_PATH*4];
    HWND next = GetWindow(hwnd, GW_CHILD);

    while (next) {
      GetClassName(next, name, CountOf(name));
      GetWindowText(next, title, CountOf(title));
      _stprintf_s(string, CountOf(string), _T("Window [0X%08X] \"%s\" %s"), next, title, name);
      
      item = treev.addItem(parent, item, string, iconId, iconId);
    
      find(item, next);
      next = GetWindow(next, GW_HWNDNEXT);
    }
  }
  
public:
  /** 
   * Constructor
   */
  SolWinTree(Application& applet, const TCHAR* name, Args& args)
    :ApplicationView(applet, name, 
      args.set(XmNbackground, (ulong)(COLOR_BTNFACE+1))  )
  {
    //Create an ImageList 
    imageList.create(16, 16, ILC_COLOR32|ILC_MASK, 10, 5);
    HINSTANCE hInst = applet.getInstance();
    iconId = imageList.addIcon(LoadIcon(hInst, MAKEINTRESOURCE(IDI_WINDOW) ));

    //Create a fileVersionDialog
    fileVersion.create(this);

    addCallback(XmNmenuCallback, IDM_REFRESH, this,
        (Callback)&SolWinTree::refresh, NULL);
    addCallback(XmNmenuCallback, IDM_EXIT, this,
        (Callback)&SolWinTree::exit, NULL);

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

    Args ar;
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle, TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT);
    treev.create(this, NULL, ar);
    //Set a smallImageList
    treev.setImageList(imageList.getImageList(), 0);  
    add(treev);    

    build();

    restorePlacement();
  }
};

}

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

    Args args;
    SolWinTree winTree(applet, name, args);
    winTree.realize();

    applet.run();

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


Last modified: 1 Feb 2017

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