示例#1
0
VOID DrawClock (HPS hpsDraw)
{
    RECTL rcl;

    WinQueryWindowRect (hwndClient, &rcl);
    WinFillRect (hpsBuffer, &rcl, cp.clrBackground);

    /* draw the face, the hour hand, and the minute hand */

    ClkDrawRing (hpsDraw);
    ClkDrawFace (hpsDraw);
    ClkDrawDate (hpsDraw, DM_REDRAW);
    ClkDrawHand (hpsDraw, HT_HOUR_SHADE, dt.hours);
    ClkDrawHand (hpsDraw, HT_MINUTE_SHADE, dt.minutes);
    ClkDrawHand (hpsDraw, HT_HOUR, dt.hours);
    ClkDrawHand (hpsDraw, HT_MINUTE, dt.minutes);

    /* draw the tick marks */
    if ((cp.usMajorTickPref == CLKTM_ALWAYS) ||
	    ((cp.usMajorTickPref == CLKTM_NOTICONIC) && ! fIconic))
	ClkDrawTicks (hpsDraw, CLK_MAJORTICKS);

    if ((cp.usMinorTickPref == CLKTM_ALWAYS) ||
	    ((cp.usMinorTickPref == CLKTM_NOTICONIC) && !fIconic))
	ClkDrawTicks (hpsDraw, CLK_MINORTICKS);
}
示例#2
0
/****************************************************************\
 *  Name:ClkTimer()
 *
 *  Purpose: Handles window timer events
 *  Returns:
 *	    1 - if sucessful execution completed
 *	    0 - if error
\****************************************************************/
VOID ClkTimer (HWND hwnd)
{
	/* if we must move the hour and minute hands, redraw it all */
	if (dtNew.minutes != dt.minutes)
	{

	    ClkDrawFace(hpsBuffer);
	    ClkDrawDate(hpsBuffer, DM_REDRAW);
	    ClkDrawHand(hpsBuffer, HT_HOUR_SHADE, dtNew.hours);
	    ClkDrawHand(hpsBuffer, HT_MINUTE_SHADE, dtNew.minutes);
	    ClkDrawHand(hpsBuffer, HT_HOUR, dtNew.hours);
	    ClkDrawHand(hpsBuffer, HT_MINUTE, dtNew.minutes);

	    UpdateScreen (hps, NULL);

	}
}
示例#3
0
VOID ClkPaint (HWND hwnd)
{
    RECTL rclUpdate;
    HPS hpsWnd;

    if (cp.usDispMode & DM_ANALOG)
    {

	WinBeginPaint (hwnd, hps, &rclUpdate);

	GpiCreateLogColorTable (hps, 0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);

	WinFillRect (hps, &rclUpdate, cp.clrBackground);

	if (fBufferDirty)
	{
	    DrawClock (hpsBuffer);
	    fBufferDirty = FALSE;
	}

	UpdateScreen (hps, &rclUpdate);

	/*
	 * Draw the second hand last, so xor will work.
	 */
	if (fShowSecondHand && (cp.usDispMode & DM_SECONDHAND))
	    ClkDrawHand(hps, HT_SECOND, dt.seconds);

	WinEndPaint (hps);

    }
    else
    { /*For now, if it is not Analog, it must be digital*/

	hpsWnd = WinBeginPaint (hwnd, NULLHANDLE, &rclUpdate);

	GpiCreateLogColorTable(hpsWnd, 0L, LCOLF_RGB, 0L, 0L, (PLONG) NULL);

	WinFillRect (hpsWnd, &rclUpdate, cp.clrBackground);

	memset (achOldTime, 0, sizeof(achOldTime));
	memset (achOldAmPm, '0', sizeof(achOldAmPm));
	memset (achOldDate, '0', sizeof(achOldDate));

	DrawDigitalTime (hwnd);

	WinEndPaint (hpsWnd);
    }
}
/****************************************************************\
 *
 *--------------------------------------------------------------
 *
 *  Name:ClkTimer()
 *
 *  Purpose: Handles window timer events
 *
 *
 *
 *  Usage:
 *
 *  Method:
 *          -
 *
 *          -
 *          -
 *
 *          -
 *          -
 *
 *  Returns:
 *          1 - if sucessful execution completed
 *          0 - if error
\****************************************************************/
VOID ClkTimer (HWND hwnd)
{
    DATETIME  dtNew;
    static LONG lTimeChangeCheck = 0L;
    LONG  lTime;
    DosGetDateTime ( &dtNew ) ;

    if (cp.usDispMode & DM_ANALOG)
    {

        /* get the new time */
        DosGetDateTime (&dtNew);

        /* adjust the hour hand */
        dtNew.hours = (dtNew.hours * (UCHAR) 5 ) % (UCHAR) 60
                      + dtNew.minutes / (UCHAR)12;

        /* if we must move the hour and minute hands, redraw it all */
        if (dtNew.minutes != dt.minutes)
        {

            ClkDrawFace(hpsBuffer);
            ClkDrawDate(hpsBuffer, DM_REDRAW);
            ClkDrawHand(hpsBuffer, HT_HOUR_SHADE, dtNew.hours);
            ClkDrawHand(hpsBuffer, HT_MINUTE_SHADE, dtNew.minutes);
            ClkDrawHand(hpsBuffer, HT_HOUR, dtNew.hours);
            ClkDrawHand(hpsBuffer, HT_MINUTE, dtNew.minutes);

            UpdateScreen (hps, NULL);

            if (fShowSecondHand && (cp.usDispMode & DM_SECONDHAND))
            {
                GpiSetMix(hps, FM_INVERT);
                ClkDrawHand(hps, HT_SECOND, dtNew.seconds);
            }
        }

        /* otherwise just undraw the old second hand and draw the new */
        else if (fShowSecondHand  && (cp.usDispMode & DM_SECONDHAND))
        {
            GpiSetMix(hps, FM_INVERT);
            ClkDrawHand(hps, HT_SECOND, dt.seconds);
            ClkDrawHand(hps, HT_SECOND, dtNew.seconds);
        }

        dt = dtNew ;
    }
    else /*Must be Digital*/
    {
        DrawDigitalTime(hwnd);
    }

    /*
     *if this is the first
     *time through init it
     */
    if(!lTimeChangeCheck)
    {
          time(&lTimeChangeCheck);

    }

    /*
     *a quick check to see if
     *any other session
     *adjusted our time
     *if so reset the timer
     */
    else
    {
          time(&lTime);
          /*
           *did the clock get changed by more than 60 seconds
           */
          if( lTime  > ( lTimeChangeCheck  + 60L ) ||
              lTimeChangeCheck > ( lTime   + 60L ) )
          {

               AlarmSetTimer(cp.alarm.uchHour,
                                   cp.alarm.uchMinutes);
          }
          lTimeChangeCheck = lTime;
     }

}
/****************************************************************\
 *
 *--------------------------------------------------------------
 *
 *  Name:ClkCommand()
 *
 *  Purpose:Handle  WM_COMMAND events.
 *
 *
 *
 *  Usage:
 *
 *  Method:
 *          -
 *
 *          -
 *          -
 *
 *          -
 *          -
 *
 *  Returns:
 *          VOID
 *
\****************************************************************/
VOID ClkCommand ( HWND hwnd , MPARAM mp1, MPARAM mp2 )
{
    DATETIME  dtNew ;

    switch ( SHORT1FROMMP ( mp1 ) )
    {

        case IDM_TICKS :
            WinDlgBox ( HWND_DESKTOP , hwndFrame , ClkTicksDlgProc ,
                        NULLHANDLE ,
                        IDD_TICKS , (PVOID )NULL ) ;
            break;

        case IDM_EXIT:
            /*
             *post the event semaphore
             *for our alarm thread
             */
            fEndThread = TRUE;
            DosPostEventSem(TimerResources.hTimerDev);
            WinPostMsg(hwnd, WM_QUIT,MPVOID, MPVOID);


            break;

        case IDM_COLORS :
            WinDlgBox ( HWND_DESKTOP , hwndFrame ,ClkColorsDlgProc ,
                        NULLHANDLE ,
                        IDD_COLORS , NULL ) ;
            SetRGBColors();
            ClkSize(hwnd);
            break ;

        case IDM_TOGGLECONTROLS :
            if (cp.fControlsHidden) {
                ClkShowFrameControls( hwndFrame );
            } else {
                ClkHideFrameControls ( hwndFrame ) ;
            }
            break ;

        case IDM_DATETIME:
            if (hDateTime == NULLHANDLE)
            {
                WinDlgBox(HWND_DESKTOP,hwndFrame,TimeDlgProc,
                          NULLHANDLE,IDD_TIME ,NULL);
                dt.minutes += 2; /*Fool the ClkTimer proc. It will now think it have
                                  to redraw*/
            } else {
                WinSetFocus (HWND_DESKTOP, hDateTime);
            }
            break;
        case IDM_ALARM:
            if (hAlarmTime == (HWND)NULL)
            {
                WinDlgBox(HWND_DESKTOP,hwndFrame,AlarmDlgProc,
                          NULLHANDLE,IDD_ALARM ,NULL);
            }
            else
            {
                WinSetFocus(HWND_DESKTOP,hAlarmTime);
            }

            break;

        case IDM_SECONDHAND:
            cp.usDispMode = ((cp.usDispMode & DM_SECONDHAND) ?
                    (cp.usDispMode & (~DM_SECONDHAND)) : (cp.usDispMode | DM_SECONDHAND));

            GpiSetMix(hps, FM_INVERT);

            /*
             * Depending on the current mode draw or remove the second hand.
             */
            if (cp.usDispMode & DM_SECONDHAND) {
                DosGetDateTime(&dtNew);
                ClkDrawHand(hps, HT_SECOND, dtNew.seconds);
                dt.seconds = dtNew.seconds;
            } else {
                ClkDrawHand(hps, HT_SECOND, dt.seconds);
            }

            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_SECONDHAND, TRUE),
                        MPFROM2SHORT( MIA_CHECKED,
                                      ( (cp.usDispMode & DM_SECONDHAND)?  MIA_CHECKED
                                              : ~MIA_CHECKED) ) );
            break;

        case IDM_TIME:
            cp.usDispMode = ((cp.usDispMode & DM_TIME) ? (cp.usDispMode & (~DM_TIME))
                                                      : (cp.usDispMode | DM_TIME));

            WinSendMsg(hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDM_TIME, TRUE),
                    MPFROM2SHORT(MIA_CHECKED, ((cp.usDispMode & DM_TIME) ?
                    MIA_CHECKED : ~MIA_CHECKED)));

            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_DATE, TRUE),
                        MPFROM2SHORT( MIA_DISABLED,
                                      ( (!(cp.usDispMode & DM_TIME)) ? MIA_DISABLED
                                              : ~MIA_DISABLED) ) );
            ClkSize(hwnd);
            WinInvalidateRect(hwnd, NULL, TRUE);
            break;

        case IDM_DATE:
            cp.usDispMode = ((cp.usDispMode & DM_DATE) ? (cp.usDispMode & (~DM_DATE))
                                                      : (cp.usDispMode | DM_DATE));
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_DATE, TRUE),
                        MPFROM2SHORT( MIA_CHECKED,
                                      ( (cp.usDispMode & DM_DATE)?  MIA_CHECKED
                                              : ~MIA_CHECKED) ) );
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_TIME, TRUE),
                        MPFROM2SHORT( MIA_DISABLED,
                                      ( ((!(cp.usDispMode & DM_DATE)) || (cp.usDispMode & DM_ANALOG))?  MIA_DISABLED
                                              : ~MIA_DISABLED) ) );
            ClkSize(hwnd);
            WinInvalidateRect(hwnd,(PRECTL)NULL,TRUE);

            break;
        case IDM_DIGITAL:
            cp.usDispMode |=  DM_DIGITAL;
            cp.usDispMode &=  (~DM_ANALOG);
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_DIGITAL, TRUE),
                        MPFROM2SHORT( MIA_CHECKED,
                                      MIA_CHECKED));
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_ANALOG , TRUE),
                        MPFROM2SHORT( MIA_CHECKED,
                                     ~MIA_CHECKED));
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_SECONDHAND, TRUE),
                        MPFROM2SHORT( MIA_DISABLED,
                                        MIA_DISABLED));
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_TICKS, TRUE),
                        MPFROM2SHORT( MIA_DISABLED,
                                        MIA_DISABLED));
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_TIME, TRUE),
                        MPFROM2SHORT( MIA_DISABLED,
                                      ( ((!(cp.usDispMode & DM_DATE)) || (cp.usDispMode & DM_ANALOG))?  MIA_DISABLED
                                              : ~MIA_DISABLED) ) );
            WinInvalidateRect(hwnd,(PRECTL)NULL,TRUE);
            break;
        case IDM_ANALOG :
            cp.usDispMode |=  DM_ANALOG;
            cp.usDispMode &=  (~DM_DIGITAL);
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_ANALOG, TRUE),
                        MPFROM2SHORT( MIA_CHECKED,
                                      MIA_CHECKED));
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_DIGITAL, TRUE),
                        MPFROM2SHORT( MIA_CHECKED,
                                     ~MIA_CHECKED));
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_TIME, TRUE),
                        MPFROM2SHORT( MIA_DISABLED,
                                        MIA_DISABLED));
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_DATE, TRUE),
                        MPFROM2SHORT( MIA_DISABLED,
                                        ~MIA_DISABLED));

            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_SECONDHAND, TRUE),
                        MPFROM2SHORT( MIA_DISABLED,
                                        ~MIA_DISABLED));
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_TICKS, TRUE),
                        MPFROM2SHORT( MIA_DISABLED,
                                        ~MIA_DISABLED));

            cp.usDispMode |= DM_TIME;
            WinSendMsg( hwndMenu,
                        MM_SETITEMATTR,
                        MPFROM2SHORT( IDM_TIME, TRUE),
                        MPFROM2SHORT( MIA_CHECKED,
                                      MIA_CHECKED));
            WinInvalidateRect(hwnd,(PRECTL)NULL,TRUE);
            break;


        case IDM_HELPHELPFORHELP:
            HelpHelpForHelp(mp2);
            break;

        case IDM_HELPEXTENDED:
            HelpExtended(mp2);
            break;

        case IDM_HELPKEYS:
            HelpKeys(mp2);
            break;

        case IDM_HELPINDEX:
            HelpIndex(mp2);
            break;

        case IDM_HELPTUTORIAL:
            HelpTutorial(mp2);
            break;

        case IDM_HELPABOUT:
            HelpAbout(mp2);
            break;

     case IDM_ALARM_EXPIRED:
           WinMessageBox(HWND_DESKTOP,
                         hwndFrame,
                         (PSZ)"Alarm Expired",
                         (PSZ)"The Bells Are Ringing",
                         0,
                         MB_OK);
            break;
    }
}