| |

VerySource

 Forgot password?
 Register
Search
View: 523|Reply: 2

Novice questions, I hope everyone can help, I debugged for several days and succeeded but no results

[Copy link]

3

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-6 05:40:01
| Show all posts |Read mode
This is the constructor in the CDib class

CDib :: CDib (char * dibFileName)
{
    size = 0;
strcpy (m_fileName, dibFileName);
    LoadFile (m_fileName);
}
 


This is the loading function in the CDib class


void CDib :: LoadFile (const char * dibFileName)
{strcpy (m_fileName, dibFileName);
    CFile dibFile;
    dibFile.Open (m_fileName, CFile :: modeRead | CFile :: typeBinary);
    dibFile.Read ((void *)&bitmapFileHeader, sizeof (BITMAPFILEHEADER)); // This is point C. After debugging, it returns to void CBmp2View :: OnDraw (CDC * pDC) will not execute
    if (bitmapFileHeader.bfType == 0x4d42)
    {
        DWORD fileLength = dibFile.GetLength ();
size = fileLength -sizeof (BITMAPFILEHEADER);
pDib = (BYTE *) GlobalAllocPtr (GMEM_MOVEABLE, size);
        dibFile.Read ((void *) pDib, size);
        dibFile.Close ();
        m_pBitmapInfo = (BITMAPINFO *) pDib;
        m_pBitmapInfoHeader = (BITMAPINFOHEADER *) pDib;
        m_pRGB = (RGBQUAD *) (pDib + m_pBitmapInfoHeader-> biSize);
        int m_numberOfColors = GetNumberOfColors ();
        if (m_pBitmapInfoHeader-> biClrUsed == 0)
            m_pBitmapInfoHeader-> biClrUsed = m_numberOfColors;
        DWORD colorTableSize = m_numberOfColors * sizeof (RGBQUAD);
        m_pData = pDib + m_pBitmapInfoHeader-> biSize + colorTableSize;
if (m_pRGB == (RGBQUAD *) m_pData) m_pRGB = NULL;
        m_pBitmapInfoHeader-> biSizeImage = GetSize ();
m_valid = true;
    }
    else
    {
        m_valid = false;
        AfxMessageBox ("This isn't a bitmap file!");
    }
}

This is the function that I want to display in the CView class
void CBmp2View :: OnDraw (CDC * pDC) // here is point A
{
CBmp2Doc * pDoc = GetDocument ();
ASSERT_VALID (pDoc);
// TODO: add draw code for native data here
CDib cdib ("c:\try.bmp"); // This is point B, and jump back to A
BYTE * pBitmapData = cdib.GetData ();
LPBITMAPINFO pBitmapInfo = cdib.GetInfo ();
    pDC = GetDC ();
:: StretchDIBits (pDC-> GetSafeHdc (),
0,0,500,500,
0,0,500,500,
pBitmapData, pBitmapInfo, DIB_RGB_COLORS, SRCCOPY);
}

Compile can build EXE, but the image will not be displayed
After debugging, it is found that it always moves between points A and B. Among them, the CDib cdib ("c:\try.bmp") function at point B does not jump out and return to point A.
Reply

Use magic Report

0

Threads

25

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-1-6 17:45:01
| Show all posts
Put
CDib cdib ("c:\try.bmp"); // This is point B, and jump back to A
Move to the constructor of CBmp2View or OnInitialUpdate () and try.
Reply

Use magic Report

3

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 United States

 Author| Post time: 2020-1-10 15:36:01
| Show all posts
Thanks, but still not.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list