WINCE6.0下用SilverLight技术实现的图片浏览器(支持手势 *** 作,在模拟器下可以运行)

WINCE6.0下用SilverLight技术实现的图片浏览器(支持手势 *** 作,在模拟器下可以运行),第1张

概述支持滚动的左右手势进行图片切换,支持滚动的上下手势进行图片的放大与缩小。 (在模拟器里面上与下正好反了,左与右正好反了,动画的效果还有点问题估计在实际的硬件环境下不会有问题)   //############################################################################################################

支持滚动的左右手势进行图片切换,支持滚动的上下手势进行图片的放大与缩小。
(在模拟器里面上与下正好反了,左与右正好反了,动画的效果还有点问题估计在实际的硬件环境下不会有问题)

 


//###############################################################################################################
//Main.cpp
//Designed by xqh
//Date:2009--12--29


//#include <pwinuser.h>
#include <XamlRuntime.h>
#include <XRDelegate.h>
#include <XRPtr.h>
#include <Ehm.h>


//=================================================================================================================
IXRApplication* pApplication = NulL;
IXRVisualHost* pVisualHost = NulL;

IXRImagePtr  CenterImage;
IXRImagePtr  Leftimage;
IXRImagePtr  Rightimage;
LPCTSTR   strfilePath[8];


class BtnEventHandler //单独响应按钮 *** 作
{

protected:
   
 IXRStoryboardPtr     sboard;


public:

   BtnEventHandler(IXRStoryboardPtr& storyboard)
 {      
      sboard=storyboard;
 }

    HRESulT Btn_OnClick(IXRDependencyObject* source,XRMouse@R_404_5554@EventArgs* args)   
 {     

#if  1

  //MessageBox(NulL,TEXT("Btn_OnClick!"),TEXT("Silverlight for windows Embedded test"),MB_OK);  


        RETAILMSG(1,(TEXT("++++BtnEventHandler::Btn_OnClick( )----/r/n")));

#else

      UINT  exitCode=0;

     // pApplication->StopProcessing(exitCode);

      pVisualHost->EndDialog(0);

#endif

     return S_OK;   
 }

//====================================================================================================
    HRESulT Image_Mouseleft@R_404_5554@Down(IXRDependencyObject* source,XRMouse@R_404_5554@EventArgs* args)   
 {     

     static  int  ImageIndex=0;

//先弄一个动画效果

       HRESulT        hr;       
    XRClockState ckstate;

//MessageBox(NulL,TEXT("Image_Mouseleft@R_404_5554@Down!"),MB_OK);  

 RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Mouseleft@R_404_5554@Down( )----/r/n")));


        if (Failed(hr=sboard->GetCurrentState(&ckstate)))           
   return hr;

        if (ckstate==XRClockState_Stopped)       
  {    
      if (Failed(hr=sboard->Begin()))               
       return hr;       
  }       
  else       
  {           
      if (Failed(hr=sboard->Stop()))               
       return hr;       
  }


      if(ImageIndex>6)
    ImageIndex=0;
   else
    ImageIndex++;


  

       IXRBitmAPImagePtr    BitmAPImage;

//------------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);


BitmAPImage->SetUriSource(strfilePath[ImageIndex]);


if(Leftimage==NulL)
RETAILMSG(1,(TEXT("++++the Leftimage is NulL!/r/n")));


Leftimage->SetSource(BitmAPImage);  //这个地方设置不成功!!!
//--------------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);

if(ImageIndex>6)
BitmAPImage->SetUriSource(strfilePath[7-ImageIndex]);

else
BitmAPImage->SetUriSource(strfilePath[ImageIndex+1]);

CenterImage->SetSource(BitmAPImage);


//----------------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);

if(ImageIndex>5)
BitmAPImage->SetUriSource(strfilePath[ImageIndex-6]);

else
BitmAPImage->SetUriSource(strfilePath[ImageIndex+2]);


Rightimage->SetSource(BitmAPImage);


     return S_OK;   
 }


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

