最近刚接触MFC,在调试项目的时候,点击退出时总会触发一个断点,如果直接运行exe(无论是debug还是release)都没有问题。
设置断点发现是在GdiplusShutdown(m_pGdiToken);处触发的的断点。
basic::basic()
{
GdiplusStartup(&m_pGdiToken, &m_gdiplusStartupInput, NULL);
}
basic::~basic()
{
GdiplusShutdown(m_pGdiToken);
}
查看相关代码始终没有找到,触发断点原因,相关代码如下:
bool ui::img_from_res(UINT nID, LPCTSTR sTR, Image * &pImg)
{
HINSTANCE hInst = AfxGetResourceHandle();
HRSRC hRsrc = ::FindResource (hInst, MAKEINTRESOURCE(nID), sTR); // type
if (!hRsrc)
return false;
// load resource into memory
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc)
return false;
// Allocate global memory on which to create stream
HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
memcpy(pmem,lpRsrc,len);
IStream* pstm;
CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);
// load from stream
pImg = Gdiplus::Image::FromStream(pstm);
// free/release stuff
GlobalUnlock(m_hMem);
pstm->Release();
FreeResource(lpRsrc);
return true;
}
DWORD ui::gifproc(LPVOID lpParam)
{
Image *img = (Image *)lpParam;
UINT nCount = img->GetFrameDimensionsCount();
GUID* pDimensionsIDs = (GUID*)new GUID[nCount];
img->GetFrameDimensionsList(pDimensionsIDs,nCount);
wchar_t strGUID[39]={0};
StringFromGUID2(pDimensionsIDs[0], strGUID, 39);
UINT nFrameCount = img->GetFrameCount(&pDimensionsIDs[0]);
delete[] pDimensionsIDs;
int size = img->GetPropertyItemSize(PropertyTagFrameDelay);
byte *p = new byte[size];
PropertyItem* pItem = (PropertyItem*)p;
img->GetPropertyItem(PropertyTagFrameDelay,size, pItem);
int fcount = 0;
GUID guid = FrameDimensionTime;
HDC hDC = ::GetDC(m_gifwnd);
Graphics gc(hDC);
RECT rect = {0};
GetClientRect(m_gifwnd, &rect);
int x = (rect.right - img->GetWidth()) / 2;
int y = (rect.bottom - img->GetHeight()) / 2;
while (m_gifruning)
{
gc.DrawImage(img, x, y, img->GetWidth(), img->GetHeight());
img->SelectActiveFrame(&guid, fcount++);
if (fcount == nFrameCount)
{
fcount = 0;
}
//long pause = ((long*)pItem->value)[fcount];
//Sleep(pause);
}
::ReleaseDC(m_gifwnd, hDC);
delete []p;
return 0;
}
void ui::bitmap_ex(HDC hDC, HBITMAP hbitmap, int x, int y, int w, int h, int hv)
{
if (hDC != NULL && hbitmap != NULL)
{
if (hv == 0)
{
BITMAP bmp;
HDC hMM = CreateCompatibleDC(hDC);
GetObject(hbitmap, sizeof(BITMAP), &bmp);
SelectObject(hMM, hbitmap);
SetStretchBltMode(hDC, HALFTONE);
StretchBlt(hDC, x, y, w, h, hMM, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
DeleteObject(hbitmap);
DeleteObject(hMM);
}
else
{
Graphics gr(hDC);
Bitmap bitmap(hbitmap, NULL);
if (hv == 1)
{
Point HoPoints[] = {Point(x + w, y), Point(x, y), Point(x + w, y + h)};
gr.DrawImage(&bitmap, HoPoints, 3);
}
else if (hv == 2)
{
Point VePoints[] = {Point(x, y + h), Point(x + w, y + h), Point(x, y)};
gr.DrawImage(&bitmap, VePoints, 3);
}
}
}
}
求大神指点一下。