Set HBITMAP and its parameters in one call
To avoid separate calls to SetWidth/Height/Size/Depth functions after calling SetHBITMAP() use newly implemented InitFromHBITMAP() function which allows to set HBITMAP together with its parameters in one call.
This commit is contained in:
@@ -1290,6 +1290,34 @@ void wxBitmap::SetMask(wxMask *mask)
|
||||
GetBitmapData()->SetMask(mask);
|
||||
}
|
||||
|
||||
bool wxBitmap::InitFromHBITMAP(WXHBITMAP bmp, int width, int height, int depth)
|
||||
{
|
||||
#if wxDEBUG_LEVEL >= 2
|
||||
if ( bmp != NULL )
|
||||
{
|
||||
BITMAP bm;
|
||||
if ( ::GetObject(bmp, sizeof(bm), &bm) == sizeof(bm) )
|
||||
{
|
||||
wxASSERT_MSG(bm.bmWidth == width && bm.bmHeight == height && bm.bmBitsPixel == depth,
|
||||
wxS("Inconsistent bitmap parameters"));
|
||||
}
|
||||
else
|
||||
{
|
||||
wxFAIL_MSG(wxS("Cannot retrieve parameters of the bitmap"));
|
||||
}
|
||||
}
|
||||
#endif // wxDEBUG_LEVEL >= 2
|
||||
|
||||
AllocExclusive();
|
||||
|
||||
GetBitmapData()->m_handle = (WXHANDLE)bmp;
|
||||
GetBitmapData()->m_width = width;
|
||||
GetBitmapData()->m_height = height;
|
||||
GetBitmapData()->m_depth = depth;
|
||||
|
||||
return IsOk();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// raw bitmap access support
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -1620,9 +1648,7 @@ wxBitmap wxMask::GetBitmap() const
|
||||
|
||||
// Create and return a new wxBitmap.
|
||||
wxBitmap bmp;
|
||||
bmp.SetHBITMAP((WXHBITMAP)hNewBitmap);
|
||||
bmp.SetSize(bm.bmWidth, bm.bmHeight);
|
||||
bmp.SetDepth(bm.bmBitsPixel);
|
||||
bmp.InitFromHBITMAP((WXHBITMAP)hNewBitmap, bm.bmWidth, bm.bmHeight, bm.bmBitsPixel);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
Reference in New Issue
Block a user