 HRESulT Image_Gesture(IXRDependencyObject* source,XRGestureEventArgs* args)   
 { 
   DWORD  DWID;

   GESTUREINFO   GestureInfo;

   static   int  iCurImage=0;

   static   float  fScaleX=1.0,fScaleY=1.0; //设置放大/缩小的倍数
   float   fActualX,fActualY;
   float   fWIDth,fheight;


   IXRBitmAPImagePtr    BitmAPImage;
   HRESulT        hr;       
   XRClockState ckstate;

   IXRScaletransform*  pRendertransform;

   GestureInfo=args->GestureInfo;

   DWID=GestureInfo.DWID;

  
   RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----/r/n")));


   switch(DWID)
   {

   case  GID_BEGIN:  //手势开始

RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_BEGIN!/r/n")));
 
    break;

   case  GID_END:  //手势结束

RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_END!/r/n")));
    break;


   case  GID_PAN:  //滑动----速度慢一点
RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_PAN!/r/n")));
    break;

   case  GID_ROTATE:  //旋转----保留没有使用
RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_ROTATE!/r/n")));
    break;


   case  GID_SCRolL://滚动---速度要求比PAN快

RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_SCRolL!/r/n")));


            switch( GID_SCRolL_DIRECTION(GestureInfo.ullArguments) ) //判断滚动的方向
   {
       case  ARG_SCRolL_NONE:
RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_SCRolL--case  ARG_SCRolL_NONE!/r/n")));
    break;

               case  ARG_SCRolL_UP:
RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_SCRolL--case  ARG_SCRolL_UP!/r/n")));

//进行图片缩小的处理
if(fScaleX>0.5)
fScaleX-=0.1;

if(fScaleY>0.5)
fScaleY-=0.1;


pApplication->CreateObject(IID_IXRScaletransform,&pRendertransform);


CenterImage->GetActualX(&fActualX);  //获取对应的坐标值
CenterImage->GetActualY(&fActualY);

CenterImage->GetWIDth(&fWIDth); //获取控件的大小
CenterImage->GetHeight(&fheight); 

pRendertransform->SetCenterX(fActualX+fWIDth/2);
pRendertransform->SetCenterY(fActualY+fheight/2);

pRendertransform->SetScaleX(fScaleX);
pRendertransform->SetScaleY(fScaleY);

CenterImage->SetRendertransform(pRendertransform );


    break;


                case  ARG_SCRolL_DOWN:
RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_SCRolL--case  ARG_SCRolL_DOWN!/r/n")));


//进行图片放大的处理

if(fScaleX<2.0)
fScaleX+=0.1;

if(fScaleY<2.0)
fScaleY+=0.1;

 

pApplication->CreateObject(IID_IXRScaletransform,&pRendertransform);


CenterImage->GetActualX(&fActualX);  //获取对应的坐标值
CenterImage->GetActualY(&fActualY);

CenterImage->GetWIDth(&fWIDth); //获取控件的大小
CenterImage->GetHeight(&fheight); 

pRendertransform->SetCenterX(fActualX+fWIDth/2);
pRendertransform->SetCenterY(fActualY+fheight/2);

pRendertransform->SetScaleX(fScaleX);
pRendertransform->SetScaleY(fScaleY);

CenterImage->SetRendertransform(pRendertransform );


    break;

                 case  ARG_SCRolL_left:
RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_SCRolL--case  ARG_SCRolL_left!/r/n")));

//先弄一个动画效果
/*
        if (Failed(hr=sboard->GetCurrentState(&ckstate)))  //为什么会是XRClockState_Filling状态?         
   return hr;

        if (ckstate==XRClockState_Stopped)       
  {    
      if (Failed(hr=sboard->Begin()))  //1S钟就结束             
       return hr;       
  }       
  else       
  {           
      if (Failed(hr=sboard->Stop()))               
       return hr;       
  }
*/

if(iCurImage>6)
    iCurImage=0;
else
    iCurImage++;


 

//------------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);

BitmAPImage->SetUriSource(strfilePath[iCurImage]);

Leftimage->SetSource(BitmAPImage); 
//--------------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);

if(iCurImage>6)
   BitmAPImage->SetUriSource(strfilePath[7-iCurImage]);
else
   BitmAPImage->SetUriSource(strfilePath[iCurImage+1]);

CenterImage->SetSource(BitmAPImage);


//----------------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);

if(iCurImage>5)
   BitmAPImage->SetUriSource(strfilePath[iCurImage-6]);
else
  BitmAPImage->SetUriSource(strfilePath[iCurImage+2]);

Rightimage->SetSource(BitmAPImage);


    break;

 

               case  ARG_SCRolL_RIGHT:
RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_SCRolL--case  ARG_SCRolL_RIGHT!/r/n")));


//先弄一个动画效果
/*
        if (Failed(hr=sboard->GetCurrentState(&ckstate)))           
   return hr;

        if (ckstate==XRClockState_Stopped)       
  {    
      if (Failed(hr=sboard->Begin()))               
       return hr;       
  }       
  else       
  {           
      if (Failed(hr=sboard->Stop()))               
       return hr;       
  }
*/


if(iCurImage==0)
    iCurImage=7;
else
    iCurImage--;


 IXRBitmAPImagePtr    BitmAPImage;

//------------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);

if(iCurImage>5)
   BitmAPImage->SetUriSource(strfilePath[iCurImage-6]);
else
  BitmAPImage->SetUriSource(strfilePath[iCurImage+2]);

Rightimage->SetSource(BitmAPImage);


    break;

   }
//---------------------------------------
/*
            switch( GID_SCRolL_VELociTY(GestureInfo.ullArguments) ) //判断滚动的速度
   {


      default:
    break;
             }

//---------------------------------------
            switch( GID_SCRolL_ANGLE(GestureInfo.ullArguments) ) //判断滚动的角度
   {

                default:
    break;
             }
*/

 

    break;


   case  GID_HolD://保持

RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_HolD!/r/n")));
    break;


   case  GID_SELECT://单击选择
RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_SELECT!/r/n")));
    break;

   case  GID_DOUBLESELECT://双击选择----要求两次单击的时间间隔不要太长

RETAILMSG(1,(TEXT("++++BtnEventHandler::Image_Gesture( )----case  GID_DOUBLESELECT!/r/n")));
    break;


   }

 

      return S_OK;   
    }

 


};

