SOL9 Sample: ProgramList

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL++2000
// 2000.02.18

#define COMMONCONTROLS_V6


#include <sol\ApplicationView.h>
#include <sol\ListBox.h>

#include "resource.h"

namespace SOL {

class ProgramList :public ApplicationView {
private:
  ListBox listbox;

private:
  static const UINT WM_LISTUP = (WM_USER+2009);

private:

  void exec(Action& action)
  {
    TCHAR buff[256];
    listbox.getCurText(buff);
    ShellExecute(NULL, _T("open"), buff, NULL, NULL, SW_SHOW);
  }

public:

  ProgramList(Application& applet, const TCHAR* name, Args& args)
  :ApplicationView(applet, name, args)
  {
    Args ar;
    ar.set(XmNstyle, (ulong)WS_VSCROLL|LBS_SORT|LBS_NOINTEGRALHEIGHT);
    listbox.create(this, NULL, ar);
    add(listbox);

    addEventHandler(WM_LISTUP, this,
      (Handler)&ProgramList::listup, NULL);

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

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

    // Add callback exec to run a selected program.
    listbox.addCallback(XmNdefaultActionCallback, this,
      (Callback)&ProgramList::exec,  NULL);

    post(WM_LISTUP, 0, 0);
    
    restorePlacement();
  }

private:
  void refresh(Action& action)
  {
    listbox.clear();
    post(WM_LISTUP, 0, 0);  
  }

private:
  long listup(Event& event)
  {
    TCHAR dir[MAX_PATH];
    ::GetWindowsDirectory(dir, CountOf(dir));
    //strcat(buffer, _T("\\*.EXE"));
    _stprintf_s(&dir[3], CountOf(dir) - 3, _T("%s"), _T("Program Files"));
    

    TCHAR caption[MAX_PATH];
    _stprintf_s(caption, CountOf(caption), _T("%s - ProgramList"), dir);
    setText(caption);
    // List up all executable files in the "?:\Program Files".
    listbox.findAllFiles(dir, _T(".exe"));

    return 0L;
  }

};

}

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

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


Last modified: 1 Feb 2017

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