SOL9 Sample: SolFolderView

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL9
// 2012/11/10

#define COMMONCONTROLS_V6

#include <sol\ApplicationView.h>
#include <sol\ComboBox.h>
#include <sol\shell\FolderViewHost.h>
#include <sol\shell\ShellView.h>
#include <sol\shell\FolderView.h>
#include <sol\ole\OleInitializer.h>
#include "resource.h"

namespace SOL {

// class SolFolderView

class SolFolderView :public ApplicationView {
private:
  ComboBox       viewMode;
  FolderViewHost folderViewHost;

public:
  /**
   * Constructor
   */
  SolFolderView(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name, 
      args.set(XmNbackground, (ulong)(COLOR_BTNFACE+1))
      .set(XmNstyle, WS_CLIPCHILDREN))
  {
    Args ar;
    ar.set(XmNstyle, WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST);
    ar.set(XmNheight, 300);
    viewMode.create(this, NULL, ar);

    const TCHAR* mode[] = { _T("Icon"), _T("SmallIcon"), _T("List"),_T("Details"), 
              _T("ThumbNail"), _T("Tile"), _T("ThumbStrip"), _T("Content") };
    for (int i = 0; i<CountOf(mode); i++) {
      viewMode.addString(mode[i]);
    }
    viewMode.setCurSel(2); //List
    viewMode.addCallback(XmNselChangeCallback, this,
      (Callback)&SolFolderView::selChange, NULL);

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

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

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

    addEventHandler(WM_SIZE, this, 
      (Handler)&SolFolderView::size, NULL);

    //Desktop
    PIDLIST_ABSOLUTE pidl;
    //SHGetSpecialFolderLocation(NULL, CSIDL_CONTROLS, //CSIDL_MYDOCUMENTS, //CSIDL_COMMON_PROGRAMS, //CSIDL_DESKTOP, 
    //        &pidl);
    HRESULT hr = SHGetKnownFolderIDList(
        //FOLDERID_CommonPrograms , 
        //FOLDERID_ControlPanelFolder,
        FOLDERID_Desktop,
        0, (HANDLE)-1, &pidl);

    try {
      folderViewHost.initialize(*this, pidl);//, rec);
      ShellView shellView = folderViewHost.queryActiveView();

      FolderView folderView = shellView.getFolderView();
      folderView.setCurrentViewMode(FVM_LIST);  //List

    } catch (...) {
    }
    CoTaskMemFree(pidl);

    restorePlacement();
  }

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

private:
  void refresh(Action& action)
  {
    try {
      ShellView shellView =  folderViewHost.queryActiveView();
      shellView.refresh();
    } catch (...) {

    }
  }


private:
  long size(Event& event)
  {
    int w, h;
    event.getSize(w, h);
    int cw, ch;
    viewMode.getSize(cw, ch);
    viewMode.reshape(w-120, 0, 110, ch);

    ShellView shellView = folderViewHost.queryActiveView();
    shellView.reshape(0, ch+2, w, h-ch-2);
    return 0;
  }

private:
  void selChange(Action& action)
  {
    int mode = viewMode.getCurSel() + 1;

    try {
      ShellView shellView = folderViewHost.queryActiveView();
      FolderView folderView = shellView.getFolderView();
      folderView.setCurrentViewMode(mode);
    } catch (...) {

    }
  }

};

}

//  Program entry point.
void  Main(int argc, TCHAR** argv)
{
  OleInitializer initializer;

  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();

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

    Args args;
    args.set(XmNclassStyle, 0);
    SolFolderView explorer(applet, name, args);
    explorer.realize();

    applet.run();

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


Last modified: 1 Feb 2017

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