voID InitPicturePathStr(voID)
{


strfilePath[0]=L"//Storage Card//XAMLPERF//Bmps//1.png";
strfilePath[1]=L"//Storage Card//XAMLPERF//Bmps//2.png";
strfilePath[2]=L"//Storage Card//XAMLPERF//Bmps//3.png";
strfilePath[3]=L"//Storage Card//XAMLPERF//Bmps//4.png";
strfilePath[4]=L"//Storage Card//XAMLPERF//Bmps//5.png";
strfilePath[5]=L"//Storage Card//XAMLPERF//Bmps//6.png";
strfilePath[6]=L"//Storage Card//XAMLPERF//Bmps//7.png";
strfilePath[7]=L"//Storage Card//XAMLPERF//Bmps//8.png";

}
//==========================================================================================================
INT WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPWSTR lpCmdline,
    int nCmdshow
    )
{
   int    exitCode = -1;
   BOol   bRet;
   HRESulT hr;
  
   bRet= XamlRuntimeInitialize();

   GetXRApplicationInstance(&pApplication);

   XRXamlSource SourceXaml;

   SourceXaml.Setfile(L"//Storage Card//XAMLPERF//Page_Picturebrowser.xaml");


//###############################################################

XRWindowCreateParams WindowParameters;
ZeroMemory(&WindowParameters,sizeof(WindowParameters));
WindowParameters.Style       = WS_POPUP;
WindowParameters.pTitle      = L"Title name";
WindowParameters.left        = 0;
WindowParameters.top         = 0;

//################################################################

//IXRVisualHost* pVisualHost = NulL;


pApplication->CreateHostFromXaml(&SourceXaml,&WindowParameters,&pVisualHost);


if(!pVisualHost)
 RETAILMSG(1,(TEXT("++++the pVisualHost is NulL!/r/n")));

//################################################################

//找到根目录
IXRFrameworkElementPtr root;
if (Failed(hr=pVisualHost->GetRootElement(&root)))      
return -1;


//################################################################


InitPicturePathStr( );

if (Failed(hr=root->Findname(TEXT("Leftimage"),&Leftimage)))       
return -1;

if (Failed(hr=root->Findname(TEXT("CenterImage"),&CenterImage)))       
return -1;
 

if (Failed(hr=root->Findname(TEXT("Rightimage"),&Rightimage)))       
return -1;

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


IXRStoryboardPtr sboard;

    if (Failed(hr=root->Findname(TEXT("CenterImageStoryboard"),&sboard)))       
  
  return -1;


//BtnEventHandler handlerImage;

BtnEventHandler handlerImage(sboard);


/*

//注册鼠标左键单击事件
IXRDelegate<XRMouse@R_404_5554@EventArgs>* clickdelegateImage;

if (Failed(hr=CreateDelegate(&handlerImage,&BtnEventHandler::Image_Mouseleft@R_404_5554@Down,&clickdelegateImage)))       
  return -1;


if (Failed(hr=CenterImage->AddMouseleft@R_404_5554@DownEventHandler(clickdelegateImage)))  //注册交互事件     
  return -1;
*/


//注册触摸屏手势事件
IXRDelegate<XRGestureEventArgs>* gesturedelegateImage;

if (Failed(hr=CreateDelegate(&handlerImage,&BtnEventHandler::Image_Gesture,&gesturedelegateImage)))       
  return -1;


if (Failed(hr=CenterImage->AddGestureEventHandler(gesturedelegateImage)))  //注册交互事件     
  return -1;

 

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

IXRBitmAPImagePtr    BitmAPImage;

//-------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);


BitmAPImage->SetUriSource(strfilePath[0]);


Leftimage->SetSource(BitmAPImage);
//--------------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);


BitmAPImage->SetUriSource(strfilePath[1]);

CenterImage->SetSource(BitmAPImage);

//----------------------------------------------------------------------

pApplication->CreateObject(IID_IXRBitmAPImage,&BitmAPImage);


BitmAPImage->SetUriSource(strfilePath[2]);


Rightimage->SetSource(BitmAPImage);


//###############################################################

pVisualHost->StartDialog(NulL);//显示对话框


UINT StartProcessCode = 0;


pApplication->StartProcessing(&StartProcessCode);

//##################################################################

//clickdelegateImage->Release();
gesturedelegateImage->Release();

   return exitCode;


}

 

