SOL9 Sample: BitmapViewer
|
1 Screenshot
2 Source code
/*
* BitmapViewer.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.16
// 2008/09/13 Modified to use DIBSection class.
// 2008/09/16 Modified to use restoreFileFolder/saveFileFolder to manage a selected folder
// in FileDialog.
#define COMMONCONTROLS_V6
#include <sol\ApplicationView.h>
#include <sol\PaintDC.h>
#include <sol\ClientDC.h>
#include <sol\FileDialog.h>
#include <sol\DIBSection.h>
#include <sol\Profile.h>
#include <sol\Folder.h>
#include "resource.h"
namespace SOL {
class BitmapViewer :public ApplicationView {
private:
DIBSection loadedImage;
FileDialog fileDialog;
public:
/**
* Constructor
*/
BitmapViewer(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name,
args.set(XmNstyle, (ulong)WS_VSCROLL|WS_HSCROLL))
{
addCallback(XmNmenuCallback, IDM_OPEN, this,
(Callback)&BitmapViewer::open, NULL);
addCallback(XmNmenuCallback, IDM_EXIT, this,
(Callback)&BitmapViewer::exit, NULL);
addCallback(XmNmenuCallback, IDM_VERSION, this,
(Callback)&BitmapViewer::version, NULL);
addEventHandler(WM_PAINT, this,
(Handler)&BitmapViewer::paint, NULL);
addEventHandler(WM_SIZE, this,
(Handler)&BitmapViewer::size, NULL);
addEventHandler(WM_CLOSE, this,
(Handler)&BitmapViewer::close, NULL);
Args ar;
ar.set(XmNfilter, _T("BitmapFiles (*.bmp)\0 *.bmp\0"));
fileDialog.create(this, _T(""), ar);
restorePlacement();
}
public:
~BitmapViewer()
{
}
private:
long BitmapViewer::close(Event& event)
{
savePlacement();
return defaultProc(event);
}
private:
void open(Action& action)
{
Args ar;
TCHAR dir[MAX_PATH];
memset(dir, (TCHAR)0, CountOf(dir));
//Call getFileFolder method in SOL::ApplicationView.
//This gets a previously select folder from a registry(profile of this application) for fileDialog
if (restoreFileFolder(dir, CountOf(dir))) { //2012/06/26
ar.set(XmNdirectory, dir);
fileDialog.setValues(ar);
}
if(fileDialog.open()){
TCHAR title[MAX_PATH];
TCHAR* filename = fileDialog.getFileName();
TCHAR* ftitle = fileDialog.getFileTitle();
//Call saveFileFolder method in SOL::ApplicationView.
saveFileFolder(filename);
ClientDC cdc(this);
loadedImage.load(cdc, filename);
_stprintf_s(title, CountOf(title), _T("%s - BitmapViewer"), filename);
setText(title);
setScrollPos(HORIZONTAL, 0);
setScrollPos(VERTICAL, 0);
updateScrollRange();
invalidate((const RECT*)NULL);
update();
}
}
private:
void updateScrollRange()
{
int bw = loadedImage.getWidth();
int bh = loadedImage.getHeight();
setScrollExtent(bw, bh);
}
private:
long size(Event& event)
{
updateScrollRange();
return 0;
}
private:
void version(Action& action)
{
showMessageDialog(_T("Version"),
_T("BitmapViewer 1.0.0.2 \r\n Copyright(c) 2009 Antillia.com"), MB_ICONINFORMATION|MB_OK);
}
private:
long paint(Event& event)
{
int x = getScrollPos(Composite::HORIZONTAL);
int y = getScrollPos(Composite::VERTICAL);
PaintDC pdc(this);
loadedImage.draw(pdc, -x, -y);
return 0;
}
};
}
//////////////////////////////////////////////
//
void Main(int argc, TCHAR** argv)
{
ModuleFileName module(argv[0]);
const TCHAR* appClass = module.getFileName(); //_T("BitmapViewer");
try {
Application applet(appClass, argc, argv);
Args args;
BitmapViewer bitmapView(applet, appClass, args);
bitmapView.realize();
applet.run();
} catch (Exception& ex) {
caught(ex);
}
}
Last modified: 1 Feb 2017
Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.