Apply to: Windows Embedded CE 6

想要擁有美美的互動式UI? 如何在CE OS上支援Silverlight的開發

請依造以下步驟:

  

Silvelight之前, 請先準備好開發環境:

1. 安裝 Microsoft Visual Studio 2005.

2. 安裝 Windows Embedded CE 6.0.

3. 安裝 Microsoft Visual Studio 2005 Service pack 1.

4. 安裝 Microsoft Visual Studio 2005 Service pack 1 for Vista (Vista System).

5. 安裝 Windows Embedded CE 6.0 Service pack 1.

6. 安裝 Windows Embedded CE 6.0 R2.

7. 安裝 Windows Embedded CE 6.0 R3.

 

Here is the step:

 

  1. Build up a WinCE 6.0 with Silverlight runtime.
  2. Prepare a emulator for Silverlight.

     

    1. Silverlight coding steps.


    •  
      • XAML runtime initial.

           bIsXRInitialized = XamlRuntimeInitialize();

           if (!bIsXRInitialized)

              return FALSE;


    •  
      • Get application instance.

           hResult = GetXRApplicationInstance(&pApplication);

           if(FAILED(hResult))

           {

              RETAILMSG(MSG_FLAG, (TEXT("XAML: GetXRApplicationInstance %x error."), hResult));

              return FALSE;

           }


    •  
      • Add resource.

           hResult = pApplication->AddResourceModule(hInstance);

           if(FAILED(hResult))

           {

              RETAILMSG(MSG_FLAG, (TEXT("XAML: AddResourceModule %x error."), hResult));

              return FALSE;

           }


    •  
      • Set XAML.

           // 直接指定 XAML file 路徑

           // cSourceXaml.SetFile(TEXT("\\Windows\\Page.xaml"));

           // 將 XAML file 加入 resource 後, 可用此方式

           cSourceXaml.SetResource(hInstance, TEXT("XAML"), MAKEINTRESOURCE(IDR_XAML1));


    •  
      • Set Silverlight window.

           XRWindowCreateParams WindowParameters;

           ZeroMemory(&WindowParameters, sizeof(WindowParameters));

           WindowParameters.Style = WS_CAPTION | WS_SYSMENU;

           WindowParameters.pTitle = TEXT("Silverlight Sample UI");

           WindowParameters.Left = 0;

           WindowParameters.Top = 0;


    •  
      • Get visual host.

           hResult = pApplication->CreateHostFromXaml(&cSourceXaml, &WindowParameters, &pVisualHost);

           if(FAILED(hResult))

           {

                RETAILMSG(MSG_FLAG, (TEXT("XAML: CreateHostFromXaml %x error."), hResult));

              return FALSE;

           }


    •  
      • Get root.

           pVisualHost->GetRootElement(&pRootElement);


    •  
      • Get window handle but dialog don't need this.

           pVisualHost->GetContainerHWND(&hwnd);


    •  
      • Add image mouse down handle.

           // I1 是 XAML 圖形元件名稱, 透由 find name 找出其 handle.

           pRootElement->FindName(TEXT("I1"), &pImg);

           pImg->AddMouseLeftButtonDownEventHandler((IXRDelegate<XRMouseButtonEventArgs> *)

           CreateDelegate(this, &MySilverlight::OnMouseLeftButtonDownEventHandler));


    •  
      • Mouse down handle implementation.

           class MySilverlight

           {

              // Mouse enter event handler

              HRESULT OnMouseLeftButtonDownEventHandler(IXRDependencyObject *pSender, 

              XRMouseButtonEventArgs *pArgs)

              {

                 if(!bFocus)

                 {

                    // to do your code

                 }

                 else

                 {

                    // to do your code

                 }

              }

           }


    •  
      • Run Silverlight.

           #if 0

           // Use dialog

           hResult = pVisualHost->StartDialog(NULL);

           if(FAILED(hResult))

           {

              RETAILMSG(MSG_FLAG, (TEXT("XAML: StartDialog %x error."), hResult));

              return FALSE;

           }

           #endif

           // Use window

           pVisualHost->ShowWindow();

           UpdateWindow(hwnd);

           // Start processing

           pApplication->StartProcessing(&exitCode);

     

    More details:

    http://www.microsoft.com/windowsembedded/en-us/evaluate/silverlight-for-windows-embedded-ce-6.aspx

    http://blogs.msdn.com/b/raffael/archive/2010/02/08/silverlight-for-windows-embedded-ce-6-0-first-sample-codes-stress-and-multiple-instances-of-a-control-in-separate-dll.aspx

     

     

 
arrow
arrow
    全站熱搜

    sherwintech 發表在 痞客邦 留言(0) 人氣()