- // Ensure that static items get messages. Some controls don't like this
- // message to be intercepted (e.g. RichEdit), hence the tests.
- if (nMsg == WM_NCHITTEST)
- return (long)HTCLIENT;
+ Free();
+ InvalidateBestSize();
+
+ m_isIcon = image->IsKindOf( wxCLASSINFO(wxIcon) );
+ // the image has already been copied
+ m_image = image;
+
+ int x, y;
+ int w, h;
+ GetPosition(&x, &y);
+ GetSize(&w, &h);
+
+#ifdef __WIN32__
+ HANDLE handle = (HANDLE)m_image->GetHandle();
+ LONG style = ::GetWindowLong( (HWND)GetHWND(), GWL_STYLE ) ;
+ ::SetWindowLong( (HWND)GetHWND(), GWL_STYLE, ( style & ~( SS_BITMAP|SS_ICON ) ) |
+ ( m_isIcon ? SS_ICON : SS_BITMAP ) );
+ HGDIOBJ oldHandle = (HGDIOBJ)::SendMessage(GetHwnd(), STM_SETIMAGE,
+ m_isIcon ? IMAGE_ICON : IMAGE_BITMAP, (LPARAM)handle);
+ // detect if this is still the handle we passed before or
+ // if the static-control made a copy of the bitmap!
+ if (m_currentHandle != 0 && oldHandle != (HGDIOBJ) m_currentHandle)
+ {
+ // the static control made a copy and we are responsible for deleting it
+ DeleteObject((HGDIOBJ) oldHandle);
+ }
+ m_currentHandle = (WXHANDLE)handle;
+#endif // Win32
+
+ if ( ImageIsOk() )
+ {
+ int width = image->GetWidth(),
+ height = image->GetHeight();
+ if ( width && height )
+ {
+ w = width;
+ h = height;
+
+ ::MoveWindow(GetHwnd(), x, y, width, height, FALSE);
+ }
+ }