/*************************************************************************** 
 *                                                                         *
 *    File:         Event.cpp                                              *
 *                                                                         *
 *    Description:  This file contains the main entry point into the       *
 *                  Mouse and Keyboard Events system.                      *
 *                                                                         *
 *    Copyright:    (C) Copyright "Des" inc 1997.                          *
 *                  All Rights Reserved.                                   *
 *                                                                         *
 *    Date:         09 May 1997                                            *
 *                                                                         *
 *    Note:         Generated by the Guidelines code generation facility.  *
 *                                                                         *
 ***************************************************************************/

#define INCL_PM
#define INCL_NLS
#define INCL_BASE

#define GUIDELINES "3.1A"

#include <os2.h>                                 /* OS/2 include file      */
#include <stdio.h>                               /* Standard I/O functions */
#include <stdlib.h>                              /* Misc. functions        */
#include <string.h>                              /* String functions       */

#include "Event.hpp"


/*************************************************************************** 
 *    Private functions.                                                   *
 ***************************************************************************/

static void GuiSetup (void);


/*************************************************************************** 
 *    Global variables.                                                    *
 ***************************************************************************/

WINDOW  wDialog;                                 /* Dialog info            */
WINDOW  wDialog1;                                /* Dialog1 info           */




/*************************************************************************** 
 *                                                                         *
 *    Function:     main                                                   *
 *                                                                         *
 *    Description:  This is main entry point into the                      *
 *                  Mouse and Keyboard Events application.                 *
 *                                                                         *
 ***************************************************************************/

int main (int argc, char *argv[])
{
    SWCNTRL  swctl;
    PAPPINFO pApp;
    
   /******************************
    * Initialize the application *
    ******************************/
    
    GuiInitApp ("Event", "Mouse and Keyboard Events");
    GuiSaveCmdLine (argc, argv);
    
    pApp = GuiAppInfo ();
    GuiInitWindows (pApp);
    GuiSetup ();
    
   /********************************
    * Load and display main window *
    ********************************/
    
    GuiSetWindow (&wDialog, IDD_DIALOG, WT_DIALOG, DialogWndProc, (HMODULE)0);
    if  (GuiLoadWindow (&wDialog, GuiDesktopWindow ()))
    {
       /*************************
        * Add entry to tasklist *
        *************************/
        
        strcpy (swctl.szSwtitle, pApp->szPgmTitle);
        
        swctl.hwnd          = wDialog.hwnd;
        swctl.hwndIcon      = (HWND)0;
        swctl.hprog         = (HPROGRAM)0;
        swctl.idProcess     = pApp->pid;
        swctl.idSession     = 0;
        swctl.uchVisibility = SWL_VISIBLE;
        swctl.fbJump        = SWL_JUMPABLE;
        
        WinAddSwitchEntry (&swctl);
        
       /*******************************
        * Process the window template *
        *******************************/
        
        pApp->hwndMain = wDialog.hwnd;
        GuiProcessWindow (&wDialog);
        GuiUnloadWindow (&wDialog);
    }
    
   /**************************
    * Termination processing *
    **************************/
    
    GuiExitWindows ();
    
    return (pApp->sExitCode);
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     GuiSetup                                               *
 *                                                                         *
 *    Description:  This routine performs any processing required          *
 *                  to initialize the runtime environment for this         *
 *                  application or DLL.                                    *
 *                                                                         *
 ***************************************************************************/

static void GuiSetup (void)
{
    PAPPINFO pApp = GuiAppInfo ();
    
    GuiRegisterButton (pApp->hab);
    GuiRegisterStatic (pApp->hab);
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     DialogWndProc                                          *
 *                                                                         *
 *    Description:  This is the window procedure handler for the           *
 *                  Dialog window.                                         *
 *                                                                         *
 ***************************************************************************/

PMENTRY DialogWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
    MRESULT mResult = FALSE;
    
    if  (msg == WM_GUIGETWINDOW)
    {
        *((PWINDOW)mp2) = wDialog;
        return (FALSE);
    }
    
    /* Check if window fully loaded */
    if  (!wDialog.hwnd)
        return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
    
    switch (msg)
    {
       /***********************
        * Property processing *
        ***********************/
        
        case WM_GUIGETPROPERTY:
        case WM_GUISETPROPERTY:
             break;
        
       /*******************************
        * Window resized/repositioned *
        *******************************/
        
        case WM_WINDOWPOSCHANGED:
             {
                 PSWP pSwp = (PSWP) mp1;
                 if  (pSwp->fl & SWP_SIZE)
                 {
                     GuiBroadcastMsg (hwnd, WM_GUIPARENTRESIZED, 0, 0);
                 }
             }
             break;
        
       /***************************
        * User command processing *
        ***************************/
        
        case WM_COMMAND:
             switch (SHORT1FROMMP (mp1))
             {
                 case IDD_PUSHBUTTON:
                      DialogPushButtonClick ();
                      break;
                 
                 default:
                      break;
             }
             return (mResult);
        
        default:
             break;
    }
    
    return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
}


void DialogPushButtonClick (void)
{
    GuiExitApp ((SHORT)0);
}

void EventTable (void)
{
    GuiExitApp ((SHORT)0);
}


