Click here to Skip to main content
16,012,223 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Help with VC++... Pin
projectip30-Jun-08 19:00
projectip30-Jun-08 19:00 
AnswerRe: Help with VC++... Pin
_AnsHUMAN_ 30-Jun-08 19:04
_AnsHUMAN_ 30-Jun-08 19:04 
GeneralRe: Help with VC++... Pin
projectip30-Jun-08 19:08
projectip30-Jun-08 19:08 
GeneralRe: Help with VC++... Pin
_AnsHUMAN_ 30-Jun-08 19:10
_AnsHUMAN_ 30-Jun-08 19:10 
GeneralRe: Help with VC++... Pin
projectip30-Jun-08 19:37
projectip30-Jun-08 19:37 
GeneralRe: Help with VC++... Pin
theCPkid30-Jun-08 19:11
theCPkid30-Jun-08 19:11 
GeneralRe: Help with VC++... Pin
projectip30-Jun-08 19:54
projectip30-Jun-08 19:54 
GeneralRe: Help with VC++... Pin
projectip30-Jun-08 19:55
projectip30-Jun-08 19:55 
I get a warning
conversion from 'unsigned long' to 'unsigned char', possible loss of data<br />
when i give BYTE *pLeftBits = new BYTE(BitmapInfoLeft.bmiHeader.biSizeImage);
the entire code is..
bool CMydlgtestDlg::CompareBitmaps(HBITMAP HBitmapLeft, HBITMAP HBitmapRight)
{
    if (HBitmapLeft == HBitmapRight)
    {
        return true;
    }

    if (NULL == HBitmapLeft || NULL == HBitmapRight)
    {
        return false;
    }

    bool bSame = false;
	
	CDC *pDC = GetDC();
	HDC hdc = pDC->GetSafeHdc();

   // HDC hdc = GetDC();
    BITMAPINFO BitmapInfoLeft = {0};
    BITMAPINFO BitmapInfoRight = {0};

    BitmapInfoLeft.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    BitmapInfoRight.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);

    if (0 != GetDIBits(hdc, HBitmapLeft, 0, 0, NULL, &BitmapInfoLeft, DIB_RGB_COLORS) &&
        0 != GetDIBits(hdc, HBitmapRight, 0, 0, NULL, &BitmapInfoRight, DIB_RGB_COLORS))
    {
        // Compare the BITMAPINFOHEADERs of the two bitmaps

        if (0 == memcmp(&BitmapInfoLeft.bmiHeader, &BitmapInfoRight.bmiHeader, 
            sizeof(BITMAPINFOHEADER)))
        {
            // The BITMAPINFOHEADERs are the same so now compare the actual bitmap bits

            BYTE *pLeftBits = new BYTE(BitmapInfoLeft.bmiHeader.biSizeImage);
            BYTE *pRightBits = new BYTE(BitmapInfoRight.bmiHeader.biSizeImage);
            BYTE *pByteLeft = NULL;
            BYTE *pByteRight = NULL;

            PBITMAPINFO pBitmapInfoLeft = &BitmapInfoLeft;
            PBITMAPINFO pBitmapInfoRight = &BitmapInfoRight;

            // calculate the size in BYTEs of the additional

            // memory needed for the bmiColor table

            int AdditionalMemory = 0;
            switch (BitmapInfoLeft.bmiHeader.biBitCount)
            {
            case 1:
                AdditionalMemory = 1 * sizeof(RGBQUAD);
                break;
            case 4:
                AdditionalMemory = 15 * sizeof(RGBQUAD);
                break;
            case 8:
                AdditionalMemory = 255 * sizeof(RGBQUAD);
                break;
            case 16:
            case 32:
                AdditionalMemory = 2 * sizeof(RGBQUAD);
            }

            if (AdditionalMemory)
            {
                // we have to allocate room for the bmiColor table that will be

                // attached to our BITMAPINFO variables

                pByteLeft = new BYTE[sizeof(BITMAPINFO) + AdditionalMemory];
                if (pByteLeft)
                {
                    memset(pByteLeft, 0, sizeof(BITMAPINFO) + AdditionalMemory);
                    memcpy(pByteLeft, pBitmapInfoLeft, sizeof(BITMAPINFO));
                    pBitmapInfoLeft = (PBITMAPINFO)pByteLeft;
                }

                pByteRight = new BYTE[sizeof(BITMAPINFO) + AdditionalMemory];
                if (pByteRight)
                {
                    memset(pByteRight, 0, sizeof(BITMAPINFO) + AdditionalMemory);
                    memcpy(pByteRight, pBitmapInfoRight, sizeof(BITMAPINFO));
                    pBitmapInfoRight = (PBITMAPINFO)pByteRight;
                }
            }

            if (pLeftBits && pRightBits && pBitmapInfoLeft && pBitmapInfoRight)
            {
                // zero out the bitmap bit buffers

                memset(pLeftBits, 0, BitmapInfoLeft.bmiHeader.biSizeImage);
                memset(pRightBits, 0, BitmapInfoRight.bmiHeader.biSizeImage);

                // fill the bit buffers with the actual bitmap bits

                if (0 != GetDIBits(hdc, HBitmapLeft, 0, 
                    pBitmapInfoLeft->bmiHeader.biHeight, pLeftBits, pBitmapInfoLeft, 
                    DIB_RGB_COLORS) && 0 != GetDIBits(hdc, HBitmapRight, 0, 
                    pBitmapInfoRight->bmiHeader.biHeight, pRightBits, pBitmapInfoRight, 
                    DIB_RGB_COLORS))
                {
                    // compare the actual bitmap bits of the two bitmaps

                    bSame = 0 == memcmp(pLeftBits, pRightBits,pBitmapInfoLeft->bmiHeader.biSizeImage);
                }
            }

            // clean up

            delete[] pLeftBits;
            delete[] pRightBits;
            delete[] pByteLeft;
            delete[] pByteRight;
        }
    }

    //ReleaseDC(NULL, hdc);
	ReleaseDC(pDC); 

    return bSame;
}

