SOL9 Sample: HotKey

SOL9 2.0 Samples

1 Screenshot


2 Source code

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



// SOL++2000 
// 2000.02.18

#define COMMONCONTROLS_V6

#include <sol\ApplicationView.h>
#include <sol\FileDialog.h>
#include <sol\RichText.h>
#include <sol\HotKey.h>
#include <sol/MessageFont.h>
#include "resource.h"

namespace SOL {

class AppView :public ApplicationView {
private:
  FileDialog  filedlg;
  HotKey      hotKey;
  RichText    richText;
  MessageFont font;

public:
  /**
   * Constructor
   */
  AppView(Application& applet, const TCHAR* label, Args& args)
    :ApplicationView(applet, label, args)
  {
    Args ar;
   
    ar.set(XmNstyle, (ulong)WS_VSCROLL|ES_AUTOVSCROLL|ES_MULTILINE);
    richText.create(this, _T(""), ar);

    ar.reset();
    ar.set(XmNx,     2);
    ar.set(XmNy,      2);
    ar.set(XmNwidth,  100);
    ar.set(XmNheight, 26);
    ar.set(XmNexStyle, (ulong)WS_EX_WINDOWEDGE);
    hotKey.create(this, _T(""), ar);

    //2009/11/04
    font.create(9);
    hotKey.setFont(font);

    WORD keyComb =  MAKEWORD('X', HOTKEYF_CONTROL);
    hotKey.setHotKey('X', HOTKEYF_CONTROL);    

    send(WM_SETHOTKEY, keyComb, 0);

    ar.reset();
    ar.set(XmNfilter, _T("(All Files *.*)\0 *.*\0"));
    filedlg.create(this, _T("Open"), ar);

    addCallback(XmNmenuCallback, IDM_OPEN, this, 
      (Callback)&AppView::open, NULL);
    addCallback(XmNmenuCallback, IDM_EXIT, this, 
      (Callback)&AppView::exit, NULL);

    addEventHandler(WM_SYSCOMMAND, this, 
      (Handler)&AppView::sysCommand, NULL);

    restorePlacement();
  }

private:
  void open(Action& action)
  {
    filedlg.popup(action);
    if(action.getResult()) {
      TCHAR* name = filedlg.getFileName();
      if(name) {
        richText.load(name);
      }
    }
  }

private:
  long size(Event& event)
  {
    LPARAM l = event.getLParam();
    int w, h;
    hotKey.getSize(w, h);

    richText.reshape(2, h+2, LOWORD(l)-4, HIWORD(l)-h-2-2);
    return NULL;
  }

private:
  long sysCommand(Event& event)
  {
    if(event.getWParam() == SC_HOTKEY) {
      show(SW_MINIMIZE);
      return NULL;
    }
    else {
      return defaultProc(event);
    }
  }
};

}

//
void  Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();
  try {
    Application applet(name, argc, argv);

    Args args;
    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.