250
253
SetImageNoCopy( convertedImage );
256
void wxStaticBitmap::MSWReplaceImageHandle(WXLPARAM handle)
258
HGDIOBJ oldHandle = (HGDIOBJ)::SendMessage(GetHwnd(), STM_SETIMAGE,
259
m_isIcon ? IMAGE_ICON : IMAGE_BITMAP, (LPARAM)handle);
260
// detect if this is still the handle we passed before or
261
// if the static-control made a copy of the bitmap!
262
if (oldHandle != 0 && oldHandle != (HGDIOBJ) m_currentHandle)
264
// the static control made a copy and we are responsible for deleting it
265
::DeleteObject((HGDIOBJ) oldHandle);
253
269
void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image)
268
284
HANDLE handle = (HANDLE)m_image->GetHandle();
286
AutoHBITMAP hbmpRelease;
289
// wxBitmap normally stores alpha in pre-multiplied format but
290
// apparently STM_SETIMAGE message handler does pre-multiplication
291
// internally so we need to undo the pre-multiplication here for a
292
// while (this is similar to what we do in ImageList::Add()).
293
const wxBitmap& bmp = static_cast<wxBitmap&>(*image);
294
if ( bmp.HasAlpha() )
296
// For bitmap with alpha channel create temporary DIB with
297
// not-premultiplied alpha values.
298
handle = wxDIB(bmp.ConvertToImage(),
299
wxDIB::PixelFormat_NotPreMultiplied).Detach();
301
// Ensure that this temporary HBITMAP will be destroyed.
302
hbmpRelease.Init((HBITMAP)handle);
269
305
LONG style = ::GetWindowLong( (HWND)GetHWND(), GWL_STYLE ) ;
270
306
::SetWindowLong( (HWND)GetHWND(), GWL_STYLE, ( style & ~( SS_BITMAP|SS_ICON ) ) |
271
307
( m_isIcon ? SS_ICON : SS_BITMAP ) );
272
HGDIOBJ oldHandle = (HGDIOBJ)::SendMessage(GetHwnd(), STM_SETIMAGE,
273
m_isIcon ? IMAGE_ICON : IMAGE_BITMAP, (LPARAM)handle);
274
// detect if this is still the handle we passed before or
275
// if the static-control made a copy of the bitmap!
276
if (m_currentHandle != 0 && oldHandle != (HGDIOBJ) m_currentHandle)
278
// the static control made a copy and we are responsible for deleting it
279
DeleteObject((HGDIOBJ) oldHandle);
281
m_currentHandle = (WXHANDLE)handle;
309
MSWReplaceImageHandle((WXLPARAM)handle);
311
// Save bitmap handle only if it's not a temporary one, otherwise it's
312
// going to be destroyed right now anyhow.
314
m_currentHandle = (WXHANDLE)handle;
284
318
if ( ImageIsOk() )