//======================================================================================
//相关Page_Picturebrowser.xaml的内容

 

<UserControl
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="SilverlightApplication_Picturebrowser.Page"
 WIDth="640" Height="480" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
 <UserControl.Resources>
  <Storyboard x:name="CenterImageStoryboard">
   <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.Targetname="CenterImage" Storyboard.TargetProperty="(UIElement.Rendertransform).(transformGroup.Children)[2].(Rotatetransform.Angle)">
    <SplineDoubleKeyFrame KeyTime="00:00:01" Value="360"/>
   </DoubleAnimationUsingKeyFrames>
  </Storyboard>
 </UserControl.Resources>

 <GrID x:name="LayoutRoot" Background="White">
  <Image HorizontalAlignment="Right" margin="0,96,215.717,232" WIDth="240.33" Source="border.png" Stretch="Fill" d:LayoutOverrIDes="HorizontalAlignment,WIDth"/>
  <Image HorizontalAlignment="left" margin="3.135,142.319,238.318" WIDth="156.865" Source="border.png" Stretch="Fill" d:LayoutOverrIDes="WIDth"/>
  <Image Height="96" HorizontalAlignment="Right" margin="0,143.871,15.777,0" VerticalAlignment="top" WIDth="152" Source="border.png" Stretch="Fill"/>
  <Image Height="65.799" HorizontalAlignment="Right" margin="0,151.099,24,0" VerticalAlignment="top" WIDth="136" Source="3.png" Stretch="Fill" d:LayoutOverrIDes="Height" x:name="Rightimage"/>
  <Image Height="103.556" margin="202.415,104,224,0" VerticalAlignment="top" Source="1.png" Stretch="Fill" d:LayoutOverrIDes="Height" x:name="CenterImage" RendertransformOrigin="0.5,0.5">
   <Image.Rendertransform>
    <transformGroup>
     <Scaletransform/>
     <Skewtransform/>
     <Rotatetransform/>
     <Translatetransform/>
    </transformGroup>
   </Image.Rendertransform>
  </Image>
  <Image Height="67.307" HorizontalAlignment="left" margin="14,148.736,0" VerticalAlignment="top" WIDth="138.354" Source="2.png" Stretch="Fill" d:LayoutOverrIDes="WIDth,Height" x:name="Leftimage"/>
 </GrID>
</UserControl>

 

//==================================================================================
//相关参考文章
http://www.cnblogs.com/Terrylee/archive/2008/03/21/Silverlight2-step-by-step-part32.html

总结

以上是内存溢出为你收集整理的WINCE6.0下用SilverLight技术实现的图片浏览器(支持手势 *** 作,在模拟器下可以运行)全部内容,希望文章能够帮你解决WINCE6.0下用SilverLight技术实现的图片浏览器(支持手势 *** 作,在模拟器下可以运行)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1039481.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存