SOL9 2.0 Sample: TrackBar

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL++2000
// 2000.02.18


#include <sol\ApplicationView.h>
#include <sol\TrackBar.h>
#include <sol\Static.h>
#include <sol\PaintDC.h>

namespace SOL {

class AppView :public ApplicationView {
private:
    COLORREF  color;
    Static   item;
    TrackBar trackBar[3];

public:
    /**
     * Constructor
     */
    AppView(Application& applet, const TCHAR* label, Args& args)
    :ApplicationView(applet, label, args)
    {
        Args ar;
        ar.set(XmNx, 10);
        ar.set(XmNy, 10);
        ar.set(XmNwidth,  200);
        ar.set(XmNheight,  50);
        ar.set(XmNstyle, (ulong)SS_OWNERDRAW);
        item.create(this, NULL, ar);

        for(int i = 0; i<3; i++) {
            ar.reset();
            ar.set(XmNx, 10);
            ar.set(XmNy, 70+60*i);
            ar.set(XmNwidth, 200);
            ar.set(XmNheight, 50);
            trackBar[i].create(this, NULL, ar);
            trackBar[i].setRange(0, 255);
            trackBar[i].setPos(192);
        }
        color = RGB(192, 192, 192);
        addEventHandler(WM_DRAWITEM, this, 
            (Handler)&AppView::drawItem, NULL);
    }

private:
    long horizScroll(Event& event)
    {
        int pos[3];
        for(int i = 0; i<3; i++) {
            pos[i] = (int)trackBar[i].getPos();
        }
        color = RGB(pos[0], pos[1], pos[2]);
    
        item.update(NULL);
        return 0L;
    }

private:

    long drawItem(Event& event)
    {
        LPARAM lParam = event.getLParam();
        DRAWITEMSTRUCT* ptr = (DRAWITEMSTRUCT*)lParam;
        HDC hdc = ptr->hDC;
        HBRUSH hb = ::CreateSolidBrush(color);
        HBRUSH oldb = (HBRUSH)::SelectObject(hdc, hb);
        ::Rectangle(hdc, 0, 0, 200, 50);
        ::SelectObject(hdc, oldb);
        ::DeleteObject(hb);

        return 0L;
    }
};

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

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

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

    }
}

Last modified: 11 Nov 2009

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