home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / os2tk21j / c / samples / clock / dialogs.c__ / dialogs.c
Encoding:
C/C++ Source or Header  |  1993-03-12  |  34.9 KB  |  1,023 lines

  1. /*static char *SCCSID = "@(#)dialogs.c    6.6 92/02/18";*/
  2. /*=========================================================================\
  3.  *                                                                         *
  4.  *       FILE:dialogs.c                                                    *
  5.  *                                                                         *
  6.  *       DESCRIPTION:    Dialog procedures for PM clock                    *
  7.  *                                                                         *
  8.  *                                                                         *
  9.  *                                                                         *
  10.  *      Copyright 1989, 1990, 1992 IBM Corp.                               *
  11.  *                                                                         *
  12.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is        *
  13.  *      sample code created by IBM Corporation. This sample code is not    *
  14.  *      part of any standard or IBM product and is provided to you solely  *
  15.  *      for  the purpose of assisting you in the development of your       *
  16.  *      applications.  The code is provided "AS IS", without               *
  17.  *      warranty of any kind.  IBM shall not be liable for any damages     *
  18.  *      arising out of your use of the sample code, even if they have been *
  19.  *      advised of the possibility of   such damages.                      *
  20.  *                                                                         *
  21.  *-------------------------------------------------------------------------*
  22.  *
  23.  *--------------------------------------------------------------
  24.  *
  25.  *  This source file contains the following functions:
  26.  *
  27.  *  ClkTicksDlgProc()
  28.  *  AlarmDialogsProc()
  29.  *  AboutBoxDialogProc()
  30.  *  SetAlarmField()
  31.  *  GetAlarmTime()
  32.  *  AlarmVScrolls()
  33.  *  EntryFieldSubProc()
  34.  *  AlarmSetTimer()
  35.  *  ClkColorsDlgProc()
  36. \*==============================================================*/
  37.  
  38. /*--------------------------------------------------------------*\
  39.  *  Include files, macros, defined constants, and externs
  40. \*--------------------------------------------------------------*/
  41.  
  42. #define INCL_WININPUT
  43. #define INCL_WINFRAMEMGR
  44. #define INCL_WINTRACKRECT
  45. #define INCL_WINMENUS
  46. #define INCL_WINSYS
  47. #define INCL_WINTIMER
  48. #define INCL_WINMESSAGEMGR
  49. #define INCL_WINDIALOGS
  50. #define INCL_WINBUTTONS
  51. #define INCL_WINENTRYFIELDS
  52. #define INCL_WINWINDOWMGR
  53. #define INCL_WINSCROLLBARS
  54. #define INCL_GPITRANSFORMS
  55. #define INCL_GPIPRIMITIVES
  56. #define INCL_GPILOGCOLORTABLE
  57. #define INCL_DOSSEMAPHORES
  58. #define INCL_DOSDATETIME
  59.  
  60. #include <os2.h>
  61. #include <time.h>
  62. #include <stdio.h>
  63. #include <stdlib.h>
  64. #include <string.h>
  65. #include "clock.h"
  66. #include "res.h"
  67. #include "clkdata.h"
  68. /*--------------------------------------------------------------*\
  69.  *  Global variables  and definitions for this file
  70. \*--------------------------------------------------------------*/
  71.  
  72. /*--------------------------------------------------------------*\
  73.  *  Entry point declarations
  74. \*--------------------------------------------------------------*/
  75.  
  76. VOID InitAlarm(HWND);
  77. VOID AlarmSet(HWND);
  78. VOID SetAlarmField(HWND, UCHAR, UCHAR);
  79. VOID GetAlarmTime(HWND, UCHAR *, UCHAR *);
  80. VOID AlarmVScrolls(HWND, USHORT, MPARAM);
  81. VOID AlarmSetTimer(UCHAR uchHour,UCHAR uchMinutes );
  82.  
  83. MRESULT EXPENTRY AlarmDlgProc(HWND hwnd , ULONG usItem,
  84.                                MPARAM mp1, MPARAM mp2 );
  85. MRESULT EXPENTRY EntryFieldSubProc(HWND hwnd, ULONG usItem,
  86.                                      MPARAM mp1, MPARAM mp2 );
  87. /**************************************************************************\
  88. *                                                                          *
  89. *       ROUTINE:    ClkTicksDlgProc ( )                                    *
  90. *                                                                          *
  91. *       COMMENT:    "Ticks..." dialog                                      *
  92. *                                                                          *
  93. *       RETURNS:    MRESULT, 0 or return value from WinDefDlgProc          *
  94. *                                                                          *
  95. \**************************************************************************/
  96.  
  97. MRESULT EXPENTRY ClkTicksDlgProc ( HWND hwnd , ULONG usMsg ,
  98.                                    MPARAM mp1 , MPARAM mp2 )
  99. {
  100.     static USHORT usMajorTickSel ;
  101.     static USHORT usMinorTickSel ;
  102.     USHORT usButtonID ;
  103.  
  104.     switch ( usMsg ) {
  105.  
  106.         case WM_INITDLG :
  107.  
  108.             /* show the current major tick preference */
  109.             WinSendMsg ( WinWindowFromID ( hwnd ,
  110.                                            ( CLKTM_MAJOR | cp.usMajorTickPref) ) ,
  111.                          BM_SETCHECK , MPFROM2SHORT ( TRUE , NULL ) , MPVOID) ;
  112.  
  113.             /* show the current minor tick preference */
  114.             WinSendMsg (  WinWindowFromID ( hwnd ,
  115.                                            (CLKTM_MINOR | cp.usMinorTickPref) ) ,
  116.                           BM_SETCHECK ,
  117.                           MPFROM2SHORT ( TRUE , 0 ) ,
  118.                           MPVOID ) ;
  119.  
  120.             /* load the selection values from the preferences */
  121.             usMajorTickSel = cp.usMajorTickPref ;
  122.             usMinorTickSel = cp.usMinorTickPref ;
  123.  
  124.             /* let the default dialog procedure handle anything else */
  125.             break ;
  126.  
  127.         case WM_COMMAND :
  128.  
  129.             switch ( LOUSHORT ( mp1 ) ) {
  130.  
  131.                 case DID_OK :
  132.  
  133.                     /* store away selections as preferences */
  134.                     cp.usMajorTickPref = usMajorTickSel ;
  135.                     cp.usMinorTickPref = usMinorTickSel ;
  136.  
  137.                     /* repaint with the new preferences */
  138.                     WinInvalidateRect ( hwndFrame , NULL, TRUE ) ;
  139.  
  140.                 case DID_CANCEL :
  141.                     WinDismissDlg ( hwnd , TRUE ) ;
  142.             }
  143.  
  144.             return NULL ;
  145.  
  146.         case WM_CONTROL :
  147.  
  148.             if ( SHORT2FROMMP ( mp1 ) == BN_CLICKED ) {
  149.  
  150.                 usButtonID = SHORT1FROMMP ( mp1 ) ;
  151.  
  152.                 switch ( usButtonID & 0xff00 ) {
  153.  
  154.                     case CLKTM_MAJOR :
  155.                         usMajorTickSel = LOBYTE ( usButtonID ) ;
  156.                         break ;
  157.  
  158.                     case CLKTM_MINOR :
  159.                         usMinorTickSel = LOBYTE ( usButtonID ) ;
  160.                         break ;
  161.                 }
  162.             }
  163.  
  164.             /* fall through to the default control processing */
  165.     }
  166.  
  167.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  168. }
  169. /**************************************************************************\
  170. *                                                                          *
  171. *       ROUTINE:    AlarmDlgProc ( )                                    *
  172. *                                                                          *
  173. *       COMMENT:    "Alarm..." dialog                                      *
  174. *                                                                          *
  175. *       RETURNS:    MRESULT, 0 or return value from WinDefDlgProc          *
  176. *                                                                          *
  177. \**************************************************************************/
  178.  
  179. MRESULT EXPENTRY AlarmDlgProc ( HWND hwnd , ULONG usMsg ,
  180.                                    MPARAM mp1 , MPARAM mp2 )
  181. {
  182.  
  183.     switch ( usMsg ) {
  184.  
  185.         case WM_INITDLG :
  186.             hAlarmTime = hwnd; /*put in a global var, so everybody know we already
  187.                                 have an opened dialog box*/
  188.             InitAlarm(hwnd);
  189.  
  190.             break ;
  191.  
  192.         case WM_COMMAND :
  193.  
  194.             switch ( LOUSHORT ( mp1 ) ) {
  195.  
  196.                 case DID_OK :
  197.                     AlarmSet(hwnd);
  198.  
  199.  
  200.                 case DID_CANCEL :
  201.                     hAlarmTime = (HWND)NULL;
  202.                     WinDismissDlg ( hwnd , TRUE ) ;
  203.             }
  204.  
  205.             return NULL ;
  206.  
  207.         case WM_CONTROL :
  208.             break;
  209.  
  210.         case WM_VSCROLL:
  211.             AlarmVScrolls( hwnd,
  212.                            HIUSHORT(mp2),
  213.                            mp1     );
  214.             break;
  215.  
  216.     }
  217.  
  218.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  219. }
  220. /**********************************************************************
  221. * InitAlarm
  222. *
  223. ************************************************************************/
  224. void InitAlarm(HWND hwnd)
  225. {
  226.  
  227.     USHORT usItem;
  228.     MPARAM Message;
  229.  
  230.     WinSendMsg( WinWindowFromID(hwnd,SCROLL_HOURS),SBM_SETSCROLLBAR,
  231.                 MPFROMLONG(2),
  232.                 MPFROM2SHORT(1,3));
  233.     WinSendMsg( WinWindowFromID(hwnd,SCROLL_MINUTES),SBM_SETSCROLLBAR,
  234.                 MPFROMLONG(2),
  235.                 MPFROM2SHORT(1,3));
  236.     WinSendDlgItemMsg( hwnd,
  237.                        IDC_HOURMINUTES,
  238.                        EM_SETTEXTLIMIT,
  239.                        MPFROMLONG(5),
  240.                        MPVOID );
  241.     SetAlarmField(hwnd,cp.alarm.uchHour,cp.alarm.uchMinutes);
  242.     WinSendDlgItemMsg ( hwnd ,IDC_HOURMINUTES, EM_SETSEL , MPFROM2SHORT(0,0),
  243.                         MPVOID  ) ;
  244.     pfnwpEntryField = WinSubclassWindow( WinWindowFromID(hwnd,
  245.                                                         IDC_HOURMINUTES),
  246.                                           EntryFieldSubProc);
  247.     usItem = (USHORT) (cp.alarm.usMode & AM_ACTIVE ?RB_ALARMON:RB_ALARMOFF );
  248.     WinSendDlgItemMsg( hwnd,
  249.                        usItem,
  250.                        BM_SETCHECK,
  251.                        MPFROMLONG(1),
  252.                        MPVOID);
  253.     Message = (cp.alarm.usMode & AM_AUDIO )? MPFROMLONG(1):MPFROMLONG(0);
  254.     WinSendDlgItemMsg( hwnd,
  255.                        IDC_BEEP,
  256.                        BM_SETCHECK,
  257.                        Message,
  258.                        MPVOID);
  259.  
  260.     Message = (cp.alarm.usMode & AM_MSGBOX) ? MPFROMLONG(1):MPFROMLONG(0);
  261.     WinSendDlgItemMsg( hwnd,
  262.                        IDC_MSG,
  263.                        BM_SETCHECK,
  264.                        Message,
  265.                        MPVOID);
  266.  
  267. }
  268. /**************************************************************************
  269. * AlarmSet
  270. ***************************************************************************/
  271. VOID AlarmSet(HWND hwnd)
  272. {
  273.  
  274.  
  275.  
  276.     GetAlarmTime(hwnd,&cp.alarm.uchHour,&cp.alarm.uchMinutes);
  277.     cp.alarm.usMode = (AM_ACTIVE * ((ULONG)WinSendDlgItemMsg( hwnd,
  278.                                                     RB_ALARMON,
  279.                                                     BM_QUERYCHECK,
  280.                                                     MPVOID,
  281.                                                     MPVOID)))
  282.                       |
  283.                       (AM_AUDIO  * ((ULONG)WinSendDlgItemMsg( hwnd,
  284.                                                     IDC_BEEP  ,
  285.                                                     BM_QUERYCHECK,
  286.                                                     MPVOID,
  287.                                                     MPVOID)))
  288.                       |
  289.                       (AM_MSGBOX * ((ULONG)WinSendDlgItemMsg( hwnd,
  290.                                                     IDC_MSG   ,
  291.                                                     BM_QUERYCHECK,
  292.                                                     MPVOID,
  293.                                                     MPVOID ) ) );
  294.           AlarmSetTimer(cp.alarm.uchHour,
  295.                               cp.alarm.uchMinutes);
  296.  
  297. }
  298.  
  299. /****************************************************************\
  300.  *
  301.  *--------------------------------------------------------------
  302.  *
  303.  *  Name:
  304.  *
  305.  *  Purpose:
  306.  *
  307.  *
  308.  *
  309.  *  Usage:
  310.  *
  311.  *  Method:
  312.  *          -
  313.  *
  314.  *          -
  315.  *          -
  316.  *
  317.  *          -
  318.  *          -
  319.  *
  320.  *  Returns:
  321.  *          1 - if sucessful execution completed
  322.  *          0 - if error
  323. \****************************************************************/
  324.  
  325. VOID AlarmSetTimer(UCHAR uchHour,UCHAR uchMinutes )
  326. {
  327.  
  328.  
  329.     DATETIME DateTime;
  330.     time_t  UTCCurrentTime,UTCAlarmTime;
  331.     struct  tm  tmTime;
  332.  
  333.     memset(&DateTime,0,sizeof(DATETIME) );
  334.     memset(&tmTime,0,sizeof(struct tm) );
  335.  
  336.     /*
  337.      *get our current time
  338.      *then use mktime to get the
  339.      *UTC time
  340.      */
  341.      DosGetDateTime(&DateTime);
  342.      tmTime.tm_min   = DateTime.minutes;
  343.      tmTime.tm_hour  = DateTime.hours;
  344.      tmTime.tm_mday  = DateTime.day;
  345.      tmTime.tm_sec   = DateTime.seconds;
  346.      tmTime.tm_mon   = --DateTime.month;
  347.      tmTime.tm_year  = (DateTime.year - 1900);
  348.  
  349.      UTCCurrentTime =  mktime(&tmTime);
  350.  
  351.      /*
  352.       *if the alarm time is less than the current  time
  353.       *then the alarm must be for tomorrow
  354.       */
  355.      if( uchHour < DateTime.hours  ||
  356.                (DateTime.hours == cp.alarm.uchHour
  357.                && uchMinutes < DateTime.minutes ) )
  358.      {
  359.           DateTime.day++;
  360.      }
  361.      /*
  362.       *get the time
  363.       *in UTC format for
  364.       *the timer to expire
  365.       */
  366.      tmTime.tm_min   = uchMinutes;
  367.      tmTime.tm_hour  = uchHour;
  368.      tmTime.tm_mday  = DateTime.day;
  369.      tmTime.tm_sec   = 0;
  370.      tmTime.tm_isdst = 0;
  371.  
  372.      /*
  373.       *set the timer value for the
  374.       *difference between our  current time
  375.       *and the alarm time ( in milliseconds)
  376.       */
  377.      UTCAlarmTime = mktime(&tmTime);
  378.      TimerResources.ulTimerValue  = ( UTCAlarmTime  - UTCCurrentTime)
  379.                                           * 1000L ;
  380.      /*
  381.       *post the timer
  382.       */
  383.       DosPostEventSem(TimerResources.hTimerDev);
  384.  
  385. }
  386.  
  387.  
  388. /**************************************************************************\
  389. *                                                                          *
  390. *       ROUTINE:    ClkColorsDlgProc ( )                                   *
  391. *                                                                          *
  392. *       COMMENT:    "Clock Color Preferences" Dialog                       *
  393. *                                                                          *
  394. *       RETURNS:    MRESULT, 0 or return value from WinDefDlgProc          *
  395. *                                                                          *
  396. \**************************************************************************/
  397. MRESULT EXPENTRY ClkColorsDlgProc ( HWND hwnd , ULONG usMsg ,
  398.                                    MPARAM mp1 , MPARAM mp2 )
  399. {
  400.     USHORT usButtonID;
  401.     static USHORT usCheckedPartID=0, usCheckedColorID=0;
  402.     HWND hwndButton;
  403.     HPS hpsT;
  404.     RECTL rclButton , rclButtonInterior;
  405.     static LONG clrBackgroundNew;
  406.     static LONG clrFaceNew;
  407.     static LONG clrHourHandNew;
  408.     static LONG clrMinuteHandNew;
  409.     static LONG *pclrNew;
  410.     MRESULT rc;
  411.  
  412.     switch (usMsg)
  413.     {
  414.  
  415.         case WM_INITDLG :
  416.             hpsT = WinGetPS(hwnd);
  417.  
  418.             GpiCreateLogColorTable(hpsT, LCOL_RESET, LCOLF_RGB, 0L, 0L,(PLONG)NULL);
  419.  
  420.             /* load the new values from the current ones */
  421.             clrBackgroundNew = GpiQueryColorIndex(hpsT, 0L, cp.clrBackground);
  422.  
  423.             clrFaceNew = GpiQueryColorIndex(hpsT, 0L, cp.clrFace);
  424.             clrHourHandNew = GpiQueryColorIndex(hpsT, 0L, cp.clrHourHand);
  425.             clrMinuteHandNew = GpiQueryColorIndex(hpsT, 0L, cp.clrMinuteHand);
  426.  
  427.             WinReleasePS(hpsT);
  428.  
  429.             /* click the "Background" radio button */
  430.             WinPostMsg ( WinWindowFromID ( hwnd , CLKCLR_BACKGROUND ) ,
  431.                          BM_CLICK , MPFROMSHORT ( TRUE ) , MPVOID) ;
  432.  
  433.             /* let the default dialog procedure handle anything else */
  434.             break;
  435.  
  436.         case WM_COMMAND :
  437.  
  438.             switch ( LOUSHORT ( mp1 ) ) {
  439.                 case DID_OK:
  440.                     hpsT = WinGetPS(hwnd);
  441.  
  442.                     GpiCreateLogColorTable( hpsT,LCOLF_RGB,
  443.                                             0L, 0L, 0L,NULL );
  444.  
  445.                     /*
  446.                      *update the one the user has
  447.                      *selected
  448.                      */
  449.                     switch( usCheckedPartID )
  450.                     {
  451.                     case CLKCLR_BACKGROUND:
  452.                          cp.clrBackground = GpiQueryRGBColor(hpsT, 0L,
  453.                                                 clrBackgroundNew);
  454.                          break;
  455.                     case CLKCLR_FACE:
  456.                          cp.clrFace = GpiQueryRGBColor(hpsT, 0L,
  457.                                              clrFaceNew);
  458.                          break;
  459.                     case CLKCLR_HOURHAND:
  460.                          cp.clrHourHand = GpiQueryRGBColor(hpsT, 0L,
  461.                                              clrHourHandNew);
  462.                          break;
  463.                     case CLKCLR_MINUTEHAND:
  464.                          cp.clrMinuteHand = GpiQueryRGBColor(hpsT, 0L,
  465.                                              clrMinuteHandNew);
  466.                          break;
  467.                     }
  468.                     WinReleasePS(hpsT);
  469.  
  470.                     /* repaint with the new colors */
  471.                     WinInvalidateRect (hwndFrame, NULL, TRUE);
  472.  
  473.                 case DID_CANCEL:
  474.                     WinDismissDlg(hwnd, TRUE);
  475.             }
  476.             return NULL ;
  477.  
  478.         case WM_CONTROL :
  479.  
  480.             usButtonID = SHORT1FROMMP ( mp1 ) ;
  481.  
  482.             /* selecting a new object */
  483.             if ( usButtonID & CLKCLR_OBJECTS ) {
  484.  
  485.                 switch ( usButtonID ) {
  486.                     case CLKCLR_BACKGROUND :
  487.                         pclrNew = &clrBackgroundNew ;
  488.                         break ;
  489.                     case CLKCLR_FACE :
  490.                         pclrNew = &clrFaceNew ;
  491.                         break ;
  492.                     case CLKCLR_HOURHAND :
  493.                         pclrNew = &clrHourHandNew ;
  494.                         break ;
  495.                     case CLKCLR_MINUTEHAND :
  496.                         pclrNew = &clrMinuteHandNew ;
  497.  
  498.                 }
  499.                 usCheckedPartID = usButtonID ;
  500.  
  501.                 /* click the button for the new object's current color */
  502.                 rc=WinSendMsg (WinWindowFromID(hwnd, (CLKCLR_BUTTONSHIFT + *pclrNew)),
  503.                              BM_CLICK , MPFROMSHORT ( TRUE ) , MPVOID) ;
  504.                 break ;
  505.             }
  506.  
  507.             switch ( SHORT2FROMMP ( mp1 ) ) {
  508.  
  509.                 case BN_CLICKED :
  510.  
  511.                     *pclrNew = ( LONG ) usButtonID - CLKCLR_BUTTONSHIFT ;
  512.  
  513.                     /* turn off the check state of the previously checked
  514.                      * button and turn on the check state of the button
  515.                      * just clicked */
  516.  
  517.                     WinCheckButton(hwnd, usCheckedColorID, FALSE);
  518.                     WinCheckButton(hwnd, usButtonID, TRUE);
  519.                     usCheckedColorID = usButtonID;
  520.  
  521.                     break ;
  522.  
  523.                 case BN_PAINT :
  524.  
  525.                     /* fill only the interior of the button, so we don't
  526.                      * conflict with the focus indicator */
  527.  
  528.                     hwndButton = ( ( PUSERBUTTON ) mp2 ) -> hwnd ;
  529.                     WinQueryWindowRect ( hwndButton , &rclButton ) ;
  530.                     rclButton . xLeft ++ ;
  531.                     rclButton . yBottom ++ ;
  532.                     rclButton . xRight -- ;
  533.                     rclButton . yTop -- ;
  534.                     WinFillRect ( ( ( PUSERBUTTON ) mp2 ) -> hps ,
  535.                                   &rclButton ,
  536.                                   ( LONG ) usButtonID - CLKCLR_BUTTONSHIFT ) ;
  537.  
  538.                     /* hollow out those buttons which aren't checked */
  539.                     if (!WinQueryButtonCheckstate(hwnd, usButtonID))
  540.                     {
  541.                         rclButtonInterior . xLeft = rclButton . xLeft + 4 ;
  542.                         rclButtonInterior . yBottom = rclButton . yBottom + 4 ;
  543.                         rclButtonInterior . xRight = rclButton . xRight - 4 ;
  544.                         rclButtonInterior . yTop = rclButton . yTop - 4 ;
  545.                         WinFillRect ( ( ( PUSERBUTTON ) mp2 ) -> hps ,
  546.                                       &rclButtonInterior , SYSCLR_WINDOW ) ;
  547.                     }
  548.  
  549.                     break ;
  550.             }
  551.  
  552.             /* fall through to the default control processing */
  553.     }
  554.  
  555.     return WinDefDlgProc ( hwnd , usMsg , mp1 , mp2 ) ;
  556. }
  557.  
  558.  
  559. /**************************************************************************\
  560. *                                                                          *
  561. *       ROUTINE:    EntryFieldSubProc                                      *
  562. *                                                                          *
  563. *       COMMENT:    "Alarm..." dialog                                      *
  564. * This procedure filter messages for the entry field and make it a time    *
  565. * entry field. It doesn't allow for illigal characters according to the    *
  566. * current selection. It doesn't allow modification of the time seperator.  *
  567. * It works only for hours and minutes. The entry field has to be limited   *
  568. * to 5 characters.                                                         *
  569. *                                                                          *
  570. *                                                                          *
  571. *                                                                          *
  572. *       RETURNS:    MRESULT, 0 or return value from WinDefDlgProc          *
  573. *                                                                          *
  574. \**************************************************************************/
  575.  
  576. MRESULT EXPENTRY EntryFieldSubProc ( HWND hwnd , ULONG usMsg ,
  577.                                    MPARAM mp1 , MPARAM mp2 )
  578. {
  579.     USHORT usSelect,fsKeyFlags,usLast;
  580.     UCHAR usChr1;
  581.     UCHAR uchHourMinutes[6];
  582.     BOOL bValid;
  583.     MRESULT mresult;
  584.     MRESULT mresultSel;
  585.  
  586.     if ((usMsg > WM_MOUSEFIRST) && (usMsg < WM_MOUSELAST)) {
  587.         mresult = pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  588.  
  589.         mresultSel = pfnwpEntryField(hwnd,EM_QUERYSEL,(PLONG)NULL,(PLONG) NULL);
  590.         usSelect = LOUSHORT(mresultSel);
  591.         usLast = HIUSHORT(mresultSel);
  592.         if ((usSelect == 2) )
  593.                pfnwpEntryField ( hwnd , EM_SETSEL , MPFROM2SHORT(3,3) ,
  594.                                 (PVOID)NULL ) ;
  595.         if ((usSelect == 5) )
  596.                pfnwpEntryField ( hwnd , EM_SETSEL , MPFROM2SHORT(4,4) ,
  597.                                     (PVOID)NULL) ;
  598.         return(mresult);
  599.     }
  600.  
  601.     switch ( usMsg ) {
  602.  
  603.     case WM_SETFOCUS:
  604.         pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  605.         if (SHORT1FROMMP(mp2))
  606.             pfnwpEntryField  ( hwnd,
  607.                                EM_SETINSERTMODE,
  608.                                MPFROMSHORT(FALSE),
  609.                                (MPARAM)NULL   );
  610.         return(MPVOID);
  611.     case WM_CHAR:
  612.  
  613.     fsKeyFlags = (USHORT) SHORT1FROMMP(mp1);    /* key flags             */
  614.     if (!(fsKeyFlags & KC_KEYUP)){
  615.         usSelect = (USHORT)WinSendMsg(hwnd,EM_QUERYSEL,MPVOID,MPVOID);
  616.         if (fsKeyFlags & KC_VIRTUALKEY) {
  617.             switch(SHORT2FROMMP(mp2)) {
  618.  
  619.                 case VK_INSERT:
  620.                     return(MPVOID);
  621.                 case VK_UP:
  622.                     break;
  623.                 case VK_DOWN:
  624.                     break;
  625.                 case VK_LEFT:
  626.                     if (usSelect == 3)
  627.                          pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  628.                     return pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  629.                     break;
  630.                 case VK_RIGHT:
  631.                     if (usSelect == 4)
  632.                     {
  633.                          return(MPVOID);
  634.                     }
  635.                     if (usSelect == 1)
  636.                          pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  637.                     return pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  638.                     break;
  639.                 case VK_DELETE:
  640.                 case VK_BACKSPACE:
  641.                     return(MPVOID);
  642.                 case VK_SPACE:
  643.                 switch (usSelect) {
  644.                 case 0:   /*Hours most significant digit*/
  645.                     if (bTwelveHourFormat) {
  646.                           return(pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 )) ;
  647.                     }
  648.  
  649.                 default:
  650.                     return(MPVOID);
  651.                 }
  652.  
  653.                 default:
  654.                     return pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  655.                     break;
  656.             }
  657.         }
  658.         else
  659.         {
  660.             if (fsKeyFlags & KC_CHAR )
  661.             {
  662.                 bValid = FALSE;
  663.                 WinQueryWindowText(hwnd,sizeof(uchHourMinutes),uchHourMinutes);
  664.                 usChr1 = (UCHAR) CHAR1FROMMP(mp2);
  665.                 switch (usSelect) {
  666.                 case 0:   /*Hours most significant digit*/
  667.                     if (bTwelveHourFormat)
  668.                     {
  669.                         if ((usChr1 > '1') || (usChr1 < '0'))
  670.                         {
  671.                               return(MPVOID);
  672.                         }
  673.                         else
  674.                         {
  675.                             pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  676.                             bValid = TRUE;
  677.                         }
  678.                     }
  679.                     else
  680.                     {
  681.                         if ((usChr1 > '2') || (usChr1 < '0'))
  682.                         {
  683.                               return(MPVOID);
  684.                         }
  685.                         else
  686.                         {
  687.                             pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  688.                             bValid = TRUE;
  689.                         }
  690.  
  691.                     }
  692.                     if (bValid)
  693.                     {
  694.                         uchHourMinutes[0] = usChr1;
  695.                         uchHourMinutes[1] = '0';
  696.                         WinSetWindowText(hwnd,uchHourMinutes);
  697.                         pfnwpEntryField ( hwnd , EM_SETSEL , MPFROM2SHORT(1,1) ,
  698.                                             (PLONG)NULL ) ;
  699.                     }
  700.                     return(MPVOID);
  701.                     break;
  702.                 case 1:
  703.                     if (bTwelveHourFormat) {
  704.                         if ((uchHourMinutes[0] == '0') || (uchHourMinutes[0] == ' ') ) {
  705.                             if ((usChr1 > '9') || (usChr1 < '0'))
  706.                             {
  707.                                  return(MPVOID);
  708.                             }
  709.  
  710.                             else
  711.                             {
  712.                                 pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  713.                                 bValid = TRUE;
  714.                             }
  715.                         }
  716.                         else {/*prbably 1*/
  717.                             if ((usChr1 > '2') || (usChr1 < '0') )
  718.                             {
  719.                                 return(MPVOID);
  720.                             }
  721.                             else
  722.                             {
  723.                                 pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  724.                                 bValid = TRUE;
  725.                             }
  726.                         }
  727.                     }
  728.                     else {
  729.                         if (uchHourMinutes[0] < '2') {
  730.                             if ((usChr1 > '9') || (usChr1 < '0'))
  731.                             {
  732.                                    return(MPVOID);
  733.                             }
  734.                             else
  735.                             {
  736.                                 pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  737.                                 bValid = TRUE;
  738.                             }
  739.                         }
  740.                         else
  741.                         {
  742.                             if ((usChr1 > '4') || (usChr1 < '0'))
  743.                             {
  744.                                    return(MPVOID);
  745.                             }
  746.                             else
  747.                             {
  748.                                 pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  749.                                 bValid = TRUE;
  750.                             }
  751.                         }
  752.                     }
  753.                     /*Full the entryfield as if a time seperator is in also*/
  754.                     if (bValid) {
  755.                         mp2 = (MPARAM)(((ULONG)mp2 & 0xffffff00) | szTimeSep[0]);
  756.                         return (pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ));
  757.                     }
  758.                     break;
  759.  
  760.                 case 3:   /*minutes left digit, 0-5*/
  761.                     if ((usChr1 > '5') || (usChr1 < '0'))
  762.                     {
  763.                          return(MPVOID);
  764.                     }
  765.                     else return (pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 )) ;
  766.                     break;
  767.                 case 4:   /*minutes right digit, 0-9*/
  768.                     if ((usChr1 > '9') || (usChr1 < '0'))
  769.                     {
  770.                          return(MPVOID);
  771.                     }
  772.                     else
  773.                     {
  774.                         pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  775.                         return (pfnwpEntryField (hwnd,EM_SETSEL,MPFROM2SHORT(4,4),MPVOID )) ;
  776.                     }
  777.                     break;
  778.  
  779.                 }
  780.             }
  781.         }
  782.     }
  783.  
  784.     default:
  785.         return pfnwpEntryField ( hwnd , usMsg , mp1 , mp2 ) ;
  786.     }
  787. }
  788. /****************************************************************\
  789.  *
  790.  *--------------------------------------------------------------
  791.  *
  792.  *  Name:AlarmScrolls()
  793.  *
  794.  *  Purpose:
  795.  *
  796.  *
  797.  *
  798.  *  Usage:
  799.  *
  800.  *  Method:
  801.  *          -
  802.  *
  803.  *          -
  804.  *          -
  805.  *
  806.  *          -
  807.  *          -
  808.  *
  809.  *  Returns:
  810.  *          1 - if sucessful execution completed
  811.  *          0 - if error
  812. \****************************************************************/
  813. VOID  AlarmVScrolls(HWND hwnd,USHORT ScrollMsg,MPARAM idScroll)
  814. {
  815.   UCHAR uchHours,uchMinutes;
  816.  
  817.     GetAlarmTime(hwnd,&uchHours,&uchMinutes);
  818.  
  819.     switch(ScrollMsg)
  820.     {
  821.     case SB_LINEUP:
  822.     case SB_PAGEUP:
  823.         if (idScroll == (MPARAM)SCROLL_HOURS)
  824.             if (uchHours == 23) uchHours = 0;
  825.             else uchHours++;
  826.         else
  827.             if (uchMinutes == 59) uchMinutes = 0;
  828.             else uchMinutes++;
  829.         break;
  830.  
  831.  
  832.     case SB_LINEDOWN:
  833.     case SB_PAGEDOWN:
  834.         if (idScroll == (MPARAM)SCROLL_HOURS)
  835.             if (uchHours == 0) uchHours = 23;
  836.             else uchHours--;
  837.         else
  838.             if (uchMinutes == 00) uchMinutes = 59;
  839.             else uchMinutes--;
  840.         break;
  841.  
  842.  
  843.     }
  844.     SetAlarmField(hwnd,uchHours,uchMinutes);
  845.     WinSendDlgItemMsg ( hwnd ,
  846.                         IDC_HOURMINUTES,
  847.                         EM_SETSEL ,
  848.                         (idScroll == (MPARAM)SCROLL_HOURS) ?MPFROM2SHORT(0,0):MPFROM2SHORT(3,3),
  849.                          MPVOID ) ;
  850. }
  851.  
  852. /****************************************************************\
  853.  *
  854.  *--------------------------------------------------------------
  855.  *
  856.  *  Name:GetAlarmTime()
  857.  *
  858.  *  Purpose:
  859.  *
  860.  *
  861.  *
  862.  *  Usage:
  863.  *
  864.  *  Method:
  865.  *          -
  866.  *
  867.  *          -
  868.  *          -
  869.  *
  870.  *          -
  871.  *          -
  872.  *
  873.  *  Returns:
  874.  *
  875.  *          VOID
  876. \****************************************************************/
  877. VOID GetAlarmTime(HWND hwnd,UCHAR *npuchHours,UCHAR *npuchMinutes)
  878. {
  879.     UCHAR achHourMinutes[5];
  880.     UCHAR uchHours;
  881.  
  882.     WinQueryDlgItemText(hwnd,IDC_HOURMINUTES,sizeof(achHourMinutes) + 1,achHourMinutes);
  883.     uchHours = (UCHAR)atoi(achHourMinutes);
  884.  
  885.     if (bTwelveHourFormat)
  886.     {
  887.         if (WinSendDlgItemMsg( hwnd,
  888.              RB_PM     ,
  889.              BM_QUERYCHECK,
  890.              MPVOID,
  891.              MPVOID))
  892.         {
  893.              if (uchHours != 12)
  894.                   uchHours += 12;
  895.         }
  896.         else
  897.         {
  898.             if (uchHours == 12) uchHours = 0;
  899.         }
  900.     }
  901.     *npuchHours = uchHours;
  902.     *npuchMinutes = (UCHAR)atoi(&achHourMinutes[3]);
  903.  
  904. }
  905.  
  906.  
  907. /****************************************************************\
  908.  *
  909.  *--------------------------------------------------------------
  910.  *
  911.  *  Name:SetAlarmField
  912.  *
  913.  *  Purpose:
  914.  *
  915.  *
  916.  *
  917.  *  Usage:
  918.  *
  919.  *  Method:
  920.  *          -
  921.  *
  922.  *          -
  923.  *          -
  924.  *
  925.  *          -
  926.  *          -
  927.  *
  928.  *  Returns:
  929.  *          1 - if sucessful execution completed
  930.  *          0 - if error
  931. \****************************************************************/
  932. VOID SetAlarmField(HWND hwnd,UCHAR uchHours,UCHAR uchMinutes)
  933. {
  934.     UCHAR achHourMinutes[5];
  935.  
  936.  
  937.     if (bTwelveHourFormat)
  938.     {
  939.         if (uchHours >= 12)
  940.         {
  941.             uchHours -= 12;
  942.             WinSendDlgItemMsg( hwnd,
  943.                                RB_PM,
  944.                                BM_SETCHECK,
  945.                                MPFROMLONG(1),
  946.                                MPVOID);
  947.             if (uchHours == 0)
  948.                     uchHours = 12;
  949.         }
  950.         else
  951.         {
  952.             if (uchHours == 0) uchHours = 12;
  953.             WinSendDlgItemMsg( hwnd,
  954.                                RB_AM,
  955.                                BM_SETCHECK,
  956.                                MPFROMLONG(1),
  957.                                MPVOID);
  958.         }
  959.  
  960.     }
  961.     else
  962.     {
  963.         WinShowWindow(WinWindowFromID(hwnd,RB_PM),FALSE);
  964.         WinShowWindow(WinWindowFromID(hwnd,RB_AM),FALSE);
  965.     }
  966.     _itoa(uchHours,achHourMinutes,10);
  967.     _itoa(uchMinutes,&achHourMinutes[3],10);
  968.     achHourMinutes[2] = szTimeSep[0];
  969.     if (achHourMinutes[1] == 0)
  970.     {
  971.         achHourMinutes[1] = achHourMinutes[0];
  972.         achHourMinutes[0] = ' ';
  973.     }
  974.     if (achHourMinutes[4] == 0) {
  975.         achHourMinutes[4] = achHourMinutes[3];
  976.         achHourMinutes[3] = '0';
  977.     }
  978.     WinSetDlgItemText(hwnd,IDC_HOURMINUTES,achHourMinutes);
  979. }
  980.  
  981. /****************************************************************\
  982.  *  Dialog procedure for the About dialog box
  983.  *--------------------------------------------------------------
  984.  *
  985.  *  Name:   AboutBoxDlgProc(hwnd, msg, mp1, mp2)
  986.  *
  987.  *  Purpose: Processes all messages sent to the About Box
  988.  *
  989.  *  Usage:  Called for each message sent to the About Box
  990.  *          dialog box.
  991.  *
  992.  *  Method: the about box only has a button control so this
  993.  *          routine only processes WM_COMMAND messages.  Any
  994.  *          WM_COMMAND posted must have come from the Ok
  995.  *          button so we dismiss the dialog upon receiving it.
  996.  *
  997.  *  Returns: Dependent upon message sent
  998.  *
  999. \****************************************************************/
  1000. MRESULT EXPENTRY AboutBoxDlgProc(HWND hwnd, ULONG msg, MPARAM mp1,
  1001.                                      MPARAM mp2 )
  1002. {
  1003.     switch(msg)
  1004.     {
  1005.         case WM_COMMAND:
  1006.             /* no matter what the command, close the dialog */
  1007.             WinDismissDlg(hwnd, TRUE);
  1008.             break;
  1009.  
  1010.         default:
  1011.             return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1012.             break;
  1013.     }
  1014.  
  1015.     return(MPVOID);
  1016.  
  1017. }   /* AboutBoxWndProc() */
  1018.  
  1019.  
  1020. /*--------------------------------------------------------------*\
  1021.  *  End of file :dialogs.c
  1022. \*--------------------------------------------------------------*/
  1023.