WinCE使用DirectDraw实现页面下掉的特效

#include <ddraw.h>
#pragma comment(lib, "ddraw.lib")

//画一个要掉下来的动态页面之前把loop设为TRUE

BOOL loop = TRUE;

static LPDIRECTDRAW lpDD = NULL;
static LPDIRECTDRAWCLIPPER lpClipper = NULL;
static LPDIRECTDRAWSURFACE lpBmpSurface = NULL;
static LPDIRECTDRAWSURFACE lpPrimarySurface = NULL;

//初始化Direct Draw

void CBluetoothDlg::InitializeDirectDraw()
{
   HRESULT            hRes;
   DDSURFACEDESC    ddDesc;

   if ( lpDD != NULL )
       return;

   hRes = DirectDrawCreate( NULL, &lpDD, NULL );
   if ( hRes != DD_OK )
       return;

   hRes = lpDD->SetCooperativeLevel(NULL, DDSCL_NORMAL);
   if ( hRes != DD_OK )
       return;

   hRes = lpDD->CreateClipper(0, &lpClipper, NULL);
   if ( hRes != DD_OK )
       return;

   ZeroMemory(&ddDesc, sizeof(ddDesc));
   ddDesc.dwSize = sizeof(ddDesc);
   ddDesc.dwFlags = DDSD_CAPS;
   ddDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
   hRes = lpDD->CreateSurface(&ddDesc, &lpPrimarySurface, NULL);
   if ( hRes != DD_OK )
       return;

   lpPrimarySurface->SetClipper(lpClipper);

   lpClipper->SetHWnd(0, m_hWnd);
}

//加载页面(页面图像改变时调用)

BOOL CBluetoothDlg::LoadPicture()
{
 BOOL bRet = FALSE;
 HDC hdc = NULL;
 DDSURFACEDESC ddsDesc;
 
 if ( lpDD == NULL )
  return bRet;
 
 if ( lpBmpSurface != NULL )
 {
  lpBmpSurface->Release();
  lpBmpSurface = NULL;
 }

 ZeroMemory(&ddsDesc, sizeof(ddsDesc));
 ddsDesc.dwSize = sizeof(DDSURFACEDESC);
 ddsDesc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
 ddsDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
 ddsDesc.dwWidth = 480;
 ddsDesc.dwHeight = 272;

 if ( lpDD->CreateSurface(&ddsDesc, &lpBmpSurface, NULL) != DD_OK )
 {
  return bRet;
 }

 lpBmpSurface->GetDC(&hdc);
 if(Page[CPage::stackPage.GetTop()].Draw(hdc))
  bRet = TRUE;
 
 lpBmpSurface->ReleaseDC(hdc);
 return bRet;
}

//显示页面

void CBluetoothDlg::ShowPicture()
{
   if ( lpPrimarySurface == NULL )
       return;
   if ( lpBmpSurface == NULL )
       return;

   // if there is a screensaver, when resume from it, 
   // the surface will lost, then the program should restore the surface
   if ( lpBmpSurface->IsLost() == DDERR_SURFACELOST )
   {
       if ( lpBmpSurface->Restore() != DD_OK )
           return;
   }

   if ( lpPrimarySurface->IsLost() == DDERR_SURFACELOST )
   {
       if ( lpPrimarySurface->Restore() != DD_OK )
           return;
   }
   if(loop)
   {
    RECT rect = {0,0,480,0};
    RECT rect2 = {0,272,480,272};
    for(int i=0;i<68;i++)
    {
     rect.bottom+=4;
     rect2.top-=4;
   lpPrimarySurface->Blt(&rect, lpBmpSurface, &rect2, DDBLT_WAIT, NULL);
    }
    loop = FALSE;
   }
   else
   {
    lpPrimarySurface->Blt(NULL, lpBmpSurface, NULL, DDBLT_WAIT, NULL);
   }
}

//释放

void CBluetoothDlg::InvalidateDirectDraw()
{
   if ( lpPrimarySurface != NULL )
   {
       lpPrimarySurface->Release();
       lpPrimarySurface = NULL;
   }

   if ( lpClipper != NULL)
   {
       lpClipper->Release();
       lpClipper = NULL;
   }

   if ( lpBmpSurface != NULL )
   {
       lpBmpSurface->Release();
       lpBmpSurface = NULL;
   }

   if ( lpDD != NULL )
   {
       lpDD->Release();
       lpDD = NULL;
   }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值