这两天使用silverlight编写一个在wince 7.0上运行的photoview小工具,中间遇到许多问题,现在记录下来,方便以后查找。
HWND hWnd;
IXRBitmapImagePtr image_background;
IXRImagePtr image_control;
IXRImagePtr pFull_image;
IXRScaleTransformPtr pImageScale;
IXRRotateTransformPtr pImageRotate;
IXRScrollViewerPtr pScroll;
IXRCanvasPtr pFull;
float fWidth,fheight;
HWND hWndTaskBar = NULL; // The TaskBar
BOOL mode = false;
图片放大/缩小:
HRESULT OnBSClicked(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
{
HRESULT retcode;
BSTR pName;
float fActualX,fActualY;
static float x = 1.0;
static float y = 1.0;
if(Failed(retcode = source->GetName(&pName)))
return retcode;
if(!wcscmp(pName,L"btn_small"))
{
if(x > 0.5)
x -= 0.1;
if(y > 0.5)
y -= 0.1;
}
else
{
x += 0.1;
y += 0.1;
}
//image_control->GetActualX(&fActualX);
//image_control->GetActualY(&fActualY);
//pImageScale->SetCenterX(fActualX + fWidth/2);
//pImageScale->SetCenterY(fActualY + fheight/2);
pImageScale->SetScaleX(x);
pImageScale->SetScaleY(y);
if( 1.0 < x )
{
pScroll->SetVerticalScrollBarVisibility(XRScrollBarVisibility_Visible);
pScroll->SetHorizontalScrollBarVisibility(XRScrollBarVisibility_Visible);
}
else
{
pScroll->SetVerticalScrollBarVisibility(XRScrollBarVisibility_Hidden);
pScroll->SetHorizontalScrollBarVisibility(XRScrollBarVisibility_Hidden);
}
image_control->SetWidth(x * fWidth);
image_control->SetHeight(y * fheight);
image_control->SetRenderTransform(pImageScale);
image_control->SetStretch(XRStretch_UniformToFill);
return S_OK;
}
图片翻转:
HRESULT OnRotateClicked(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
{
HRESULT retcode;
BSTR pName;
static float angle = 0;
//float centerX = fWidth/2;
//float centerY = fheight/2;
float centerX = 0.5;
float centerY = 0.5;
if(Failed(retcode = source->GetName(&pName)))
return retcode;
if(!wcscmp(pName,L"btn_forward"))
{
angle += 90;
}
else
angle -= 90;
pImageRotate->SetAngle(angle);
pImageRotate->SetCenterX(centerX);
pImageRotate->SetCenterY(centerY);
image_control->SetRenderTransform(pImageRotate);
return S_OK;
}
HRESULT OnDelClicked(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
{
if(IDOK == MessageBox(hWnd,L"Are you sure to delete the picture?",L"PhotoView",MB_OKCANCEL))
DeleteFile(ImageArry[i]);
return S_OK;
}
图片全屏:
HRESULT OnPlayClicked(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
{
if (mode)
{
if(hWndTaskBar != NULL)
ShowWindow(hWndTaskBar,SW_SHOW);
pScroll->Setopacity(100);
pScroll->SetVisibility(XRVisibility_Visible);
pFull->SetVisibility(XRVisibility_Collapsed);
::SetwindowPos(hWnd,/*HWND_TOPMOST*/HWND_NOTOPMOST,50,640,480,SWP_NOOWNERZORDER|SWP_SHOWWINDOW);
mode = false;
}
else
{
if (hWndTaskBar != NULL) ShowWindow(hWndTaskBar,SW_HIDE);
int iFullWidth = GetSystemMetrics(SM_CXSCREEN);
int iFullHeight = GetSystemMetrics(SM_CYSCREEN);
pImageScale->SetScaleX(1.0);
pImageScale->SetScaleY(1.0);
pScroll->Setopacity(0);
pScroll->SetVisibility(XRVisibility_Collapsed);
pFull->SetRenderTransform(pImageScale);
pFull->Setopacity(100);
pFull->SetVisibility(XRVisibility_Visible);
::SetwindowPos(hWnd,HWND_TOPMOST/*HWND_NOTOPMOST*/,iFullWidth,iFullHeight,SWP_NOOWNERZORDER|SWP_SHOWWINDOW);
//pScroll->UpdateLayout();
mode = true;
}
return S_OK;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。