SOL9 Sample: TrackBar

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL++2000
// 2000.02.18
// 2012/06/29

#define COMMONCONTROLS_V6

#include <sol\ApplicationView.h>
#include <sol\TrackBar.h>
#include <sol\Static.h>
#include <sol\PaintDC.h>
#include <sol\Brush.h>
#include "resource.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, 0xff);
      trackBar[i].setPos(192);
    }
    color = RGB(192, 192, 192);
    addEventHandler(WM_DRAWITEM, this, 
      (Handler)&AppView::drawItem, NULL);
    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&AppView::exit, 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]);
    TCHAR caption[1024];
    //_stprintf(caption, _T("RGB(%02x,%02x,%02x) - TrackBar"), pos[0], pos[1], pos[2]);
    _stprintf_s(caption, _T("RGB(%02x,%02x,%02x) - TrackBar"), pos[0], pos[1], pos[2]);

    setText(caption);

    item.update(NULL);
    return 0L;
  }

private:
  //2012/06/29
  long drawItem(Event& event)
  {
    LPARAM lParam = event.getLParam();
    DRAWITEMSTRUCT* ptr = (DRAWITEMSTRUCT*)lParam;
    DC dc = ptr->hDC;

    Brush brush(color);

    HBRUSH oldb = (HBRUSH)dc.select(brush);
    dc.rectangle(0, 0, 200, 50);
    dc.select(oldb);

    return 0L;
  }
};

}

//
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, 0);
    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.