我用CSplitterWnd分了主窗口后,然后在每个视中画图做界面用,可这个程序占用CPU达到98%,不是为什么?

解决方案 »

  1.   

    那些情况会生产GDI资源泄漏?
      

  2.   

    void CShowBitmap::DrawBitmap(int Left,int Top,int From,int To,CDC* pDC)
    {
    //Is the filename loaded
    if(!IsFileLoaded)
    {
    MessageBox(NULL,"The filename of bitmap has not been loaded!","ERROR",MB_OK|MB_ICONERROR);
    return;
    }
    //To open the bitmap file
    CFile file;
    if(!file.Open("Bmps/"+FileName,CFile::modeRead,NULL))
    {
    MessageBox(NULL,"Can not open the bitmap file!","ERROR",MB_OK|MB_ICONERROR);
    return;
    }
    //To read the BITMAPFILEHEADER
    BITMAPFILEHEADER bfHeader;
    if(file.Read((void*)&bfHeader,sizeof(BITMAPFILEHEADER))!=sizeof(BITMAPFILEHEADER))
    {
    MessageBox(NULL,"Can not read the BITMAPFILEHEADER!","ERROR",MB_OK|MB_ICONERROR);
    file.Close();
    return;
    }
    //To read the BITMAPINFOHEADER
    BITMAPINFOHEADER biHeader;
    if(file.Read((void*)&biHeader,sizeof(BITMAPINFOHEADER))!=sizeof(BITMAPINFOHEADER))
    {
    MessageBox(NULL,"Can not read the BITMAPINFOHEADER!","ERROR",MB_OK|MB_ICONERROR);
    file.Close();
    return;
    }
    //Calculate the colors
    int nColors=0;
    if(biHeader.biBitCount<24) //if the RGBQUAD is in the data file
    {
    nColors=1<<biHeader.biBitCount;
    }
    //Contribute the memory for the new BITMAPINFO
    BITMAPINFO* pBi;
    pBi=(BITMAPINFO*) new BYTE[sizeof(BITMAPINFOHEADER)+nColors*sizeof(RGBQUAD)];
    memcpy(pBi,&biHeader,sizeof(BITMAPINFOHEADER));
    //Read the RGBQUAD
    RGBQUAD* pQuad;
    pQuad=(RGBQUAD*)((BYTE*)pBi+sizeof(BITMAPINFOHEADER));
    if(file.Read((void*)pQuad,nColors*sizeof(RGBQUAD))!=nColors*sizeof(RGBQUAD))
    {
    MessageBox(NULL,"Can not read the RGBQUAD!","ERROR",MB_OK|MB_ICONERROR);
    file.Close();
    return;
    }
    //Read the image data
    void* pImageData;
    biHeader.biSizeImage=bfHeader.bfSize-bfHeader.bfOffBits;
    pImageData=(void*) new BYTE[biHeader.biSizeImage];
    if(file.Read(pImageData,biHeader.biSizeImage)!=biHeader.biSizeImage)
    {
    MessageBox(NULL,"Can not read the IMAGE DATA!","ERROR",MB_OK|MB_ICONERROR);
    file.Close();
    return;
    }
    //Draw the picture
    //From: Scan start line
    //To:   Line to Scan to
    SetDIBitsToDevice(pDC->GetSafeHdc(),Left,Top,biHeader.biWidth,biHeader.biHeight,
    0,0,From,To,pImageData,pBi,DIB_RGB_COLORS);
    //Close the file and release the memory
    file.Close();
    delete pBi;
    delete pImageData;
    }
      

  3.   

    CView::OnPaint()会不会产生这样的情况呀?
      

  4.   

    可能没有吧,我所有的CDC、CPen、CBrush类都及时地放了。