SOL9 Sample: TransparentButton
|
1 Screenshot
2 Source code
/*
* TransparentButton.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.02.18
// 2012/07/06
#define COMMONCONTROLS_V6
#include <sol\ApplicationView.h>
#include <sol\DIBitmapFile.h>
#include <sol\DIBSection.h>
#include <sol\PaintDC.h>
#include <sol\ClientDC.h>
#include <sol\FileDialog.h>
#include <sol\TransparentButton.h>
#include "resource.h"
#include <sol\stdio.h>
namespace SOL {
class AppView :public ApplicationView {
private:
TransparentButton transb;
DIBSection loadedImage;
FileDialog filedlg;
public:
/**
* Constructor
*/
AppView(Application& applet, const TCHAR* name, Args& args)
:ApplicationView(applet, name,
args.set(XmNstyle, (ulong)(WS_VSCROLL|WS_HSCROLL) ))
{
Args ar;
ar.set(XmNx, 20);
ar.set(XmNy, 20);
ar.set(XmNwidth, 200);
ar.set(XmNheight, 60);
ar.set(XmNtextColor, RGB(0xff, 0, 0));
ar.set(XmNtextAlignment, DT_LEFT); //DT_CENTER);
ar.set(XmNstyle, (ulong)WS_BORDER);
ar.set(XmNcursor, (ulong)LoadCursor(NULL, IDC_HAND));
transb.create(this,
// _T("Press me"),
_T("TransparentButton\nPress me"),
ar);
transb.disable();
transb.enable();
transb.addCallback(XmNactivateCallback, this,
(Callback)&AppView::activate, NULL);
addEventHandler(WM_PAINT, this,
(Handler)&AppView::paint, NULL);
addEventHandler(WM_MOUSEMOVE, this,
(Handler)&AppView::mouseMove, NULL);
addCallback(XmNmenuCallback, ID_OPEN, this,
(Callback)&AppView::open, NULL);
addCallback(XmNmenuCallback, ID_EXIT, this,
(Callback)&AppView::exit, NULL);
TCHAR dir[_MAX_PATH];
::GetWindowsDirectory(dir, CountOf(dir));
TCHAR* p = (TCHAR*)strchr(dir, (TCHAR)'\\');
if (p) {
p++;
*p = '\0';
}
ar.reset();
ar.set(XmNdirectory, dir);
ar.set(XmNfilter, _T("Bitmap (*.bmp)\0 *.bmp\0"));
filedlg.create(this, _T("FileSelection"), ar);
}
public:
~AppView()
{
}
private:
void activate(Action& action)
{
//Printf("AppView::Arm called \r\n");
showMessageDialog(_T("SOL9"), _T("Transparent Button has been clicked"));
}
private:
void open(Action& action)
{
TCHAR dir[MAX_PATH];
memset(dir, (TCHAR)0, CountOf(dir));
if (restoreFileFolder(dir, CountOf(dir))) {
Args ar;
ar.set(XmNdirectory, dir);
filedlg.setValues(ar);
}
if(filedlg.open() == IDOK) {
TCHAR* filename = filedlg.getFileName();
TCHAR title[1024];
ClientDC cdc(this);
//Load an original image.
loadedImage.load(cdc, filename);
//2008/09/16
saveFileFolder(filename);
invalidate((RECT*)NULL);
update();
_stprintf_s(title, CountOf(title), _T("%s - TransparentButton"), filename);
setText(title);
}
}
private:
long paint(Event& event)
{
PaintDC pdc(this);
loadedImage.draw(pdc, 10, 10);
return 0L;
}
long mouseMove(Event& event)
{
//getMousePosition();
POINT p;
getCursorPos(&p);
TCHAR pos[1024];
_stprintf_s(pos, CountOf(pos), _T("POS x=%d y=%d"), p.x, p.y);
setText(pos);
return 0;
}
};
}
//
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(XmNclassStyle, NO_REDRAW);
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.