Changeset 861


Ignore:
Timestamp:
01/06/09 07:55:31 (6 years ago)
Author:
lowjoel
Message:

Fixed 32-bit bitmaps for Vista. Somehow my DDB to DIB conversion lost the alpha channel. Using BeginBufferedPaint? should solve it, but my old method is still around as a fallback.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/ShellExt/CtxMenu.cpp

    r851 r861  
    285285                osvi.dwMajorVersion >= 6) 
    286286            { 
    287                 mii.fMask |= MIIM_CHECKMARKS; 
    288                 mii.hbmpUnchecked = GetMenuBitmap(); 
     287                mii.fMask |= MIIM_BITMAP; 
     288                mii.hbmpItem = GetMenuBitmap(); 
    289289            } 
    290290            else if (InvokeReason != INVOKEREASON_DRAGDROP) 
     
    780780        int smIconSize = GetSystemMetrics(SM_CXMENUCHECK); 
    781781        return static_cast<HICON>(LoadImage(theApp.m_hInstance, L"Eraser", 
    782             IMAGE_ICON, smIconSize, smIconSize, LR_LOADTRANSPARENT)); 
     782            IMAGE_ICON, smIconSize, smIconSize, LR_DEFAULTCOLOR)); 
    783783    } 
    784784 
     
    802802 
    803803        //Try converting the DDB into a DIB. 
    804         DIBSECTION dibSection; 
     804        Handle<HDC> hdcDest = CreateCompatibleDC(NULL); 
    805805        HBITMAP dib = CreateDIB(bitmap.bmWidth, bitmap.bmHeight, NULL); 
    806         if (!GetObject(dib, sizeof(dibSection), &dibSection) || 
    807             !GetDIBits(CreateCompatibleDC(NULL), iconInfo.hbmColor, 0, bitmap.bmHeight, 
    808                 dibSection.dsBm.bmBits, reinterpret_cast<BITMAPINFO*>(&dibSection.dsBmih), 
    809                 DIB_RGB_COLORS)) 
    810         { 
    811             return iconInfo.hbmColor; 
     806        SelectObject(hdcDest, dib); 
     807 
     808        typedef HRESULT (__stdcall *pBufferedPaintInit)(void); 
     809        static HMODULE uxTheme = LoadLibrary(L"UxTheme.dll"); 
     810        static pBufferedPaintInit BufferedPaintInit = 
     811            reinterpret_cast<pBufferedPaintInit>(GetProcAddress(uxTheme, "BufferedPaintInit")); 
     812        if (BufferedPaintInit) 
     813        { 
     814            typedef HPAINTBUFFER (_stdcall *pBeginBufferedPaint)(HDC hdcTarget, const RECT* prcTarget, 
     815                BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS* pPaintParams, HDC* phdc); 
     816            typedef HRESULT (__stdcall *pEndBufferedPaint)(HPAINTBUFFER hBufferedPaint, 
     817                BOOL fUpdateTarget); 
     818            static pBeginBufferedPaint BeginBufferedPaint = 
     819                reinterpret_cast<pBeginBufferedPaint>(GetProcAddress(uxTheme, "BeginBufferedPaint")); 
     820            static pEndBufferedPaint EndBufferedPaint = 
     821                reinterpret_cast<pEndBufferedPaint>(GetProcAddress(uxTheme, "EndBufferedPaint")); 
     822 
     823            BLENDFUNCTION blendFunc = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; 
     824            BP_PAINTPARAMS paintParams; 
     825            paintParams.cbSize = sizeof(paintParams); 
     826            paintParams.dwFlags = BPPF_ERASE; 
     827            paintParams.prcExclude = NULL; 
     828            paintParams.pBlendFunction = &blendFunc; 
     829 
     830            HDC hdcBuffer; 
     831            RECT iconRect = { 0, 0, bitmap.bmWidth, bitmap.bmHeight }; 
     832            HPAINTBUFFER hPaintBuffer = BeginBufferedPaint(hdcDest, &iconRect, BPBF_DIB, 
     833                &paintParams, &hdcBuffer); 
     834 
     835            if (hPaintBuffer) 
     836            { 
     837                DrawIconEx(hdcBuffer, 0, 0, icon, bitmap.bmWidth, bitmap.bmHeight, 0, 
     838                    NULL, DI_NORMAL); 
     839                EndBufferedPaint(hPaintBuffer, TRUE); 
     840            } 
     841        } 
     842        else 
     843        { 
     844            DIBSECTION dibSection; 
     845            if (!GetObject(dib, sizeof(dibSection), &dibSection)) 
     846                return iconInfo.hbmColor; 
     847            if (!GetDIBits(hdcDest, iconInfo.hbmColor, 0, bitmap.bmHeight, 
     848                    dibSection.dsBm.bmBits, reinterpret_cast<BITMAPINFO*>(&dibSection.dsBmih), 
     849                    DIB_RGB_COLORS)) 
     850                return iconInfo.hbmColor; 
    812851        } 
    813852 
     
    824863        info.bmiHeader.biPlanes = 1; 
    825864        info.bmiHeader.biBitCount = 32; 
    826         info.bmiHeader.biCompression = BI_RGB; 
    827         char* dibBitmapBits = NULL; 
    828         return ::CreateDIBSection(0, &info, DIB_RGB_COLORS, 
    829             reinterpret_cast<void**>(bitmapBits ? bitmapBits : &dibBitmapBits), NULL, 0); 
     865 
     866        Handle<HDC> screenDC(GetDC(NULL)); 
     867        return ::CreateDIBSection(screenDC, &info, DIB_RGB_COLORS, 
     868            reinterpret_cast<void**>(bitmapBits), NULL, 0); 
    830869    } 
    831870} 
Note: See TracChangeset for help on using the changeset viewer.