/*************************************************************************** 
 *                                                                         *
 *    File:         kino.cpp                                               *
 *                                                                         *
 *    Description:  This file contains the main entry point into the       *
 *                  Test Program system.                                   *
 *                                                                         *
 *    Copyright:    (C) Copyright Home Ltd 1996.                           *
 *                  All Rights Reserved.                                   *
 *                                                                         *
 *    Date:         30 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 "kino.hpp"


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

static void GuiSetup (void);


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

WINDOW  wMainFrame;                              /* MainFrame info         */


Image   frameImage;


/*************************************************************************** 
 *                                                                         *
 *    Function:     main                                                   *
 *                                                                         *
 *    Description:  This is main entry point into the                      *
 *                  Test Program application.                              *
 *                                                                         *
 ***************************************************************************/

int main (int argc, char *argv[])
{
    SWCNTRL  swctl;
    PAPPINFO pApp;
    
   /******************************
    * Initialize the application *
    ******************************/
    
    GuiInitApp ("kino", "Test Program");
    GuiSaveCmdLine (argc, argv);
    
    pApp = GuiAppInfo ();
    GuiInitWindows (pApp);
    GuiSetup ();
    
   /********************************
    * Load and display main window *
    ********************************/
    
    GuiSetWindow (&wMainFrame, IDD_MAINFRAME, WT_DIALOG, MainFrameWndProc, (HMODULE)0);
    if  (GuiLoadWindow (&wMainFrame, GuiDesktopWindow ()))
    {
       /*************************
        * Add entry to tasklist *
        *************************/
        
        strcpy (swctl.szSwtitle, pApp->szPgmTitle);
        
        swctl.hwnd          = wMainFrame.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 = wMainFrame.hwnd;
        GuiProcessWindow (&wMainFrame);
        GuiUnloadWindow (&wMainFrame);
    }
    
   /**************************
    * 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);
    GuiRegisterMLE (pApp->hab);
    GuiRegisterStatic (pApp->hab);
}


/*************************************************************************** 
 *                                                                         *
 *    Function:     MainFrameWndProc                                       *
 *                                                                         *
 *    Description:  This is the window procedure handler for the           *
 *                  MainFrame window.                                      *
 *                                                                         *
 ***************************************************************************/

PMENTRY MainFrameWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
    MRESULT mResult = FALSE;
    
    if  (msg == WM_GUIGETWINDOW)
    {
        *((PWINDOW)mp2) = wMainFrame;
        return (FALSE);
    }
    
    /* Check if window fully loaded */
    if  (!wMainFrame.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_PUSHBUTTONSTART:
                      MainFramePushButtonStartClick ();
                      break;
                 case IDD_PUSHBUTTONSTOP:
                      MainFramePushButtonStopClick ();
                      break;
                 case IDD_PUSHBUTTONNEXT:
                      MainFramePushButtonNextClick ();
                      break;
                 
                 default:
                      break;
             }
             return (mResult);
        
       /**************************
        * Window is being loaded *
        **************************/
        
        case WM_GUIWINDOWLOADED:
             MainFrameCreate ();
             return (FALSE);
        
       /*************************
        * Control notifications *
        *************************/
        
        case WM_CONTROL:
             if  (!GuiEventLoop (mp1))
                 break;
             switch (SHORT1FROMMP (mp1))
             {
                 case IDD_MLE:
                      switch (SHORT2FROMMP (mp1))
                      {
                          case MLN_CHANGE:
                               MainFrameMLEChange ();
                               break;
                      }
                      break;
             }
             GuiEventLoop (0);
             return (mResult);
        
        default:
             break;
    }
    
    return (GuiDefFrameProc (WinDefDlgProc, hwnd, msg, mp1, mp2));
}


void MainFramePushButtonStartClick (void)
{
    frameImage = Image (String("stas1.bmp"));
}


void MainFramePushButtonStopClick (void)
{
    Image (String("Stas7.bmp"));
}


void MainFramePushButtonNextClick (void)
{
    Image (String("stas7.bmp"));
}


void MainFrameCreate (void)
{
    GuiSetColor (&wMainFrame, PP_BACKGROUNDCOLOR, RGB_BLUE);
}


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


