/*
* ProgramListWithIcon.cpp
* Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/11/07
#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:
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, SizeOf(dir));
//strcat(buffer, _T("\\*.EXE"));
_stprintf(&dir[3], _T("%s"), _T("Program Files"));
TCHAR caption[MAX_PATH];
_stprintf(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(caption, _T("%s - ProgramListWithIcon"), dir);
setText(caption);
return 0L;
}
};
}
//
void Main(int argc, TCHAR** argv)
{
const TCHAR* name = _T("ProgramListWithIcon");
try {
Application applet(name, argc, argv);
Args args;
ProgramListWithIcon programList(applet, name, args);
programList.realize();
applet.run();
} catch (...) {
}
}
|