]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/dc.cpp
If zero time is specified, don't try to sleep when using a timer.
[wxWidgets.git] / src / msw / dc.cpp
index 8a05efa95c76f6b68e7d0206eff9e4e6c8ea2ba5..63eadae25369f269c5436476baf88eb52017c971 100644 (file)
@@ -43,6 +43,7 @@
 #include "wx/sysopt.h"
 #include "wx/dcprint.h"
 #include "wx/module.h"
+#include "wx/dynload.h"
 
 #include <string.h>
 #include <math.h>
@@ -272,10 +273,12 @@ void wxDC::SelectOldObjects(WXHDC dc)
         if (m_oldBitmap)
         {
             ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap);
+#ifdef __WXDEBUG__
             if (m_selectedBitmap.Ok())
             {
                 m_selectedBitmap.SetSelectedInto(NULL);
             }
+#endif
         }
         m_oldBitmap = 0;
         if (m_oldPen)
@@ -939,6 +942,65 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
     HPALETTE oldPal = 0;
 #endif // wxUSE_PALETTE
 
+    // do we have AlphaBlend() and company in the headers?
+#ifdef AC_SRC_OVER
+    if ( bmp.HasAlpha() )
+    {
+        // yes, now try to see if we have it during run-time
+
+        typedef BOOL (WINAPI *AlphaBlend_t)(HDC,int,int,int,int,
+                                            HDC,int,int,int,int,
+                                            BLENDFUNCTION);
+
+        // bitmaps can be drawn only from GUI thread so there is no need to
+        // protect this static variable from multiple threads
+        static bool s_triedToLoad = FALSE;
+        static AlphaBlend_t pfnAlphaBlend = NULL;
+        if ( !s_triedToLoad )
+        {
+            s_triedToLoad = TRUE;
+
+            wxDynamicLibrary dll(_T("msimg32.dll"));
+            if ( dll.IsLoaded() )
+            {
+                pfnAlphaBlend = (AlphaBlend_t)dll.GetSymbol(_T("AlphaBlend"));
+                if ( pfnAlphaBlend )
+                {
+                    // we must keep the DLL loaded if we want to be able to
+                    // call AlphaBlend() so just never unload it at all
+                    dll.Detach();
+                }
+            }
+        }
+
+        if ( pfnAlphaBlend )
+        {
+            MemoryHDC hdcMem;
+            SelectInHDC select(hdcMem, GetHbitmapOf(bmp));
+
+#ifndef AC_SRC_ALPHA
+    #define AC_SRC_ALPHA 1
+#endif
+
+            BLENDFUNCTION bf;
+            bf.BlendOp = AC_SRC_OVER;
+            bf.BlendFlags = 0;
+            bf.SourceConstantAlpha = 0xff;
+            bf.AlphaFormat = AC_SRC_ALPHA;
+
+            if ( !pfnAlphaBlend(GetHdc(), x, y, width, height,
+                                hdcMem, 0, 0, width, height,
+                                bf) )
+            {
+                wxLogLastError(_T("AlphaBlend"));
+            }
+
+            return;
+        }
+        //else: AlphaBlend() not available
+    }
+#endif // defined(AC_SRC_OVER)
+
     if ( useMask )
     {
         wxMask *mask = bmp.GetMask();