SOL9 2.0 Sample: SolWinTree

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * SolWinTree.cpp 
 * Copyright (c) 2009 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, SizeOf(name));
        GetWindowText(desktop, title, SizeOf(title));

        _stprintf_s(string, SizeOf(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, SizeOf(name));
            GetWindowText(next, title, SizeOf(title));
            _stprintf_s(string, SizeOf(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)
{
    const String appClass = "SolWinTree";

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

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

        applet.run();

    } catch (...) {

    }
}


Last modified: 11 Nov 2009

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