SOL9 2.0 Sample: TransparentButton

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * TransparentButton.cpp 
 * Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
// 2000.02.18


#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,  50);
        ar.set(XmNheight, 50);
        ar.set(XmNstyle,  (ulong)WS_BORDER);
        ar.set(XmNcursor, (ulong)LoadCursor(NULL, IDC_HAND));

        transb.create(this, NULL, ar);

        transb.addCallback(XmNarmCallback, this,
            (Callback)&AppView::arm, NULL);
            

        addEventHandler(WM_PAINT, this,
            (Handler)&AppView::paint, 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, sizeof(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 arm(Action& action)
    {        
        //Printf("AppView::Arm called \r\n");
        showMessageDialog(_T("SOL9"), _T("Transparent Button clicked"));
    }

private:
    void open(Action& action)
    {
        TCHAR dir[MAX_PATH];
        memset(dir, (TCHAR)0, SizeOf(dir));
        if (restoreFileFolder(dir, sizeof(dir))) {
            Args ar;
            ar.set(XmNdirectory, dir);
            filedlg.setValues(ar);
        }

        if(filedlg.open() == IDOK) {
            TCHAR* filename = filedlg.getFileName();
            TCHAR title[256];
            ClientDC cdc(this);

            //Load an original image.
            loadedImage.load(cdc, filename);
            
            //2008/09/16
            saveFileFolder(filename);
            invalidate((RECT*)NULL);

            update();

            _stprintf(title, _T("%s - TransparentButton"), filename);
            
            setText(title);

        }
    }

private:
    long paint(Event& event)
    {
        PaintDC pdc(this);
        loadedImage.draw(pdc, 10, 10);

        return 0L;
    }
};

}
//
void    Main(int argc, TCHAR** argv)
{
    const String appClass = "TransparentButton";
    try {
        Application applet(appClass, argc, argv);

        Args args;
        args.set(XmNclassStyle, NO_REDRAW);
        AppView appView(applet, appClass, args);
        appView.realize();

        applet.run();
    } catch (...) {

    }
}


Last modified: 11 Nov 2009

Copyright (c) 2009 Antillia.com ALL RIGHTS RESERVED.