2025年显示动态gif图片

显示动态gif图片DWORD WINAPI GifThread LPVOID lpParam 查找资源 加载资源到内存 锁定资源 HRSRC hRsrc FindResource hInst MAKEINTRESOU IDR GIF L GIF HGLOBAL hGlobal

大家好,我是讯享网,很高兴认识大家。
DWORD WINAPI GifThread(LPVOID lpParam) { //查找资源,加载资源到内存,锁定资源 HRSRC hRsrc = FindResourceW(hInst, MAKEINTRESOURCEW(IDR_GIF), L"GIF"); HGLOBAL hGlobal = LoadResource(hInst, hRsrc); LPVOID lpResData = LockResource(hGlobal); DWORD dwResSize = SizeofResource(hInst, hRsrc); //获得系统环境路径 WCHAR szResPath[MAX_PATH] = L"\0"; GetEnvironmentVariableW(L"TEMP", szResPath, sizeof(szResPath)); wcscat(szResPath, L"\\hhhhgif.gif"); //建立flash资源文件 HANDLE hFile = CreateFileW(szResPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, NULL, NULL); if (hFile != INVALID_HANDLE_VALUE) { DWORD dwWritten; WriteFile(hFile, lpResData, dwResSize, &dwWritten, NULL); } CloseHandle(hFile); FreeResource (hGlobal); //释放flash资源 //显示gif HDC hdc = GetDC(g_hwnd); Image *image = new Image(szResPath); if (image == NULL) { return -1; } UINT count = 0; count = image->GetFrameDimensionsCount(); GUID *pDimensionIDs = (GUID*)new GUID[count]; image->GetFrameDimensionsList(pDimensionIDs, count); WCHAR strGuid[39]; StringFromGUID2(pDimensionIDs[0], strGuid, 39); UINT frameCount = image->GetFrameCount(&pDimensionIDs[0]); delete []pDimensionIDs; int size = image->GetPropertyItemSize(PropertyTagFrameDelay); PropertyItem *pItem = NULL; pItem = (PropertyItem*)malloc(size); image->GetPropertyItem(PropertyTagFrameDelay,size,pItem); UINT fcount=0; GUID Guid = FrameDimensionTime; while (g_gif) { Graphics graphics(hdc); graphics.DrawImage(image, 50, 120, 400, 200); image->SelectActiveFrame(&Guid, fcount++); if (fcount == frameCount) fcount=0; long lPause = ((long*)pItem->value)[fcount]*10; Sleep(lPause); } ReleaseDC(g_hwnd, hdc); return 0; }

讯享网
讯享网#define TIMER_FIR 1 #define TIMER_SEC 2 //利用两个定时器,分别显示多帧的gif BOOL CALLBACK GifDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; HBRUSH hBrush, hOldbrush; RECT rect; static Image *image; static UINT count; static WCHAR strGuid[39]; static UINT frameCount; static PropertyItem* pItem=NULL; static UINT fcount; static GUID Guid; static long lPause; static int size; static GUID *pDimensionIDs; //gdi+用到的两个变量 GdiplusStartupInput m_gdiplusStartupInput; static ULONG_PTR m_pGdiToken; static WCHAR szResPath[MAX_PATH] = L"\0"; switch (message) { case WM_INITDIALOG: { //装载gdi+ GdiplusStartup(&m_pGdiToken, &m_gdiplusStartupInput, NULL); //查找资源,加载资源到内存,锁定资源 HRSRC hRsrc = FindResourceW(hInst, MAKEINTRESOURCEW(IDR_GIF), L"GIF"); HGLOBAL hGlobal = LoadResource(hInst, hRsrc); LPVOID lpResData = LockResource(hGlobal); DWORD dwResSize = SizeofResource(hInst, hRsrc); //获得系统环境路径 GetEnvironmentVariableW(L"TEMP", szResPath, sizeof(szResPath)); wcscat(szResPath, L"\\hhhhgif.gif"); //建立flash资源文件 HANDLE hFile = CreateFileW(szResPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, NULL, NULL); if (hFile != INVALID_HANDLE_VALUE) { DWORD dwWritten; WriteFile(hFile, lpResData, dwResSize, &dwWritten, NULL); } CloseHandle(hFile); FreeResource (hGlobal); //释放flash资源 SetTimer(hDlg,TIMER_FIR,0,NULL); } break; case WM_TIMER: { switch(wParam) { case TIMER_FIR: { hdc=GetDC(hDlg); image=new Image(szResPath); count=0; count=image->GetFrameDimensionsCount(); pDimensionIDs=(GUID*)new GUID[count]; image->GetFrameDimensionsList(pDimensionIDs,count); StringFromGUID2(pDimensionIDs[0],strGuid,39); frameCount=image->GetFrameCount(&pDimensionIDs[0]); delete []pDimensionIDs; size=image->GetPropertyItemSize(PropertyTagFrameDelay); //PropertyItem* pItem=NULL; // pItem=(PropertyItem*)malloc(size); pItem=(PropertyItem*)new PropertyItem[size]; image->GetPropertyItem(PropertyTagFrameDelay,size,pItem); fcount=0; Guid=FrameDimensionTime; Graphics graphics(hdc); graphics.DrawImage(image,0,0); image->SelectActiveFrame(&Guid,fcount++); if(fcount==frameCount) fcount=0; lPause=((long*)pItem->value)[fcount]*10; ReleaseDC(hDlg,hdc); KillTimer (hDlg, TIMER_FIR) ; SetTimer(hDlg,TIMER_SEC,lPause,NULL); InvalidateRect (hDlg, NULL, FALSE) ; break; } case TIMER_SEC: { image->SelectActiveFrame(&Guid,fcount++); if(fcount==frameCount) fcount=0; lPause=((long*)pItem->value)[fcount]*10; KillTimer(hDlg,TIMER_SEC); SetTimer(hDlg,TIMER_SEC,lPause,NULL); InvalidateRect (hDlg, NULL, FALSE) ; } } } break; case WM_PAINT: { hdc = BeginPaint(hDlg, &ps); // TODO: 在此添加任意绘图代码... //hBrush = CreateSolidBrush(RGB(68,68,68)); //创建新画刷 //GetClientRect(hDlg, &rect); //获得主窗口的面积 //hOldbrush = (HBRUSH)SelectObject(hdc, hBrush); //把画刷选入设备 //Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom); //FrameRect(hdc, &rect, hBrush); //重画窗口边框 //SelectObject(hdc, hOldbrush); //把旧画刷选入设备 Graphics graphics(hdc); graphics.DrawImage(image,0,0); EndPaint(hDlg, &ps); } break; } return FALSE; }


小讯
上一篇 2025-01-09 22:08
下一篇 2025-01-23 20:12

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/61696.html