// TODO: 在此添加控件通知处理程序代码
height=width=widthBytes=0;
m_screen.SetWindowPos(&CWnd::wndBottom,0,0,720,576, SWP_NOMOVE | SWP_SHOWWINDOW);
UpdateWindow();
main_window_handle = m_screen.GetSafeHwnd();
if(DD_OK!=(DirectDrawCreateEx(NULL, (void **)&lpdd7, IID_IDirectDraw7, NULL)))
{
return ;
}
// set the cooperative level for full-screen mode
if(DD_OK != lpdd7->SetCooperativeLevel(AfxGetMainWnd()->GetSafeHwnd(), DDSCL_NORMAL))
{
return ;
}
/*设置控制级时,如果应用程序请求了 DDSCL_NORMAL 模式(表明应用程序以普通窗口的形式运行),则不需要提供一个指定窗口的句柄.给窗口句柄参数为 NULL, 所有的窗口都可以被设置为普通的控制级. */
// set the display mode to 640x480x256
// clear ddsd and set size
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
// enable valid fields
ddsd.dwFlags=DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
// create the primary surface
if(DD_OK!=(lpdd7->CreateSurface(&ddsd, &lpddsprimary, NULL)))
{
return ;
}
// 创建裁剪器
if (FAILED(lpdd7->CreateClipper(0, &lpDDClipper, NULL)))
return ;
// 与窗口工作区关联
if (FAILED(lpDDClipper->SetHWnd(0, main_window_handle)))
{
lpDDClipper->Release();
return ;
}
if (FAILED(lpddsprimary->SetClipper(lpDDClipper)))
{
lpDDClipper->Release();
return ;
}
//
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
//DDPIXELFORMAT camdispPixelFormat = {sizeof(DDPIXELFORMAT), DDPF_FOURCC, mmioFOURCC('Y','U','1','2'), 0,0,0,0,0};
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
ddsd.dwWidth = 720;
ddsd.dwHeight = 576;
//ddsd.dwBackBufferCount = 0;//忽略 //忽略
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN| DDSCAPS_VIDEOMEMORY;
//ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB ;
ddsd.ddpfPixelFormat.dwFourCC = 0;
ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
ddsd.ddpfPixelFormat.dwRBitMask = 0xf800;
ddsd.ddpfPixelFormat.dwGBitMask = 0x7E0;
ddsd.ddpfPixelFormat.dwBBitMask = 0x1F;
ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0;
//
if(DD_OK!=(lpdd7->CreateSurface(&ddsd, &lpddsmypage[0], NULL)))
{
return ;
}
POINT p;
p.x = 0; p.y = 0;
m_screen.ClientToScreen(&p);//获取屏幕顶点
// m_screen.GetClientRect(&rcRectDest);
rcRectDest.left = 0; rcRectDest.top=0; rcRectDest.right = 720; rcRectDest.bottom = 576;
OffsetRect(&rcRectDest, p.x, p.y);//把窗口区域转化为屏幕区域坐标
SetRect(&rcRectSrc, 0, 0, 720, 576);//初始化窗口区域
/////////////////////////////////////////////////////////////
FILE *fp;
buf[0] = new BYTE[720*576*3];
// buf[1] = new BYTE[720*576];
// buf[2] = new BYTE[720*576/4];
fp = fopen("d:\\temp\\7205762.bmp","rb+");
fread(buf[0],54,1,fp);
fread(buf[0],720*576*3,1,fp);
//while(!feof(fp))
{
if(DD_OK != lpddsmypage[0]->Lock(NULL,&ddsd,DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR,NULL))
{
return ;
}
UCHAR *lp_buffer = (UCHAR *)ddsd.lpSurface;
WORD tmp=0;
WORD *bmp555=new WORD[720];
///////////////////////////提取数据/////////////////////////////////////////////
for (int i=0;i<576;i++)
{
for (int k=0;k<720;k++)
{
tmp = ((buf[0][(i*720+k)*3+2]&0xf8)>>3)<<11 | ((buf[0][(i*720+k)*3+1]&0xfc)>>2)<<5 | (buf[0][(i*720+k)*3+0]&0xf8)>>3;
bmp555[k] = tmp&0xffff;
}
memcpy(lp_buffer +(575-i)*ddsd.lPitch,bmp555,720*2);
}
Sleep(40);
//////////////////////////////////////////////////////////////////////////
//memcpy(bmp_buffer,buf[0],720*576*2);
if(DD_OK != lpddsmypage[0]->Unlock(NULL))
{
return ;
}
HRESULT ddRval;
ddRval= lpddsprimary->Blt( &rcRectDest, lpddsmypage[0], &rcRectSrc, DDBLT_WAIT, NULL);
//while(ddRval == DDERR_WASSTILLDRAWING);
//ddRval=lpddsprimary->Flip(lpddsmypage[0],1);
if(DD_OK != ddRval)
{
return ;
}
}
//fclose(fp);
if(lpddsmypage)
{
lpddsmypage[0]->Release();
lpddsmypage[0]=NULL;
}
MessageBox(_T("over"));