fixed incorrect calls to SelectObject(hdc, NULL)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13379 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -90,7 +90,7 @@ void wxBitmapRefData::Free()
|
|||||||
|
|
||||||
if ( m_hBitmap)
|
if ( m_hBitmap)
|
||||||
{
|
{
|
||||||
// printf("About to delete bitmap %d\n", (int) (HBITMAP) m_hBitmap);
|
// printf("About to delete bitmap %d\n", (int) (HBITMAP) m_hBitmap);
|
||||||
#if 1
|
#if 1
|
||||||
if ( !::DeleteObject((HBITMAP)m_hBitmap) )
|
if ( !::DeleteObject((HBITMAP)m_hBitmap) )
|
||||||
{
|
{
|
||||||
@@ -395,7 +395,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
// Initial attempt at a simple-minded implementation.
|
// Initial attempt at a simple-minded implementation.
|
||||||
// The bitmap will always be created at the screen depth,
|
// The bitmap will always be created at the screen depth,
|
||||||
// so the 'depth' argument is ignored.
|
// so the 'depth' argument is ignored.
|
||||||
|
|
||||||
HDC hScreenDC = ::GetDC(NULL);
|
HDC hScreenDC = ::GetDC(NULL);
|
||||||
// printf("Screen planes = %d, bpp = %d\n", hScreenDC->psd->planes, hScreenDC->psd->bpp);
|
// printf("Screen planes = %d, bpp = %d\n", hScreenDC->psd->planes, hScreenDC->psd->bpp);
|
||||||
int screenDepth = ::GetDeviceCaps(hScreenDC, BITSPIXEL);
|
int screenDepth = ::GetDeviceCaps(hScreenDC, BITSPIXEL);
|
||||||
@@ -412,7 +412,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
if (hBitmap == NULL)
|
if (hBitmap == NULL)
|
||||||
{
|
{
|
||||||
::ReleaseDC(NULL, hScreenDC);
|
::ReleaseDC(NULL, hScreenDC);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
HDC hMemDC = ::CreateCompatibleDC(hScreenDC);
|
HDC hMemDC = ::CreateCompatibleDC(hScreenDC);
|
||||||
|
|
||||||
@@ -439,7 +439,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
if (!hMaskBitmap)
|
if (!hMaskBitmap)
|
||||||
{
|
{
|
||||||
hasMask = FALSE;
|
hasMask = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hScreenDC = ::GetDC(NULL);
|
hScreenDC = ::GetDC(NULL);
|
||||||
@@ -447,7 +447,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
::ReleaseDC(NULL, hScreenDC);
|
::ReleaseDC(NULL, hScreenDC);
|
||||||
|
|
||||||
hOldMaskBitmap = ::SelectObject( hMaskDC, hMaskBitmap);
|
hOldMaskBitmap = ::SelectObject( hMaskDC, hMaskBitmap);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
hasMask = FALSE;
|
hasMask = FALSE;
|
||||||
#endif
|
#endif
|
||||||
@@ -456,13 +456,13 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
int i, j;
|
int i, j;
|
||||||
for (i = 0; i < image.GetWidth(); i++)
|
for (i = 0; i < image.GetWidth(); i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < image.GetHeight(); j++)
|
for (j = 0; j < image.GetHeight(); j++)
|
||||||
{
|
{
|
||||||
unsigned char red = image.GetRed(i, j);
|
unsigned char red = image.GetRed(i, j);
|
||||||
unsigned char green = image.GetGreen(i, j);
|
unsigned char green = image.GetGreen(i, j);
|
||||||
unsigned char blue = image.GetBlue(i, j);
|
unsigned char blue = image.GetBlue(i, j);
|
||||||
|
|
||||||
::SetPixel(hMemDC, i, j, PALETTERGB(red, green, blue));
|
::SetPixel(hMemDC, i, j, PALETTERGB(red, green, blue));
|
||||||
|
|
||||||
if (hasMask)
|
if (hasMask)
|
||||||
{
|
{
|
||||||
@@ -472,8 +472,8 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
::SetPixel(hMaskDC, i, j, PALETTERGB(0, 0, 0));
|
::SetPixel(hMaskDC, i, j, PALETTERGB(0, 0, 0));
|
||||||
else
|
else
|
||||||
::SetPixel(hMaskDC, i, j, PALETTERGB(255, 255, 255));
|
::SetPixel(hMaskDC, i, j, PALETTERGB(255, 255, 255));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
::SelectObject(hMemDC, hOldBitmap);
|
::SelectObject(hMemDC, hOldBitmap);
|
||||||
@@ -481,16 +481,16 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
|
|||||||
if (hasMask)
|
if (hasMask)
|
||||||
{
|
{
|
||||||
::SelectObject(hMaskDC, hOldMaskBitmap);
|
::SelectObject(hMaskDC, hOldMaskBitmap);
|
||||||
::DeleteDC(hMaskDC);
|
::DeleteDC(hMaskDC);
|
||||||
|
|
||||||
((wxBitmapRefData*)m_refData)->m_bitmapMask = new wxMask((WXHBITMAP) hMaskBitmap);
|
((wxBitmapRefData*)m_refData)->m_bitmapMask = new wxMask((WXHBITMAP) hMaskBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetWidth(image.GetWidth());
|
SetWidth(image.GetWidth());
|
||||||
SetHeight(image.GetHeight());
|
SetHeight(image.GetHeight());
|
||||||
SetDepth(screenDepth);
|
SetDepth(screenDepth);
|
||||||
SetHBITMAP( (WXHBITMAP) hBitmap );
|
SetHBITMAP( (WXHBITMAP) hBitmap );
|
||||||
|
|
||||||
#if wxUSE_PALETTE
|
#if wxUSE_PALETTE
|
||||||
// Copy the palette from the source image
|
// Copy the palette from the source image
|
||||||
SetPalette(image.GetPalette());
|
SetPalette(image.GetPalette());
|
||||||
@@ -747,7 +747,7 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
if (!Ok())
|
if (!Ok())
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("bitmap is invalid") );
|
wxFAIL_MSG( wxT("bitmap is invalid") );
|
||||||
return wxNullImage;
|
return wxNullImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxImage image;
|
wxImage image;
|
||||||
@@ -764,33 +764,33 @@ wxImage wxBitmap::ConvertToImage() const
|
|||||||
wxFAIL_MSG( wxT("could not allocate data for image") );
|
wxFAIL_MSG( wxT("could not allocate data for image") );
|
||||||
return wxNullImage;
|
return wxNullImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
HDC hScreenDC = ::GetDC(NULL);
|
HDC hScreenDC = ::GetDC(NULL);
|
||||||
|
|
||||||
HDC hMemDC = ::CreateCompatibleDC(hScreenDC);
|
HDC hMemDC = ::CreateCompatibleDC(hScreenDC);
|
||||||
::ReleaseDC(NULL, hScreenDC);
|
::ReleaseDC(NULL, hScreenDC);
|
||||||
|
|
||||||
HBITMAP hBitmap = (HBITMAP) GetHBITMAP();
|
HBITMAP hBitmap = (HBITMAP) GetHBITMAP();
|
||||||
|
|
||||||
HBITMAP hOldBitmap = ::SelectObject(hMemDC, hBitmap);
|
HBITMAP hOldBitmap = ::SelectObject(hMemDC, hBitmap);
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
for (i = 0; i < GetWidth(); i++)
|
for (i = 0; i < GetWidth(); i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < GetHeight(); j++)
|
for (j = 0; j < GetHeight(); j++)
|
||||||
{
|
{
|
||||||
COLORREF color = ::GetPixel(hMemDC, i, j);
|
COLORREF color = ::GetPixel(hMemDC, i, j);
|
||||||
unsigned char red = GetRValue(color);
|
unsigned char red = GetRValue(color);
|
||||||
unsigned char green = GetGValue(color);
|
unsigned char green = GetGValue(color);
|
||||||
unsigned char blue = GetBValue(color);
|
unsigned char blue = GetBValue(color);
|
||||||
|
|
||||||
image.SetRGB(i, j, red, green, blue);
|
image.SetRGB(i, j, red, green, blue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
::SelectObject(hMemDC, hOldBitmap);
|
::SelectObject(hMemDC, hOldBitmap);
|
||||||
::DeleteDC(hMemDC);
|
::DeleteDC(hMemDC);
|
||||||
|
|
||||||
#if wxUSE_PALETTE
|
#if wxUSE_PALETTE
|
||||||
// Copy the palette from the source image
|
// Copy the palette from the source image
|
||||||
if (GetPalette())
|
if (GetPalette())
|
||||||
@@ -1007,7 +1007,6 @@ bool wxBitmap::SaveFile(const wxString& filename,
|
|||||||
|
|
||||||
wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
|
wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
|
||||||
{
|
{
|
||||||
#ifndef __WXMICROWIN__
|
|
||||||
wxCHECK_MSG( Ok() &&
|
wxCHECK_MSG( Ok() &&
|
||||||
(rect.x >= 0) && (rect.y >= 0) &&
|
(rect.x >= 0) && (rect.y >= 0) &&
|
||||||
(rect.x+rect.width <= GetWidth()) &&
|
(rect.x+rect.width <= GetWidth()) &&
|
||||||
@@ -1017,35 +1016,41 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
|
|||||||
wxBitmap ret( rect.width, rect.height, GetDepth() );
|
wxBitmap ret( rect.width, rect.height, GetDepth() );
|
||||||
wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
|
wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
|
||||||
|
|
||||||
|
#ifndef __WXMICROWIN__
|
||||||
// copy bitmap data
|
// copy bitmap data
|
||||||
HDC dcSrc = ::CreateCompatibleDC(NULL);
|
MemoryHDC dcSrc, dcDst;
|
||||||
HDC dcDst = ::CreateCompatibleDC(NULL);
|
|
||||||
SelectObject(dcSrc, (HBITMAP) GetHBITMAP());
|
{
|
||||||
SelectObject(dcDst, (HBITMAP) ret.GetHBITMAP());
|
SelectInHDC selectSrc(dcSrc, GetHbitmap()),
|
||||||
BitBlt(dcDst, 0, 0, rect.width, rect.height, dcSrc, rect.x, rect.y, SRCCOPY);
|
selectDst(dcDst, GetHbitmapOf(ret));
|
||||||
|
|
||||||
|
if ( !::BitBlt(dcDst, 0, 0, rect.width, rect.height,
|
||||||
|
dcSrc, rect.x, rect.y, SRCCOPY) )
|
||||||
|
{
|
||||||
|
wxLogLastError(_T("BitBlt"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// copy mask if there is one
|
// copy mask if there is one
|
||||||
if (GetMask())
|
if ( GetMask() )
|
||||||
{
|
{
|
||||||
HBITMAP hbmpMask = ::CreateBitmap(rect.width, rect.height, 1, 1, 0);
|
HBITMAP hbmpMask = ::CreateBitmap(rect.width, rect.height, 1, 1, 0);
|
||||||
|
|
||||||
SelectObject(dcSrc, (HBITMAP) GetMask()->GetMaskBitmap());
|
SelectInHDC selectSrc(dcSrc, (HBITMAP) GetMask()->GetMaskBitmap()),
|
||||||
SelectObject(dcDst, (HBITMAP) hbmpMask);
|
selectDst(dcDst, hbmpMask);
|
||||||
BitBlt(dcDst, 0, 0, rect.width, rect.height, dcSrc, rect.x, rect.y, SRCCOPY);
|
|
||||||
|
if ( !::BitBlt(dcDst, 0, 0, rect.width, rect.height,
|
||||||
|
dcSrc, rect.x, rect.y, SRCCOPY) )
|
||||||
|
{
|
||||||
|
wxLogLastError(_T("BitBlt"));
|
||||||
|
}
|
||||||
|
|
||||||
wxMask *mask = new wxMask((WXHBITMAP) hbmpMask);
|
wxMask *mask = new wxMask((WXHBITMAP) hbmpMask);
|
||||||
ret.SetMask(mask);
|
ret.SetMask(mask);
|
||||||
}
|
}
|
||||||
|
#endif // !__WXMICROWIN__
|
||||||
SelectObject(dcDst, NULL);
|
|
||||||
SelectObject(dcSrc, NULL);
|
|
||||||
DeleteDC(dcDst);
|
|
||||||
DeleteDC(dcSrc);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
#else
|
|
||||||
return wxBitmap();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -111,21 +111,20 @@ void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
|
|||||||
iconInfo.hbmMask = wxInvertMask((HBITMAP)mask->GetMaskBitmap());
|
iconInfo.hbmMask = wxInvertMask((HBITMAP)mask->GetMaskBitmap());
|
||||||
iconInfo.hbmColor = GetHbitmapOf(bmp);
|
iconInfo.hbmColor = GetHbitmapOf(bmp);
|
||||||
|
|
||||||
/* GRG: black out the transparent area to preserve background
|
// black out the transparent area to preserve background colour, because
|
||||||
* colour, because Windows blits the original bitmap using
|
// Windows blits the original bitmap using SRCINVERT (XOR) after applying
|
||||||
* SRCINVERT (XOR) after applying the mask to the dest rect.
|
// the mask to the dest rect.
|
||||||
*/
|
{
|
||||||
HDC dcSrc = ::CreateCompatibleDC(NULL);
|
MemoryHDC dcSrc, dcDst;
|
||||||
HDC dcDst = ::CreateCompatibleDC(NULL);
|
SelectInHDC selectMask(dcSrc, (HBITMAP)mask->GetMaskBitmap()),
|
||||||
SelectObject(dcSrc, (HBITMAP)mask->GetMaskBitmap());
|
selectBitmap(dcDst, iconInfo.hbmColor);
|
||||||
SelectObject(dcDst, iconInfo.hbmColor);
|
|
||||||
|
|
||||||
BitBlt(dcDst, 0, 0, bmp.GetWidth(), bmp.GetHeight(), dcSrc, 0, 0, SRCAND);
|
if ( !::BitBlt(dcDst, 0, 0, bmp.GetWidth(), bmp.GetHeight(),
|
||||||
|
dcSrc, 0, 0, SRCAND) )
|
||||||
SelectObject(dcDst, NULL);
|
{
|
||||||
SelectObject(dcSrc, NULL);
|
wxLogLastError(_T("BitBlt"));
|
||||||
DeleteDC(dcDst);
|
}
|
||||||
DeleteDC(dcSrc);
|
}
|
||||||
|
|
||||||
HICON hicon = ::CreateIconIndirect(&iconInfo);
|
HICON hicon = ::CreateIconIndirect(&iconInfo);
|
||||||
if ( !hicon )
|
if ( !hicon )
|
||||||
|
Reference in New Issue
Block a user