1 Screenshot
2 Source code
/*
* ExCombo.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.18
// 2009/11/06 Modified to use Icon in ExComboBox and IconedFileList.
#define COMMONCONTROLS_V6
#include <sol\ApplicationView.h>
#include <sol\ListBox.h>
#include <sol\Directory.h>
#include <sol\StringTokenizer.h>
#include <sol\ExtendedComboBox.h>
#include <sol/SystemImageList.h>
#include <sol/FileInfo.h>
#include <sol/IconedFileList.h>
#include "resource.h"
namespace SOL {
class MainView :public ApplicationView {
private:
ExtendedComboBox comboBox;
IconedFileList listView;
SystemImageList imageList;
public:
MainView(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name, args)
{
Args ar;
ar.set(XmNstyle, (ulong)CBS_DROPDOWNLIST);
ar.set(XmNheight, 200);
comboBox.create(this, NULL, ar);
comboBox.setImageList(imageList);
comboBox.addCallback(XmNselChangeCallback, this,
(Callback)&MainView::selected, NULL);
ar.reset();
ar.set(XmNexStyle, (ulong)WS_EX_CLIENTEDGE);
ar.set(XmNstyle, (ulong)LVS_SORTASCENDING | LVS_REPORT);//
listView.create(this, _T(""), ar);
addCallback(XmNmenuCallback, IDM_EXIT, this,
(Callback)&MainView::exit, NULL);
//TCHAR buff[_MAX_PATH];
String buff;
Directory dir;
dir.getCwd(buff);//, sizeof(buff));
FileInfo fileInfo;
int iconId = fileInfo.getSmallIconIndex((const TCHAR*)buff);
COMBOBOXEXITEM item;
memset(&item, 0, sizeof(item));
item.mask= CBEIF_TEXT|CBEIF_INDENT|CBEIF_IMAGE|CBEIF_SELECTEDIMAGE;
item.iImage = iconId;
item.iSelectedImage = iconId;
StringTokenizer tokenizer((const TCHAR*)buff);
tokenizer.clearSeparator();
tokenizer.addSeparator('\\');
const TCHAR* ptr = (const TCHAR*)buff;
int n = 0;
String root = "";
while (tokenizer.hasMoreToken()) {
String string;
ptr = tokenizer.getToken(string);
item.pszText = (TCHAR*)(const TCHAR*)string;
item.cchTextMax = string.getLength();
item.iItem = n;
item.iIndent = n;
comboBox.insertItem(&item);
if (n == 0) {
root = string;
}
n++;
}
//Show root folder
comboBox.setCurSel(0);
listView.findFiles(root);
}
private:
void selected(Action& action)
{
COMBOBOXEXITEM item;
memset(&item, 0, sizeof(item));
item.mask= CBEIF_TEXT|CBEIF_INDENT;
int n = comboBox.getCurSel();
StringBuffer dir;
for (int i = 0; i<=n; i++) {
TCHAR text[_MAX_PATH];
item.pszText = text;
item.cchTextMax = CountOf(text);
item.iItem = i;
comboBox.getItem(&item);
dir.append(text);
dir.append(_T("\\"));
}
//dir.append(_T("*.*"));
setText(dir.getBuffer());
//listView.clear();
listView.deleteAllItems();
listView.findFiles(dir.getBuffer());
}
private:
long size(Event& event)
{
int w, h;
event.getSize(w, h);
int h1 = comboBox.get(XmNheight);
comboBox.reshape(0, 0, w, h1);
listView.reshape(0, h1+2, w, h-h1-4);
return 0L;
}
};
}
// MainView 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));
MainView mainView(applet, name, args);
mainView.realize();
applet.run();
} catch (Exception& ex) {
caught(ex);
} catch (...) {
caught(UnknownException());
}
}
Last modified: 1 Feb 2017
Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.