SOL9 Sample: FileExplorer
|
1 Screenshot
2 Source code
/*
* FileExplorer.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.07.01
// 2008/07/02
#define COMMONCONTROLS_V6
#include <sol\ApplicationView.h>
#include <sol\MessageFont.h>
#include <sol\Static.h>
#include <sol\TextField.h>
#include <sol\ClientDC.h>
#include <sol\IconedFileList.h>
#include <sol\Stdio.h>
#include "resource.h"
namespace SOL {
class FileExplorer :public ApplicationView {
private:
MessageFont font;
Static label;
TextField textf;
IconedFileList listView;
int selectedItem;
TCHAR currentDir[MAX_PATH];
public:
FileExplorer(Application& applet,
const TCHAR* caption, Args& args)
:ApplicationView(applet, caption, args)
{
selectedItem = -1;
Args ar;
font.create(9);
ar.reset();
label.create(this, _T("Directory:"), ar);
label.setFont(font);
ar.reset();
ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
textf.create(this, _T(""), ar);
textf.addCallback(XmNactivateCallback, this,
(Callback)&FileExplorer::listUp, NULL);
textf.setFont(font);
ar.reset();
ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
ar.set(XmNstyle, (ulong)LVS_SORTASCENDING | LVS_REPORT);//
listView.create(this, _T(""), ar);
listView.setFont(font);
listView.addCallback(XmNdoubleClickCallback, this,
(Callback)&FileExplorer::doubleClicked, NULL);
listView.addCallback(XmNitemChangedCallback, this,
(Callback)&FileExplorer::itemChanged, NULL);
addCallback(XmNmenuCallback, IDM_EXIT, this,
(Callback)&FileExplorer::exit, NULL);
addCallback(XmNmenuCallback, IDM_VERSION, this,
(Callback)&FileExplorer::version, NULL);
addEventHandler(WM_CLOSE, this,
(Handler)&FileExplorer::close, NULL);
TCHAR dir[MAX_PATH];
GetWindowsDirectory(dir, CountOf(dir));
textf.setText(dir);
restorePlacement();
listView.findFiles(dir);
}
private:
void doubleClicked(Action& action)
{
TCHAR text[MAX_PATH];
listView.getItemText(selectedItem, 0, text, CountOf(text)-1);
TCHAR temp[MAX_PATH];
strcpy_s(temp, CountOf(temp), text);
CharLower(temp);
TCHAR dir[_MAX_PATH];
int len = textf.getText(dir, CountOf(dir)-1);
TCHAR path[MAX_PATH];
_stprintf_s(path, CountOf(path), _T("%s\\%s"), dir, text);
DWORD attr = ::GetFileAttributes(path);
if (attr & FILE_ATTRIBUTE_DIRECTORY) {
//Printf("Call findFiles %s\r\n", path);
textf.setText(path);
listView.findFiles(path);
} else if (strstr(temp, _T(".exe")) || strstr(temp, _T(".com"))) {
//Printf("Call WinExec %s\r\n", text);
//::WinExec(path, SW_SHOW);
ShellExecute(NULL, _T("open"), path, NULL, NULL, SW_SHOW);
}
}
private:
void itemChanged(Action& action)
{
Event& event = action.getEvent();
NM_LISTVIEW* nmlistv = (NM_LISTVIEW*)event.getLParam();
selectedItem = nmlistv->iItem;
}
private:
void listUp(Action& action)
{
TCHAR pattern[_MAX_PATH];
int len = textf.getText(pattern, CountOf(pattern)-1);
if(len) {
listView.findFiles(pattern);
strcpy_s(currentDir, CountOf(currentDir), pattern);
}
}
private:
long size(Event& event)
{
LPARAM l = event.getLParam();
ClientDC dc(this);
HFONT hfont = (HFONT)dc.select(&font);
int h = dc.getTextHeight();
dc.select(hfont);
label.reshape(0, 0, LOWORD(l), h);
textf.reshape(0, h+2, LOWORD(l), h+8);
listView.reshape(0, h*2+12, LOWORD(l), HIWORD(l)-h*2-12);
return 0L;
}
private:
long close(Event& event)
{
listView.detachImageList();
savePlacement();
return defaultProc(event);
}
private:
void version(Action& action)
{
showMessageDialog(_T("Version"),
_T("FileExplorer Version 1.0.0.2\r\nCopyright(C) 2008-2012 Antillia.com"),
MB_OK|MB_ICONINFORMATION);
}
};
}
// FileExplorer main
void Main(int argc, TCHAR** argv)
{
ModuleFileName module(argv[0]);
const TCHAR* name = module.getFileName();
try {
Application applet(name, argc, argv);
Args args;
args.set(XmNbackground, (COLOR_BTNFACE)+1);
FileExplorer 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.