Silverlight for Windows Embedded Clock Sample

Windows Embedded Compact 7 developers can download, build, and run the Silverlight for Windows Embedded clock code sample that is based on Silverlight for Windows Embedded.By evaluating the sample code, you can learn how to write your own code for a Silverlight for Windows Embe

C++ (2.2 MB)
 
 
 
 
 
(0)
2,955 times
Add to favorites
9/15/2011
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C++
��#include "stdafx.h"

#include "SWEClockGenerated.h"

#include "MainPage.h"

#include "App.h"

#include "resource.h"



// ============================================================================

//  OnLoaded

//

//  Description: Calls InitializeComponent to bind member variables to named

//               elements, and attach event handlers specified in XAML

//

//  Parameters:  pRoot - The root dependency object.

// ============================================================================

HRESULT MainPage::OnLoaded(__in IXRDependencyObject* pRoot)

{

    UNREFERENCED_PARAMETER(pRoot);



    HRESULT hr = InitializeComponent();



    // Add calls to FindName or Add___EventHandler() methods after this comment.



    if (m_pLayoutRoot)

    {

        m_pLayoutRoot->AddLoadedEventHandler(CreateDelegate(this, &MainPage::Canvas_Loaded));

    }

    

    return hr;

} // OnLoaded



// ============================================================================

//  Canvas_Loaded

// 

//  Description: Event handler implementation

//

//  Parameters:  pSender - The dependency object that raised the click event.

//               pArgs - Event specific arguments.

// ============================================================================

HRESULT MainPage::Canvas_Loaded (IXRDependencyObject* pSender, XRRoutedEventArgs* pArgs)

{

    HRESULT hr = E_FAIL;

    IXRDoubleAnimationPtr pHourAnimation;

    IXRDoubleAnimationPtr pMinuteAnimation;

    IXRDoubleAnimationPtr pSecondAnimation;

    IXRStoryboardPtr pClockStoryboard;

    IXRFrameworkElementPtr pRoot;



    // First find all animations and Storyboard from the root element.

    pRoot = pSender; //QI the dependency object for the FrameworkElement



    FindName(L"hourAnimation", &pHourAnimation);

    FindName(L"minuteAnimation", &pMinuteAnimation);

    FindName(L"secondAnimation", &pSecondAnimation);

    FindName(L"clockStoryboard", &pClockStoryboard);



    if (pRoot &&

        pHourAnimation &&

        pMinuteAnimation &&

        pSecondAnimation &&

        pClockStoryboard)

    {

        // The current date and time.

        SYSTEMTIME stCurrent;

        GetLocalTime(&stCurrent);



        // Find the appropriate angle (in degrees) for the hour hand

        // based on the current time.

        float hourangle = (((float)stCurrent.wHour) / 12) * 360 + stCurrent.wMinute / 2;



        // The transform is already rotated 116.5 degrees to make the hour hand be

        // in the 12 o'clock position. You must build this already existing angle

        // into the hourangle.

        hourangle += 180;



        // The same as for the hour angle.

        float minangle = (((float)stCurrent.wMinute) / 60) * 360;

        minangle += 180;



        // The same as for the hour angle.

        float secangle = (((float)stCurrent.wSecond) / 60) * 360;

        secangle += 180;



        // Set the beginning of the animation (From property) to the angle

        // corresponging to the current time.

        pHourAnimation->SetFrom(hourangle);



        // Set the end of the animation (To property)to the angle

        // corresponding to the current time PLUS 360 degrees. Thus, the

        // animation will end after the clock hand moves around the clock

        // once. Note: The RepeatBehavior property of the animation is set

        // to "Forever" so the animation will begin again as soon as it completes.

        pHourAnimation->SetTo(hourangle + 360);



        // Same as with the hour animation.

        pMinuteAnimation->SetFrom(minangle);

        pMinuteAnimation->SetTo(minangle + 360);



        // Same as with the hour animation.

        pSecondAnimation->SetFrom(secangle);

        pSecondAnimation->SetTo(secangle + 360);



        // Start the storyboard.

        if (SUCCEEDED(pClockStoryboard->Begin()))

            hr = S_OK;

    }



    return hr;

}





#pragma region GeneratedCode

// ============================================================================

//  WARNING: DO NOT EDIT THIS ALWAYS-GENERATED CODE

// ============================================================================

HRESULT MainPage::InitializeComponent()

{

    HRESULT hr = E_FAIL;



    FindName(L"LayoutRoot", &m_pLayoutRoot);

    FindName(L"outerCircle", &m_pouterCircle);

    FindName(L"MinutedHand", &m_pMinutedHand);

    FindName(L"HourHand", &m_pHourHand);

    FindName(L"SecondHand", &m_pSecondHand);



    if (m_pLayoutRoot &&

        m_pouterCircle &&

        m_pMinutedHand &&

        m_pHourHand &&

        m_pSecondHand

       )

    {

        hr = S_OK;

    }



    return hr;

}

// ============================================================================

//  WARNING: DO NOT EDIT THIS ALWAYS-GENERATED CODE

// ============================================================================

#pragma endregion GeneratedCode