/*

File: test_wingui.cpp
Author: David Bergman

A simple test of the win32gui framework.

*/

#include <win32gui/pch/pch.hpp>

// The following two files are generated by
// Resource Splitter, a code generator that
// takes a Win32 resource as input
#include "win32gui_res/menus.hpp"
#include "win32gui_res/mydlg.hpp"

// This namespace is where Win32Gui resides
using namespace win32::gui;

// This namespace is where Resource Splitter puts
// the C++ types corresponding to the Win32
// resources
using namespace win32::gui::res_id;

// Extend the dialog widget, with the layout
// given by a Win32 resource
struct test_dlg : wnd_extend<dialog, test_dlg> {
  static int dialog_id();
};

int test_dlg::dialog_id()
{
  return dialog_id_;
}

// Handles events for the test dialog
struct test_dlg_handler :
  event_handler<test_dlg_handler, test_dlg>
{
  // Event handler for ANY command for the dialog,
  // which is specified by the 0 command
  handle_event on_anything() {
    msg_box(self, "Something happened...");
    return command<0>().
      HANDLED_BY(&me::on_anything);
  }

  // Event handler for the Cancel button, using
  // the default resource ID of IDCANCEL
  handle_event on_cancel() {
    msg_box(self, "You clicked Cancel :-(");
    return command<IDCANCEL>().
      HANDLED_BY(&me::on_cancel);
  }
};

// Act on a menu command "open file"
struct test_menu_handler :
  event_handler<test_menu_handler, sdi_frame>
{
  handle_event on_open() {
    msg_box(self, "Opening file...");
    return command<menu_::arch_open>().
      HANDLED_BY(&me::on_open);
  }
  handle_event on_save() {
    msg_box(self, "Saving file...");
    return command<menu_::arch_save>().
      HANDLED_BY(&me::on_save);
  }
};

int APIENTRY WinMain(HINSTANCE hInstance,
		     HINSTANCE hPrevInstance,
		     LPSTR lpCmdLine,
		     int nCmdShow)
{
  // Create an SDI frame with a menu attached,
  // and also a dialog on
  //top of that just to show off

  wnd<sdi_frame> root = create_wnd<sdi_frame>
    ("Testing Win32Gui",
     null_wnd,
     create_info().menu(menu_::main_menu));
  create_dlg<test_dlg>(root);
  create_wnd<status_bar>(root);

  // Wait for the event loop to end

  root->wait();
}

