SOL9 Sample: DynamicIcon

SOL9 2.0 Samples

1 Screenshot


2 Source code

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



// SOL++2000 
// 2000.02.18


#include <sol\ApplicationView.h>
#include <sol\PushButton.h>
#include "resource.h"

namespace SOL {

class DynamicIcon :public ApplicationView {
private:

  int      num;

  PushButton** pushb;

public:
  /**
   * Constructor
   */
  DynamicIcon(Application& applet, const TCHAR* label, Args& args)
  :ApplicationView(applet, label, args)
  {
    static Arg params[] = {
    {_T("IDI_APPLICATION"),  (ulong)IDI_APPLICATION},
    {_T("IDI_ASTERISK"),     (ulong)IDI_ASTERISK},
    {_T("IDI_EXCLAMATION"),  (ulong)IDI_EXCLAMATION},
    {_T("IDI_HAND"),       (ulong)IDI_HAND},
    {_T("IDI_QUESTION"),     (ulong)IDI_QUESTION},
    };

    Args ar;
    num = XtNumber(params);
    pushb = new PushButton*[num];

    for(int i = 0; i<XtNumber(params); i++) {
      ar.reset();
      pushb[i] = new PushButton(this, params[i].name,  ar);
      pushb[i] -> addCallback(XmNactivateCallback, this,
        (Callback)&DynamicIcon::setIcon, 
        (void*)LoadIcon(NULL, (TCHAR*)params[i].value));
    }
    addCallback(XmNmenuCallback, IDM_EXIT, this, 
      (Callback)&DynamicIcon::exit, NULL);
  }

public:
  ~DynamicIcon()
  {
    for(int i = 0; i<num; i++) {
      delete pushb[i];
    }
    delete [] pushb;
  }

private:
  long DynamicIcon::size(Event& event)
  {
    int h = pushb[0]->get(XmNheight);
    for(int i = 0; i<num; i++) {
      pushb[i] -> setLocation(10, 10+(h+10)*i);
    }
    return 0L;
  }

private:
  void DynamicIcon::setIcon(Action& action)
  {
    HICON icon = (HICON)action.getData();
    // Set a new icon.
    set(XmNwindowIcon, (ulong)icon);
    show(SW_MINIMIZE);
  }
};

}


//  Sample main
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(XmNwidth,  300);
    args.set(XmNheight, 300);
    DynamicIcon dicon(applet, name, args);
    dicon.realize();

    applet.run();
  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  }
}


Last modified: 1 Feb 2017

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