QuestionMFC App Wizard generated SDI application crashes. Pin
Saurabh.Garg30-Jun-08 17:54
Saurabh.Garg30-Jun-08 17:54 
GeneralRe: MFC App Wizard generated SDI application crashes. Pin
theCPkid30-Jun-08 18:50
theCPkid30-Jun-08 18:50 
GeneralRe: MFC App Wizard generated SDI application crashes. Pin
Saurabh.Garg30-Jun-08 19:01
Saurabh.Garg30-Jun-08 19:01 
QuestionCoInitializeEx and MTA Pin
George_George30-Jun-08 17:09
George_George30-Jun-08 17:09 
AnswerRe: CoInitializeEx and MTA Pin
Hamid_RT30-Jun-08 20:52
Hamid_RT30-Jun-08 20:52 
GeneralRe: CoInitializeEx and MTA Pin
George_George30-Jun-08 21:21
George_George30-Jun-08 21:21 
QuestionMonitor thread status Pin
George_George30-Jun-08 16:51
George_George30-Jun-08 16:51 
AnswerRe: Monitor thread status Pin
kcynic30-Jun-08 17:34
kcynic30-Jun-08 17:34 
GeneralRe: Monitor thread status Pin
George_George30-Jun-08 17:55
George_George30-Jun-08 17:55 
GeneralRe: Monitor thread status Pin
kcynic30-Jun-08 18:15
kcynic30-Jun-08 18:15 
GeneralRe: Monitor thread status Pin
George_George30-Jun-08 18:46
George_George30-Jun-08 18:46 
GeneralRe: Monitor thread status Pin
kcynic30-Jun-08 19:23
kcynic30-Jun-08 19:23 
GeneralRe: Monitor thread status Pin
George_George30-Jun-08 19:38
George_George30-Jun-08 19:38 
AnswerRe: Monitor thread status Pin
Hamid_RT30-Jun-08 20:30
Hamid_RT30-Jun-08 20:30 
GeneralRe: Monitor thread status Pin
George_George30-Jun-08 20:42
George_George30-Jun-08 20:42 
GeneralRe: Monitor thread status Pin
toxcct30-Jun-08 20:44
toxcct30-Jun-08 20:44 
GeneralRe: Monitor thread status Pin
George_George30-Jun-08 20:59
George_George30-Jun-08 20:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.