Link to home
Start Free TrialLog in
Avatar of JiriNovotny
JiriNovotny

asked on

Working with 32BPP DIBSection using HDC regardless of display settings

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.
Avatar of marcodalzotto
marcodalzotto
Flag of Italy image

Do you have a surce code to work on?
Avatar of JiriNovotny
JiriNovotny

ASKER

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.
Is it really so hard that nobody knows?
ASKER CERTIFIED SOLUTION
Avatar of marcodalzotto
marcodalzotto
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial