SOL9 Sample: SolWMPCdromExplorer

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL9
// 2011/12/21
// 2015/12/13 Modified IDM_* menu values.

#include <sol\ApplicationView.h>
#include <sol\StatusBar.h>
#include <sol\TreeView.h>
#include <sol\PropertyView.h>
#include <sol\SmartPtr.h>
#include <sol\DropTarget.h>
#include <sol\ImageList.h>
#include <sol\FileVersionDialog.h>

#include <sol/COMInitializer.h>
#include <sol/Locale.h>

#include <sol/wmp/WMPPlayer.h>
#include <sol/wmp/WMPSettings.h>
#include <sol/wmp/WMPCdrom.h>
#include <sol/wmp/WMPCdromCollection.h>
#include <sol/wmp/WMPPlaylist.h>
#include <sol/wmp/WMPMedia.h>
#include <sol/wmp/WMPControls.h>
#include "SolWMPMedia.h"
#include "resource.h"

namespace SOL {

/**
 * SolWMPCdromExplorer class
 */
class SolWMPCdromExplorer :public ApplicationView {

private:
  TreeView        treev;
  PropertyView    propv;
  StatusBar        statusbar;
  FileVersionDialog fileVersion;
  
  WMPPlayer player;

  ImageList imageList;
  int  driveIconIndex;
  int itemIconIndex;

public:
  /**
   * Constructor
   */
  SolWMPCdromExplorer(Application& applet, const char* name, Args& args)
  :ApplicationView(applet, name, 
      args.set(XmNbackground, (ulong)(COLOR_BTNFACE+1)) ),
    driveIconIndex(0),
    itemIconIndex(0)
  {
    Args ar;

    ar.reset();
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle, (ulong)(TVS_HASBUTTONS|TVS_SHOWSELALWAYS|
      TVS_HASLINES|TVS_LINESATROOT));
    treev.create(this, "", ar);
    
    ar.reset();
    ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
    ar.set(XmNstyle,  (ulong)WS_BORDER|LVS_REPORT);
    propv.create(this, "", ar);  
    propv.setBkColor(RGB(240,240,255));
    ar.reset();
    statusbar.create(this, "", ar);
    statusbar.setText("Please select a 'Scan Cdrom' from [File] menu");
    treev.addCallback(XmNselChangedCallback, this, 
      (Callback)&SolWMPCdromExplorer::selChanged, NULL);

    fileVersion.create(this);

    addCallback(XmNmenuCallback, IDM_SCAN_CDROM, this, 
        (Callback)&SolWMPCdromExplorer::scanCdrom, NULL);
    addCallback(XmNmenuCallback, IDM_EXIT, this, 
        (Callback)&SolWMPCdromExplorer::exit, NULL);
    addCallback(XmNmenuCallback, IDM_VERSION, this, 
        (Callback)&SolWMPCdromExplorer::version, NULL);

    addEventHandler(WM_SIZE, this, 
        (Handler)&SolWMPCdromExplorer::size, NULL);
    addEventHandler(WM_CLOSE, this, 
        (Handler)&SolWMPCdromExplorer::close, NULL);
  
    HINSTANCE hInst = getInstanceHandle();
    HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_SOL));
    send(WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
    send(WM_SETICON, ICON_BIG, (LPARAM)hIcon);

    WMPSettings settings  = player.getSettings();
    //settings.requestMediaAccessRights(_bstr_t("read"));
    createImageList(hInst);

    restorePlacement();
  }

private:
  void createImageList(HINSTANCE hInst)
  {
    this->imageList.create(16, 16, ILC_COLOR32|ILC_MASK, 10, 5);
    HICON hIcon1 = (HICON)LoadIcon(hInst, MAKEINTRESOURCE(IDI_LIBRARY));
    this->driveIconIndex = imageList.addIcon(hIcon1);
    HICON hIcon2 = (HICON)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ITEM));
    this->itemIconIndex = imageList.addIcon(hIcon2);
    HIMAGELIST hImageList = imageList.getImageList();
    treev.setImageList(hImageList, TVSIL_STATE);
    treev.setImageList(hImageList, TVSIL_NORMAL);      
  }

public:
  /**
   * WM_SIZE eventhandler.
   */
  long size(Event& event)
  {
    LPARAM l = event.getLParam();
    
    statusbar.send(WM_SIZE, event.getWParam(), event.getLParam());
    int w, h;
    statusbar.getSize(w, h);
    treev.reshape(0, 0, w*1/3-1,  HIWORD(l) - h);
    propv.reshape(w/3, 0, w*2/3-2, HIWORD(l) - h);
    
    return 0;
  }

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

private:
  void showMedia(HTREEITEM top, int n, WMPMedia& media)
  {
    TCHAR string[1024];

    HTREEITEM item = (HTREEITEM)TVI_LAST;
    HTREEITEM next = NULL;
    _bstr_t name = media.getName();
    _stprintf_s(string, CountOf(string), _T("%s"), (const TCHAR*)name);
    treev.addItem(top, item, string, n, itemIconIndex, itemIconIndex);
  }

public:
  /**
   * File menu [Scan Cdrom] callback.
   */
  void scanCdrom(Action& action)
  {

    treev.clear();

    propv.clear();

    WMPCdromCollection collection = player.getCdromCollection();
    long lcount = collection.getCount();

    for (long n = 0; n<lcount; n++) {
      WMPCdrom cdrom = collection.item(n);
      _bstr_t drive = cdrom.getDriveSpecifier();

      TCHAR string[1024*2];
      _stprintf_s(string, CountOf(string), _T("Drive (%s)"), (const TCHAR*)drive);  
      HTREEITEM root = treev.addItem(NULL, TVI_ROOT, string, n,  driveIconIndex, driveIconIndex);

      WMPPlaylist list = cdrom.getPlaylist();
      long count = list.getCount();
      for (long i = 0; i<count; i++) {
        WMPMedia media = list.getItem(i);
        showMedia(root, i, media);
      }
    }
    
    treev.expandAllChildren();
  }

public:
  /**
   * File menu [Version] callback.
   */
  void version(Action& action)
  {
    fileVersion.popupAt(action);
  }

public:
  /**
   * Callback for a selection-change event in a treeView. 
   */
  void selChanged(Action& action)
  {  
    try {
      propv.clear();

      Event& event = action.getEvent();
      NM_TREEVIEW* nmtr  = (NM_TREEVIEW*)event.getLParam();
  
      TV_ITEM tvItem     = nmtr -> itemNew;
      HTREEITEM hItem = tvItem.hItem; 

      if (treev.isLeafNode(hItem)) {
        //A leaf node has been selected.
        long mediaIndex = tvItem.lParam;
      
        TV_ITEM parentItem;
        if (treev.getParentItem(hItem, parentItem)) {
          long libIndex = parentItem.lParam;
          WMPCdromCollection collection = player.getCdromCollection();

          WMPCdrom cdrom = collection.item(libIndex);
          WMPPlaylist list = cdrom.getPlaylist();

          SolWMPMedia media = list.getItem(mediaIndex);
          media.showProperties(propv);
        }
      }
    } catch(...) {
    
    }    
  }
};

}


/////////////////////////////////////////////////
//  Program entry point.
void  Main(int argc, char** argv)
{
  OleInitialize(NULL);
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();

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

    Args args;
    SolWMPCdromExplorer viewer(applet, name, args);
    viewer.realize();

    applet.run();

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


Last modified: 1 Feb 2017

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