📄 demodlg.cpp
字号:
if(m_picture.Draw(&mdc,0,0,pw,ph)==false)
{
//外部
MemDC.SelectObject(oldbmp);
tmpbmp.DeleteObject();
MemDC.DeleteDC();
//内部
mdc.SelectObject(ob);
tb.DeleteObject();
mdc.DeleteDC();
return;
}
//flat 贴图
int xx,yy;
xx=w/pw;
yy=h/ph;
if(w%pw!=0) xx++;
if(h%ph!=0) yy++;
//水平方向://垂直方向
for(int i=0;i<xx;i++)
for(int j=0;j<yy;j++)
{
MemDC.BitBlt(i*pw, j*ph, pw,ph, &mdc, 0, 0, SRCCOPY);
}
////内部
mdc.SelectObject(ob);
tb.DeleteObject();
mdc.DeleteDC();
}
//VERIFY(MemDC.StretchBlt(0, 0, w,h,&memDc, 0, 0, bminfo.bmWidth,bminfo.bmHeight,SRCCOPY));
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//SHOW==========================================
DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
//==============================================
//release resource
MemDC.SelectObject(oldbmp);
tmpbmp.DeleteObject();
MemDC.DeleteDC();
//######################################################################
//string fileName = ...;//得到文件名
//int i = fileName.LastIndexOf(".");
//string newExt = fileName.Substring(i);//取得文件扩展名
//CString filename;
/* CClientDC dc(this);
CRect rect;
GetClientRect(&rect);
int w,h;
w=rect.Width();
h=rect.Height();
//
CString strDir(filename);
strDir.TrimLeft();
strDir.TrimRight();
CString strExt1 = strDir.Right(3);
strExt1.MakeUpper();
char strExt[256];
strcpy(strExt,strExt1.GetBuffer(strExt1.GetLength()));
//
if(strcmp(strExt,"JPG")==0)//JPG
{
//load jpeg
HBITMAP m_hBitmap;
m_hBitmap = LoadJpegImage(filename);
if (m_hBitmap)
{
CDC memDc;
VERIFY(memDc.CreateCompatibleDC(&dc));
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(memDc.GetSafeHdc(), m_hBitmap);
//VERIFY(dc.BitBlt(0, 0, 640,480, &memDc, 0, 0, SRCCOPY));
BITMAP bminfo;
::GetObject(m_hBitmap,sizeof(BITMAP),&bminfo);
//???VERIFY(dc.StretchBlt(0, 0, w,h,&memDc, 0, 0, bminfo.bmWidth,bminfo.bmHeight,SRCCOPY));
//######################################################################
MemDC.CreateCompatibleDC(&dc);
tmpbmp.CreateCompatibleBitmap(&dc,w,h);
CBitmap *oldbmp=MemDC.SelectObject(&tmpbmp);
//copy...
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
VERIFY(MemDC.StretchBlt(0, 0, w,h,&memDc, 0, 0, bminfo.bmWidth,bminfo.bmHeight,SRCCOPY));
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//SHOW==========================================
DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
//==============================================
//release resource
MemDC.SelectObject(oldbmp);
tmpbmp.DeleteObject();
MemDC.DeleteDC();
//######################################################################
::SelectObject(memDc.GetSafeHdc(), hOldBitmap);
VERIFY( memDc.DeleteDC() );
//free system resource
::DeleteObject(m_hBitmap);
m_hBitmap=NULL;
}
}
else if(strcmp(strExt,"GIF")==0)
{
//LPCGLOBAL_INFO gi;
// LPCFRAME fm;
//
//CGif89a gif;
HBITMAP m_hBitmap;
// BYTE *imageData;
//
//打开GIF图象文件
//
if(!gif.open(filename,false))
{
//AfxMessageBox(TEXT("open gif error"),MB_OK);
return;
}
//Memo1->Lines->Add("版本="+StrPas(gif.getVer())+"\r\n");
gi = gif.getGlobalInfo();
//get data to buffer
imageData= (UNALIGNED BYTE*)::malloc(gi->scrWidth*gi->scrHeight*3);
if(!imageData)
{
gif.close();
return ;
}
// get cur gif frame
fm = gif.getHeadFrame();// .getNextFrame();
if(fm == NULL)
{
gif.close();
::free(imageData);
imageData=NULL;
return;
}
//Load cur frame
m_hBitmap =LoadGifCurFrame(imageData,gi,fm);
if (! m_hBitmap)
{
::free(imageData);
imageData=NULL;
gif.close();
return ;//FALSE;
}
//if correct then show
CDC tmpDC;
VERIFY(tmpDC.CreateCompatibleDC(&dc));
//selectobject
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(tmpDC.GetSafeHdc(), m_hBitmap);
//CRect rect;
//GetClientRect(&rect);
//BITMAP bminfo;
//::GetObject(m_hBitmap,sizeof(BITMAP),&bminfo);
//show pic bitmap
//VERIFY(dc.StretchBlt(0, 0, rect.Width(),rect.Height(),
// &tmpDC, 0, 0, bminfo.bmWidth,bminfo.bmHeight,SRCCOPY));
//??VERIFY(dc.StretchBlt(0, 0, w,h,&tmpDC, 0, 0, gi->scrWidth,gi->scrHeight,SRCCOPY));
//########################################################################
MemDC.CreateCompatibleDC(&dc);
tmpbmp.CreateCompatibleBitmap(&dc,w,h);
CBitmap *oldbmp=MemDC.SelectObject(&tmpbmp);
//copy...
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
VERIFY(MemDC.StretchBlt(0, 0, w,h,
&tmpDC, 0, 0, gi->scrWidth,gi->scrHeight,SRCCOPY));
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//SHOW==========================================
DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
//==============================================
//release resource
//free
MemDC.SelectObject(oldbmp);
tmpbmp.DeleteObject();
MemDC.DeleteDC();
//##################################################################
//free
::SelectObject(tmpDC.GetSafeHdc(), hOldBitmap);
VERIFY( tmpDC.DeleteDC() );
// Invalidate(FALSE);
//release
::DeleteObject(m_hBitmap);
m_hBitmap=NULL;
//
//free data
::free(imageData);
imageData=NULL;
//关闭gif文件
gif.close();
}
else//bmp
{
CDIBSectionLite dibsection;
if(dibsection.Load(filename))
//dibsection.Draw(&dc, CPoint(0,0));
//show
//dibsection.Stretch(&dc,CPoint(0,0),CSize(rect.Width(),rect.Height()));
MemDC.CreateCompatibleDC(&dc);
tmpbmp.CreateCompatibleBitmap(&dc,w,h);
CBitmap *oldbmp=MemDC.SelectObject(&tmpbmp);
//copy...
dibsection.Stretch(&MemDC,CPoint(0,0),CSize(w,h));
//SHOW==========================================
DemoPic(dc,MemDC, w, h, in,out, speed,delaytime);
//==============================================
//release resource
MemDC.SelectObject(oldbmp);
tmpbmp.DeleteObject();
MemDC.DeleteDC();
}*/
}
void CDemoDlg::ShowGifAni(CString filename,long speed,long times,int position )
{
CClientDC dc(this);
//LPCGLOBAL_INFO gi;
// LPCFRAME fm;
//
//CGif89a gif;
// HBITMAP m_hBitmap;
// BYTE *imageData;
//
//打开GIF图象文件
//
if(!gif.open(filename,false))
{
//AfxMessageBox(TEXT("open gif error"),MB_OK);
return;
}
//Memo1->Lines->Add("版本="+StrPas(gif.getVer())+"\r\n");
gi = gif.getGlobalInfo();
//get data to buffer
imageData= (UNALIGNED BYTE*)::malloc(gi->scrWidth*gi->scrHeight*3);
if(!imageData)
{
gif.close();
return ;
}
//create dc buffer
//MemDC.CreateCompatibleDC(&dc);
CRect rect;
GetClientRect(&rect);
long ttt=times;
if(ttt<=0) ttt=1;
for(int kkk=0;kkk<ttt;kkk++)
{
if(m_all_run_flag==false) break;
//reset gif
gif.Reset();
//显示所有显示帧画面
for(UINT n=0;n<gi->frames;n++)
{
if(m_all_run_flag==false) break;
// get cur gif frame
fm = gif.getNextFrame();
if(fm == NULL)
{
gif.close();
::free(imageData);
imageData=NULL;
return;
}
if(m_all_run_flag==false) break;
//Load cur frame
HBITMAP m_hBitmap;
m_hBitmap =LoadGifCurFrame(imageData,gi,fm);
if (! m_hBitmap)
{
::free(imageData);
imageData=NULL;
gif.close();
return ;//FALSE;
}
//if correct then show
//CClientDC dc(this);
CDC tmpDC;
VERIFY(tmpDC.CreateCompatibleDC(&dc));
//selectobject
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(tmpDC.GetSafeHdc(), m_hBitmap);
//BITMAP bminfo;
//::GetObject(m_hBitmap,sizeof(BITMAP),&bminfo);
//show pic bitmap
if(position==0)//center
{
//
int sx,sy;
if(gi->scrWidth>=rect.Width()) sx=0;
if(gi->scrHeight>=rect.Height()) sy=0;
sx=(rect.Width()-gi->scrWidth)/2;
sy=(rect.Height()-gi->scrHeight)/2;
VERIFY(dc.BitBlt(sx, sy,gi->scrWidth,gi->scrHeight,
&tmpDC, 0, 0,SRCCOPY));
}
else if(position==1)//stretch,flag
{
VERIFY(dc.StretchBlt(0, 0, rect.Width(),rect.Height(),
&tmpDC, 0, 0, gi->scrWidth,gi->scrHeight,SRCCOPY));
}
else//flat
{
int w,h;
w=rect.Width();
h=rect.Height();
int pw,ph;
pw=gi->scrWidth;
ph=gi->scrHeight;
//双缓冲
CBitmap tmpbmp,*oldbmp;
CDC MemDC;
//######################################################################
MemDC.CreateCompatibleDC(&dc);
tmpbmp.CreateCompatibleBitmap(&dc,w,h);
oldbmp=MemDC.SelectObject(&tmpbmp);
//
CBitmap tb,*ob;
CDC mdc;
//######################################################################
mdc.CreateCompatibleDC(&dc);
tb.CreateCompatibleBitmap(&dc,pw,ph);
ob=mdc.SelectObject(&tb);
//
VERIFY(mdc.BitBlt(0, 0,pw,ph,&tmpDC, 0, 0,SRCCOPY));
//flat 贴图
int xx,yy;
xx=w/pw;
yy=h/ph;
if(w%pw!=0) xx++;
if(h%ph!=0) yy++;
//水平方向://垂直方向
for(int i=0;i<xx;i++)
for(int j=0;j<yy;j++)
{
MemDC.BitBlt(i*pw, j*ph, pw,ph, &mdc, 0, 0, SRCCOPY);
}
////free
mdc.SelectObject(ob);
tb.DeleteObject();
mdc.DeleteDC();
//
VERIFY(dc.BitBlt(0, 0,w,h,&MemDC, 0, 0,SRCCOPY));
//release resource
MemDC.SelectObject(oldbmp);
tmpbmp.DeleteObject();
MemDC.DeleteDC();
}
//free
::SelectObject(tmpDC.GetSafeHdc(), hOldBitmap);
VERIFY( tmpDC.DeleteDC() );
// Invalidate(FALSE);
//release
::DeleteObject(m_hBitmap);
m_hBitmap=NULL;
//Delay Time for speed
if(fm->ctrlExt.active)
Sleep(fm->ctrlExt.delayTime*10);
else
Sleep(speed);
}
}
//free data
::free(imageData);
imageData=NULL;
//关闭gif文件
gif.close();
}
void CDemoDlg::ShowVideo(CString filename,int position)
{
// Filenames on Windows CE start with a \\ instead of a drive letter.
if(filename.GetLength()<=0) return;
m_position=position;
//如果文件不存在
FILE *fp;
fp=fopen(filename.GetBuffer(filename.GetLength()),"rb");
if(!fp) return;
fclose(fp);
USES_CONVERSION;
WCHAR wFile[MAX_PATH];
// Convert filename to wide character string
wcsncpy(wFile, T2W(filename), NUMELMS(wFile)-1);
wFile[MAX_PATH-1] = 0;
//init
m_video_finished_flag=false;
//???????????????????
HRESULT hr;
CRect rc;
// Create the filter graph manager and render the file.
hr=CoInitialize ( NULL );
if(FAILED(hr)) return;
//if(!m_pGraph)
hr=CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&m_pGraph);
//hr=CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder,
// (void **)&m_pGraph);
if(FAILED(hr)) goto exit_video;//return;
//Medial CONTROL
hr=m_pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pMediaControl);
if(FAILED(hr))
{
//SAFE_RELEASE(m_pGraph);
goto exit_video;
}
hr = m_pGraph->RenderFile(wFile, NULL);
if(FAILED(hr))
{
goto exit_video;
}
//指定父窗体
// IVideoWindow* pVidWin = NULL;
hr =m_pGraph->QueryInterface(IID_IVideoWindow, (void **)&m_pVidWin);
if(FAILED(hr))
{
goto exit_video;
}
hr=m_pVidWin->put_Owner((OAHWND)GetSafeHwnd());
if(FAILED(hr))
{
goto exit_video;
}
hr=m_pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS| WS_CLIPCHILDREN);
if(FAILED(hr))
{
goto exit_video;
}
//
hr=m_pGraph->QueryInterface(IID_IBasicVideo, (void **)&pBV);
if(FAILED(hr))
{
goto exit_video;
}
GetClientRect(&rc);
if(position>0)
{
hr=m_pVidWin->SetWindowPosition(rc.left, rc.top, rc.Width(), rc.Height());
if(FAILED(hr))
{
goto exit_video;
}
}
else//center
{
LONG lHeight, lWidth;
hr = pBV->GetVideoSize(&lWidth, &lHeight);
if(FAILED(hr))
{
goto exit_video;
}
int sx,sy;
int w,h;
w=rc.Width();
h=rc.Height();
if(lWidth>=w) sx=0;
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -