SOL9 Sample: ProgramListWithIcon
|
1 Screenshot
2 Source code
/*
* ProgramListWithIcon.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/11/07
// 2012/07/24
#define COMMONCONTROLS_V6
#include <sol\ApplicationView.h>
#include <sol\ListBox.h>
#include <sol\ListView.h>
#include <sol/IconedFileList.h>
#include "resource.h"
namespace SOL {
class ProgramListWithIcon :public ApplicationView {
private:
IconedFileList listbox;
private:
static const UINT WM_LISTUP = (WM_USER+2009);
private:
void fileSelected(Action& action)
{
String fileName = "";
if (listbox.getSelectedFileName(fileName)) {
const TCHAR* tfilePath = (const TCHAR*)fileName;
if (tfilePath) {
//If it were a file, call ShellExecuteEx to execute the file or an associated program
SHELLEXECUTEINFO sei;
::ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.lpFile = tfilePath;
sei.nShow = SW_SHOWNORMAL;
::ShellExecuteEx(&sei);
}
}
}
public:
/**
* Constructor
*/
ProgramListWithIcon(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name, args)
{
Args ar;
ar.set(XmNstyle, LVS_REPORT|LVS_SORTASCENDING);
listbox.create(this, NULL, ar);
//add(listbox);
addEventHandler(WM_LISTUP, this,
(Handler)&ProgramListWithIcon::listup, NULL);
addCallback(XmNmenuCallback, IDM_REFRESH, this,
(Callback)&ProgramListWithIcon::refresh, NULL);
addCallback(XmNmenuCallback, IDM_STOP, this,
(Callback)&ProgramListWithIcon::stop, NULL);
addCallback(XmNmenuCallback, IDM_EXIT, this,
(Callback)&ProgramListWithIcon::exit, NULL);
// Add callback exec to run a selected program.
listbox.addCallback(XmNdoubleClickCallback, this,
(Callback)&ProgramListWithIcon::fileSelected, NULL);
listbox.addCallback(XmNreturnCallback, this,
(Callback)&ProgramListWithIcon::fileSelected, NULL);
post(WM_LISTUP, 0, 0);
restorePlacement();
}
private:
//2012/
long size(Event& event)
{
int w, h;
event.getSize(w, h);
listbox.reshape(0, 0, w, h);
return 0;
}
private:
void refresh(Action& action)
{
if (listbox.isScanning()) {
MessageBox(NULL, _T("Scanning programs! Please wait a minute."),
_T("ProgramListWithIcon"), MB_OK);
} else {
listbox.clear();
post(WM_LISTUP, 0, 0);
}
}
private:
void stop(Action& action)
{
if (listbox.isScanning()) {
int rc = MessageBox(NULL, _T("Are you sure you want to stop scanning program files?"),
_T("ProgramListWithIcon"), MB_ICONQUESTION|MB_OKCANCEL);
if (rc == IDOK) {
listbox.stopScanning();
}
}
}
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("Scanning programs in %s - ProgramListWithIcon"), dir);
setText(caption);
// List up all executable files in the "?:\Program Files".
listbox.findAllFiles(dir, _T(".exe"));
_stprintf_s(caption, CountOf(caption), _T("%s - ProgramListWithIcon"), dir);
setText(caption);
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;
//2012/07/24
args.set(XmNclassStyle, NO_REDRAW);
ProgramListWithIcon 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.