SOL9 Sample: IconExtractor

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL++2000
// 2000.05.30
// 2009/11/06 Modified ImageList creaiton parameters.

#include <sol\ApplicationView.h>
#include <sol\ListView.h>
#include <sol\Stdio.h>
#include <sol\PaintDC.h>
#include <sol\ClientDC.h>
#include <sol\FileDialog.h>
#include "resource.h"

namespace SOL {

class IconExtractor :public ApplicationView {
private:
  ListView    listView;
  FileDialog    fileDialog;
  ImageList    imageList;

public:

  IconExtractor::IconExtractor(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name,
    args.set(XmNstyle, (ulong)WS_VSCROLL|WS_HSCROLL)),
    imageList(48, 48, ILC_COLOR24| ILC_MASK, 0, 5)

  {
    addCallback(XmNmenuCallback, IDM_OPEN, this,
      (Callback)&IconExtractor::open, NULL);
    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&IconExtractor::exit, NULL);

    Args ar;
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle, (ulong)LVS_ICON);
    listView.create(this, NULL, ar);

    listView.setImageList(&imageList, LVSIL_NORMAL);

    add(listView);
  
    TCHAR dir[_MAX_PATH];
  
    //2008/07/14
  
    //GetWindowsDirectory(dir, _MAX_PATH);
    strcpy_s(dir, CountOf(dir), _T("c:\\"));

    ar.reset();
    ar.set(XmNfilter, _T("Exe or DLL files \0*.exe;*.dll\0"));
    ar.set(XmNdirectory, dir);

    fileDialog.create(this, _T(""), ar);
  }


private:
  void open(Action& action)
  {
    if (fileDialog.open()) {
      TCHAR title[MAX_PATH];
      TCHAR* filename = fileDialog.getFileName();

      HINSTANCE hInst = GetModuleHandle(NULL); 

      int num = (int)ExtractIcon(hInst, filename, -1);
      //Printf("%s numIcon = %d \r\n", filename, num);
      TCHAR message[MAX_PATH];

      if (num <1) {
        _stprintf_s(message, CountOf(message), _T("No icons in the file:%s"), filename);
        showMessageDialog(_T("IconExtractor"), message);
        return;

      } else {
        _stprintf_s(title, CountOf(title), _T("IconExtractor - %s"), filename);
        setText(title);
      
        listView.clear();
        imageList.clear();

        TCHAR number[10];
        for (int i = 0; i<num; i++) {

          HICON hicon = ExtractIcon(hInst, filename, i);
          if (hicon) {
            int id  = imageList.addIcon(hicon);
            LV_ITEM item;
            memset(&item, 0, sizeof(LV_ITEM));

            item.mask = LVIF_TEXT|LVIF_IMAGE;

            item.iImage  = id;
            _stprintf_s(number, CountOf(number), _T("%d"), i);
            item.pszText    = number;
            item.cchTextMax = _MAX_PATH;
            listView.insertItem(&item);
          }
        }
      }
    }
  }
};

}

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

    Args args;
    IconExtractor extractor(applet, name, args);
    extractor.realize();

    applet.run();

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


Last modified: 1 Feb 2017

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