调用的类:ImageEx 
出现错误: 在运行是报错 Unhandled exception at 0x004bebd1 in test.exe: 0xC0000005: Access violation reading location 0x00000004.LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
UINT frameCount;
Image* image =new Image(L"hearts.gif");
PropertyItem * pItem = NULL;
        UINT count = 0;
switch (message)
{ case WM_CREATE:
{
count = image->GetFrameDimensionsCount();
GUID *pDimensionIDs=(GUID*)new GUID[count];
image->GetFrameDimensionsList(pDimensionIDs,count);
WCHAR strGuid[39];
StringFromGUID2(pDimensionIDs[0], strGuid, 39);
frameCount = image->GetFrameCount(&pDimensionIDs[0]);
delete []pDimensionIDs;
             int size = image->GetPropertyItemSize(PropertyTagFrameDelay); pItem =(PropertyItem*)malloc(size);

image ->GetPropertyItem(PropertyTagFrameDelay,size,pItem); return 0;
}
case WM_COMMAND:
wmId    = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT: 

hdc = BeginPaint(hWnd, &ps);
              int     fcount=0;
          // Guid的值在显示GIF为FrameDimensionTime,显示TIF时为frameDimensionPage
                  GUID    Guid = FrameDimensionTime;
        while(TRUE)
{
        Graphics gh(hdc);             //hDC是外部传入的画图DC
        gh.DrawImage(image,0,0,image->GetWidth(),image->GetHeight());
                                    //重新设置当前的活动数据帧
        image->SelectActiveFrame(&Guid,fcount++);
        if(fcount == frameCount)  //frameCount是上面GetFrameCount返回值
              fcount= 0;         //如果到了最后一帧数据又重新开始
                                //计算此帧要延迟的时间
        long lPause = ((long*)pItem->value)[fcount]*10;
        Sleep(lPause);        //这里简单使用了sleep
        }
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE; case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}

解决方案 »

  1.   

    WndProc每秒可能被调用几十次,甚至窗口还没初始化完成前就有调用。 每次都要 Image* image = new Image(L"");不死才怪。LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 

    int wmId, wmEvent; 
    PAINTSTRUCT ps; 
    HDC hdc; 
    UINT frameCount; 
    Image* image =new Image(L"hearts.gif"); 
    PropertyItem * pItem = NULL; 
      

  2.   

    Image* image =new Image(L"hearts.gif"); 
    在WINMAIN函数里动态声请一次,定image 为全局变量,在窗体销毁的时候,否则在合适的地方释放掉,就可以了
      

  3.   

    你是要显示gif图片嘛?
    不久前刚刚实现在我的对话框中显示动态gif图片,使用的是一个类,PictureEx,你可以去搜一下