X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..3d7e30a4186cc3379c3b21040712181a3c6d0b3b:/src/msw/dcmemory.cpp diff --git a/src/msw/dcmemory.cpp b/src/msw/dcmemory.cpp index 1ff28ae283..51cefba945 100644 --- a/src/msw/dcmemory.cpp +++ b/src/msw/dcmemory.cpp @@ -10,7 +10,6 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation #pragma implementation "dcmemory.h" #endif @@ -41,6 +40,7 @@ wxMemoryDC::wxMemoryDC(void) { m_hDC = (WXHDC) ::CreateCompatibleDC(NULL); m_ok = (m_hDC != 0); + m_bOwnsDC = TRUE; SetBrush(*wxWHITE_BRUSH); SetPen(*wxBLACK_PEN); @@ -83,17 +83,25 @@ void wxMemoryDC::SelectObject(const wxBitmap& bitmap) wxFatalError("Error in wxMemoryDC::SelectObject\nBitmap is selected in another wxMemoryDC.\nDelete the first wxMemoryDC or use SelectObject(NULL)"); return; } - - m_selectedBitmap = bitmap; + + // Check if the bitmap has the correct depth for this device context + if (bitmap.Ok() && (bitmap.GetDepth() != GetDepth())) + { + // Make a new bitmap that has the correct depth. + wxBitmap newBitmap = bitmap.GetBitmapForDC(* this); + + m_selectedBitmap = newBitmap ; + } + else + { + m_selectedBitmap = bitmap; + } if (!m_selectedBitmap.Ok()) return; m_selectedBitmap.SetSelectedInto(this); -#if DEBUG > 1 - wxDebugMsg("wxMemoryDC::SelectObject: Selecting HBITMAP %X\n", m_selectedBitmap.GetHBITMAP()); -#endif - HBITMAP bm = ::SelectObject((HDC) m_hDC, (HBITMAP) m_selectedBitmap.GetHBITMAP()); + HBITMAP bm = (HBITMAP) ::SelectObject((HDC) m_hDC, (HBITMAP) m_selectedBitmap.GetHBITMAP()); if (bm == ERROR) {