SOL9 Sample: ComboBoxColorChooser

SOL9 2.0 Samples

1 Screenshot


2 Source code

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



// SOL9 2.0 
// 2012/05/28 Sample program to use SOL::ColorComboBox class


#include <sol\ApplicationView.h>

#include <sol\ComboBoxColorChooser.h>
#include <sol\ColorBox.h>

#include "resource.h"

namespace SOL {

class MainView :public ApplicationView {

private:
  ComboBoxColorChooser  colorChooser;

  ColorBox colorBox;
  COLORREF rgb;

public:
  MainView(Application& applet, const TCHAR* caption, Args& args)
        :ApplicationView(applet, caption, args.set(XmNstyle, WS_CLIPCHILDREN)) 
  {
    Args ar;
    ar.reset();
    ar.set(XmNstyle, WS_VISIBLE);
    ar.set(XmNitemHeight, 32);
    //ar.set(XmNrgbStep, 0x33);
    ar.set(XmNrgbStep, 0x20);
    colorChooser.create(this, _T(""), ar);
  
    ar.reset();
    colorBox.create(this, _T(""), ar);
    // Set color white
    colorBox.setColor(RGB(255,255,255));

    addEventHandler(WM_COMBOBOX_COLORCHOOSER_SELCHANGED, this,
      (Handler)&MainView::colorChoosed, NULL);

    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&MainView::exit, NULL);
  
    restorePlacement();
  }

private:
  long colorChoosed(Event& event)
  {
    rgb = (COLORREF)event.getLParam();
    colorBox.setColor(rgb);
    return 0L;
  }

private:
  long size(Event& event)
  {
    int width, height;
    event.getSize(width, height);

    ClientDC dc(this);
    int h = dc.getTextHeight();
    colorChooser.reshape(4,  4, 180, height-10);
    colorBox.reshape(200, 4, width - 200-10, height- 10);

    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(XmNbackground, (COLOR_BTNFACE +1));
    MainView 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.