SOL9 Sample: SolShellBrowser
|
1 Screenshot
2 Source code
/*
* SolShellBrowser.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
//2017/01/29 Modified to use the following csidl value:
// int csidl = CSIDL_COMMON_PROGRAMS;
#define COMMONCONTROLS_V6
#include <sol\ApplicationView.h>
#include <sol\shell\ShellBrowser.h>
#include <sol\shell\ShellView.h>
#include <sol\ComboBox.h>
#include "resource.h"
namespace SOL {
// class SolShellBrowser
class SolShellBrowser :public ApplicationView {
private:
ComboBox viewMode;
ShellBrowser shellBrowser;
public:
/**
* Constructor
*/
SolShellBrowser(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name,
args.set(XmNbackground, (ulong)(COLOR_BTNFACE+1))
.set(XmNstyle, WS_CLIPCHILDREN))
{
Args ar;
ar.set(XmNstyle, WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST);
ar.set(XmNheight, 300);
viewMode.create(this, NULL, ar);
const TCHAR* mode[] = { _T("Icon"), _T("SmallIcon"), _T("List"),_T("Details"),
_T("ThumbNail"), _T("Tile"), _T("ThumbStrip"), _T("Content") };
for (int i = 0; i<CountOf(mode); i++) {
viewMode.addString(mode[i]);
}
viewMode.setCurSel(3); //Details
viewMode.addCallback(XmNselChangeCallback, this,
(Callback)&SolShellBrowser::selChange, NULL);
addCallback(XmNmenuCallback, IDM_REFRESH, this,
(Callback)&SolShellBrowser::refresh, NULL);
addCallback(XmNmenuCallback, IDM_EXIT, this,
(Callback)&SolShellBrowser::exit, NULL);
addCallback(XmNmenuCallback, IDM_VERSION, this,
(Callback)&SolShellBrowser::version, NULL);
addEventHandler(WM_SIZE, this,
(Handler)&SolShellBrowser::size, NULL);
try {
FOLDERSETTINGS fs;
fs.ViewMode = FVM_AUTO; //FVM_TILE; //FVM_THUMBNAIL; //FVM_ICON; //FVM_LIST; // FVM_LIST; //FVM_DETAILS;
fs.fFlags = FWF_AUTOARRANGE|FWF_SHOWSELALWAYS|FWF_HIDEFILENAMES;
RECT rc = {0, 0, 0, 0};
/*
TCHAR directory[1024];
GetWindowsDirectory(directory, CountOf(directory));
shellBrowser.create(*this, directory, fs, rc);
TCHAR caption[1024];
_stprintf(caption, _T("%s - SolShellBrowser"), directory);
setText(caption);
*/
//shellBrowser.create(*this, FOLDERID_CommonPrograms, fs, rc);
//shellBrowser.create(*this, FOLDERID_PublicDesktop, fs, rc);
//int csidl = CSIDL_DESKTOP;
int csidl = CSIDL_COMMON_PROGRAMS; //C:\ProgramData\Microsoft\Windows\Start Menu\Programs
//int csidl = CSIDL_COMMON_STARTUP;
//int csidl = CSIDL_DRIVES;
//int csidl = CSIDL_STARTMENU;
//int csidl = CSIDL_CONTROLS; //CSIDL_PERSONAL;
shellBrowser.create(*this, csidl, fs, rc);
//setCaption(csidl);
} catch (...) {
showMessageDialog(_T("Exception"),
_T("SolShellBrowser failed to create a window of ShellBrowser"),
MB_OK);
}
restorePlacement();
}
private:
void setCaption(int csidl)
{
TCHAR path[1024] = {0};
HRESULT hr = SHGetFolderPath(NULL, csidl, (HANDLE)-1, //hToken,
SHGFP_TYPE_CURRENT, path);
if (SUCCEEDED(hr)) {
setText(path);
}
}
private:
void selChange(Action& action)
{
int mode = viewMode.getCurSel() + 1;
try {
ShellView shellView = shellBrowser.queryActiveShellView();
IFolderView* fv = shellView.getFolderView();
fv->SetCurrentViewMode(mode);
fv->Release();
} catch (...) {
}
}
private:
void version(Action& action)
{
showMessageDialog(_T("Version"),
_T("SolShellBrowser Version 1.0.0.2\r\nCopyright(C) 2017 Antillia.com"),
MB_OK|MB_ICONINFORMATION);
}
private:
void refresh(Action& action)
{
try {
ShellView shellView = shellBrowser.queryActiveShellView();
shellView.refresh();
} catch (...) {
}
}
private:
void fileSelected(Action& action)
{
}
private:
long size(Event& event)
{
int w, h;
event.getSize(w, h);
int cw, ch;
viewMode.getSize(cw, ch);
viewMode.reshape(w-120, 0, 110, ch);
shellBrowser.reshape(0, ch+2, w, h-ch-2);
return 1;
}
};
}
// Program entry point.
void Main(int argc, TCHAR** argv)
{
OleInitialize(NULL);
ModuleFileName module(argv[0]);
const TCHAR* name = module.getFileName();
try {
Application applet(name, argc, argv);
Args args;
//args.set(XmNclassStyle, 0);
args.set(XmNwidth, 600);
args.set(XmNheight, 400);
SolShellBrowser explorer(applet, name, args);
explorer.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.