SOL9 Sample: FileOpenSaveDialog
|
1 Screenshot
2 Source code
/*
* FileOpenSaveDialog.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.18
#define COMMONCONTROLS_V6
#include <sol\ApplicationView.h>
#include <sol\ScrolledText.h>
#include <sol\shell\FileOpenDialog.h>
#include <sol\shell\FileSaveDialog.h>
#include <sol\shell\ShellItemArray.h>
#include <sol\shell\ShellItem.h>
#include <sol\ole\OleInitializer.h>
#include "MenuID.h"
namespace SOL {
class AppView :public ApplicationView {
private:
ScrolledText scrolledText;
FileOpenDialog openDialog;
FileSaveDialog saveDialog;
_bstr_t displayName;
_bstr_t defaultExtension;
public:
//Constructor
AppView(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name, args)
{
Args ar;
scrolledText.create(this, _T(""), ar);
add(&scrolledText);
displayName = _T("");
static const COMDLG_FILTERSPEC fileSpec[] = {
{ L"Text files", L"*.txt;*.text" },
{ L"C++ files", L"*.h;*.cpp" },
{ L"All", L"*.*" }
};
openDialog.setFileTypes(CountOf(fileSpec), fileSpec);
saveDialog.setFileTypes(CountOf(fileSpec), fileSpec);
addCallback(XmNmenuCallback, ID_OPEN, this,
(Callback)&AppView::open, NULL);
addCallback(XmNmenuCallback, ID_SAVE, this,
(Callback)&AppView::save, NULL);
addCallback(XmNmenuCallback, ID_EXIT, this,
(Callback)&AppView::exit, NULL);
restorePlacement();
}
private:
//Open menuCallback
void open(Action& action)
{
try {
openDialog.show((HWND)*this);
SOL::ShellItem item = openDialog.getResult();
displayName = item.getDisplayName(SIGDN_FILESYSPATH); //, &path);
scrolledText.load((TCHAR*)(const TCHAR*)displayName);
TCHAR title[MAX_PATH*2];
_stprintf_s(title, CountOf(title), _T("Opened:%s - FileDialog"), (const TCHAR*)displayName);
setText(title);
} catch (Exception& ex) {
caught(ex);
} catch (...) {
caught(UnknownException());
;// Probably, [Cancel] button has been clicked, or other errors have happend.
}
}
private:
//Save menuCallback
void save(Action& action)
{
try {
saveDialog.setFileName((const wchar_t*)displayName);
saveDialog.show((HWND)*this);
SOL::ShellItem item = saveDialog.getResult();
displayName = item.getDisplayName(SIGDN_FILESYSPATH);
scrolledText.save((TCHAR*)(const TCHAR*)displayName);
TCHAR title[MAX_PATH*2];
_stprintf_s(title, CountOf(title), _T("Saved:%s - FileDialog"), (const TCHAR*)displayName);
setText(title);
} catch (Exception& ex) {
caught(ex);
} catch (...) {
caught(UnknownException());
;// Probably, [Cancel] button has been clicked, or other errors have happend.
}
}
};
}
void Main(int argc, TCHAR** argv)
{
OleInitializer initializer;
ModuleFileName module(argv[0]);
const TCHAR* name = module.getFileName();
try {
Application applet(name, argc, argv);
Args args;
AppView appView(applet, name, args);
appView.realize();
applet.run();
} catch (Exception& ex) {
caught(ex);
} catch (...) {
caught(UnknownException());
}
}
Last modified: 1 Feb 2017
Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.