We help IT Professionals succeed at work.

Working with 32BPP DIBSection using HDC regardless of display settings

511 Views
Last Modified: 2013-12-03
Hello,

I have a DIB section, and I want to use standard GDI functions like LineTo, BitBlt, AlphaBlend etc. to work with it. Hovewer, I don't want to be dependent on current display settings. I would like to create DC not compatible with any device, but with memory, so I can use the full power of 32BPP bitmaps, when user has for example 256 color display mode. How to do that?

VC++ 6.0 (MFC Dialog App), SP6, PSDK Feb 2003, WinXP

Thanks.
Comment
Watch Question

Do you have a surce code to work on?

Author

Commented:
Sure, here is the DIB section creation:

BITMAPINFO m_tBI;
HDC        m_hDC;
HBITMAP    m_hDIB;
DWORD     *m_pData;
HBITMAP    m_hOldBmp;
......

        // Create device context
        m_hDC = CreateCompatibleDC(NULL);
        if(m_hDC != NULL)
        {
            // Init struct
            ZeroMemory(&m_tBI, sizeof(m_tBI));
            m_tBI.bmiHeader.biSize = sizeof(m_tBI.bmiHeader);
            m_tBI.bmiHeader.biPlanes = 1;
            m_tBI.bmiHeader.biBitCount = 32;
            m_tBI.bmiHeader.biCompression = BI_RGB;
            m_tBI.bmiHeader.biWidth = dwWidth;
            m_tBI.bmiHeader.biHeight = dwHeight;
            m_tBI.bmiHeader.biSizeImage = dwWidth * dwHeight * 4;

            // Create DIB section
            m_hDIB = CreateDIBSection(m_hDC, &m_tBI, DIB_RGB_COLORS, (LPVOID*)&m_pData, 0, 0);
            if(m_hDIB != NULL)
            {
                // Select DIB into device context
                m_hOldBmp = (HBITMAP)SelectObject(m_hDC, m_hDIB);
                // Guarantee that GDI has completed any drawing to a bitmap
                GdiFlush();
                // Save sizes
                m_dwWidth = dwWidth;
                m_dwHeight = dwHeight;
                // Validate image
                m_bValid = TRUE;
                // Return success
                return TRUE;
            }
            // Error, so clean up
            DeleteDC(m_hDC);
        }

As you can see, I'm using current display DC. Hovewer, I want to not use such a DC, but 'memory' DC. I'm sure you understand.

Author

Commented:
Is it really so hard that nobody knows?
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.