|
我最近也在搞这个东西.是win32的.一直没搞定分享下.
您的代码没仔细看过,我和您的解决方案也不一样.
/////////////////////////////////////////////////////////////////////////////
// CBeexb_gifView message handlers
typedef struct gifImage{
WORD lWidth;
WORD lHeight;
WORD width;
WORD height;
struct flag{
BYTE d:3;
BYTE c:1;
BYTE b:3;
BYTE a:1;
}Flag;
}GifImage,*PGifImage;
#include
static UINT GifThread(LPVOID gifDC)
{
CDC* pdc = (CDC*)gifDC;
HINSTANCE handle = ::AfxGetResourceHandle();
HRSRC hrsrc = ::FindResource(handle,MAKEINTRESOURCE(IDR_IMAGE1),"IMAGE");
DWORD word = ::SizeofResource(handle,hrsrc);
BYTE* lpBy = (BYTE*)LoadResource(handle,hrsrc);
BYTE* pByte[20];
DWORD nu[20];
int num = 0;
DWORD firstLocation = 0;
for(DWORD j=0;j
{
if(lpBy[j]==0x2c)
{
if(lpBy[j-1]==0x00)
{
if(num==0)
{
firstLocation = j;
}
PGifImage nowImage = (PGifImage)&lpBy[j+1];
if(nowImage->Flag.a==0)
{
DWORD number = 1+sizeof(GifImage);
while(lpBy[j+number]!=0)
{
number = number+(DWORD)lpBy[j+number]+1;
}
number++;
pByte[num] = new BYTE[number];
for(DWORD n=0;n
{
*(BYTE*)(pByte[num]+n) = lpBy[j+n];
}
nu[num] = number;
j = j+number-1;
num++;
}
else
{
int number = 1+sizeof(GifImage)+1+3*(int)floor(pow(2,nowImage->Flag.d));
while(lpBy[j+number]!=0)
{
number = number+lpBy[j+number];
}
pByte[num] = new BYTE[number];
for(int n=0;n
{
*(BYTE*)(pByte[num]+n) = lpBy[j+n];
}
nu[num] = number;
j = j+number-1;
num++;
}
}
}
}
int i = 1;
while(i)
{
for(int m=0;m
{
CBrush brush(RGB(255,255,255));
pdc->FillRect(CRect(0,0,500,500),&brush);
DWORD DDD;
VirtualProtect(lpBy,word,PAGE_READWRITE,&DDD);
for(DWORD n=0;n
{
lpBy[firstLocation+n] = *(BYTE*)(pByte[m]+n);
}
VirtualProtect(lpBy,word,DDD,NULL);
CMemFile file(lpBy,word);
CArchive ar(&file,CArchive::load|CArchive::bNoFlushOnDelete);
CArchiveStream arcstream(&ar);
CComQIPtr m_picture;
HRESULT hr = OleLoadPicture((LPSTREAM)&arcstream,0,false,IID_IPicture,(void**)&m_picture);
long a,b;
m_picture->get_Width(&a);
m_picture->get_Height(&b);
CSize sz(a,b);
pdc->HIMETRICtoDP(&sz);
CRect rect;
m_picture->Render(*pdc,0,0,sz.cx,sz.cy,0,b,a,-b,&rect);
Sleep(1000);
}
}
return 1;
}
void CBeexb_gifView::OnShowGif()
{
static BOOL bIsRunning = FALSE;
if(!bIsRunning)
{
CDC* pdc = GetDC();
m_gifDC = new CDC;
m_gifDC->Attach(pdc->GetSafeHdc());
AfxBeginThread(GifThread,(LPVOID)m_gifDC);
bIsRunning = TRUE;
}
}
这个是基于MFC的(能运行,实际操作就是分别把gif里的各张图片分张显示,Sleep(1000)间隔显示).我正想把他改成win32的.有点麻烦.
再问下(水木倩) HBITMAP CreateGifBitmap(int nWidth, int nHeight, void ** ppBuffer)
void ** ppBuffer 可以从哪个函数得到?用你那个函数得到HBITMAP
然后经过
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
BitBlt(ps.hdc, (rect.right - bm.bmWidth) / 2,(rect.bottom - cy) / 2, bm.bmWidth, bm.bmHeight,hMemDC, 0, 0, SRCCOPY);
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);就能直接显示动态gif了吗?不是要只能显示第一帧的那种.或者是需要其他途径.
我还尝试了其他方法如picture control.发现只能显示bmp和ico(太天真了).
还有个问题:那个大虾知道怎么搞progress bar control吗?要win32工程的.就是我提交一个socket请求那段时间让它显示下进度.别让客户等太急.谢谢. |
|