1 Screenshot
2 Source code
/*
* ModalDialog.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 1999.09.25 Modified
// 2000.02.18
#define COMMONCONTROLS_V6
#include <sol\ApplicationView.h>
#include <sol\ScrolledText.h>
#include <sol\ModalDialog.h>
#include <sol\Text.h>
#include <sol\ListBox.h>
#include "resource.h"
namespace SOL {
class FileDlg : public ModalDialog {
private:
Text* text;
ListBox* listbox;
private:
void changeDir(Action& action)
{
TCHAR dir[MAX_PATH];
WPARAM attribute = DDL_READWRITE|DDL_READONLY|DDL_HIDDEN |\
DDL_SYSTEM|DDL_ARCHIVE|DDL_DIRECTORY;
text -> getText(dir, CountOf(dir)); //2012/06/26
TCHAR pattern[MAX_PATH];
_stprintf_s(pattern, CountOf(pattern), _T("%s\\*.*"), dir);
listbox -> resetContent();
listbox -> dir(attribute, pattern);
}
public:
FileDlg(View* parent, const TCHAR* caption, Args& args)
:ModalDialog(parent, caption,
args.set(XmNtemplateName, _T("FileName")))
{
text = NULL;
listbox = NULL;
}
public:
~FileDlg()
{
if(text) delete text;
if(listbox) delete listbox;
}
private:
long initDialog(Event& event)
{
if(text) delete text;
if(listbox) delete listbox;
text = new Text(this, getItem(IDC_EDIT));
listbox = new ListBox(this, getItem(IDC_LIST));
text -> setFocus();
text -> addCallback(XmNactivateCallback, this,
(Callback)&FileDlg::changeDir, NULL);
return NULL;
}
public:
void getFileName(TCHAR* fileName, int size)
{
TCHAR* dir = text -> getText();
TCHAR* file = listbox -> getCurText();
*fileName = ZERO;
if(dir && file) {
_stprintf_s(fileName, size, _T("%s\\%s"), dir, file);
}
delete [] dir;
delete [] file;
}
};
//
class AppView :public ApplicationView {
private:
FileDlg* fileDlg;
ScrolledText text;
private:
void ok(Action& action)
{
TCHAR fileName[MAX_PATH];
fileDlg->getFileName(fileName, CountOf(fileName)); //2012/06/26
text.load(fileName);
}
public:
AppView(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name, args)
{
Args ar;
ar.set(XmNtemplateName, _T("FileName"));
fileDlg = new FileDlg(this, NULL, ar);
ar.reset();
text.create(this, NULL, ar);
// 1999.09.25
add(text);
addCallback(XmNmenuCallback, ID_OPEN, fileDlg,
(Callback)&ModalDialog::popup, NULL);
addCallback(XmNmenuCallback, ID_EXIT, this,
(Callback)&AppView::exit, NULL);
fileDlg->addCallback(XmNactivateCallback, IDOK, this,
(Callback)&AppView::ok, NULL);
restorePlacement();
}
};
}
//
void Main(int argc, TCHAR** argv)
{
const TCHAR* appClass = _T("AppView");
try {
Application applet(appClass, argc, argv);
Args args;
AppView appView(applet, appClass, args);
appView.realize();
applet.run();
} catch (...) {
}
}
Last modified: 1 Feb 2017
Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.