2013年12月1日 星期日

WinCE6.0 Use Silverlight build up UI

1.      Build up WinCE 6.0 with Silverlight runtime.
2.      Prepare a Silverlight project.
Refer attached files, Achieve SilverlightUI 1.
3.      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);
Refer attached files, Achieve Silverlight UI 2.

沒有留言:

張貼留言