+
+ // windows in TreeCtrl use one-based index for item state images,
+ // 0 indexed image is not being used, we're using zero-based index,
+ // so we have to add temp image (of zero index) to state image list
+ // before we draw any item, then after items are drawn we have to
+ // delete it (in POSTPAINT notify)
+ if (m_imageListState && m_imageListState->GetImageCount() > 0)
+ {
+ typedef BOOL (*ImageList_Copy_t)
+ (HIMAGELIST, int, HIMAGELIST, int, UINT);
+ static ImageList_Copy_t s_pfnImageList_Copy = NULL;
+ static bool loaded = false;
+
+ if ( !loaded )
+ {
+ wxLoadedDLL dllComCtl32(_T("comctl32.dll"));
+ if ( dllComCtl32.IsLoaded() )
+ wxDL_INIT_FUNC(s_pfn, ImageList_Copy, dllComCtl32);
+ }
+
+ if ( !s_pfnImageList_Copy )
+ {
+ // this code is broken with ImageList_Copy()
+ // but I don't care enough about Win95 support
+ // to write it now -- if anybody does, please
+ // do it
+ wxFAIL_MSG("TODO: implement this for Win95");
+ break;
+ }
+
+ const HIMAGELIST
+ hImageList = GetHimagelistOf(m_imageListState);
+
+ // add temporary image
+ int width, height;
+ m_imageListState->GetSize(0, width, height);
+
+ HBITMAP hbmpTemp = ::CreateBitmap(width, height, 1, 1, NULL);
+ int index = ::ImageList_Add(hImageList, hbmpTemp, hbmpTemp);
+ ::DeleteObject(hbmpTemp);
+
+ if ( index != -1 )
+ {
+ // move images to right
+ for ( int i = index; i > 0; i-- )
+ {
+ (*s_pfnImageList_Copy)(hImageList, i,
+ hImageList, i-1,
+ ILCF_MOVE);
+ }
+
+ // we must remove the image in POSTPAINT notify
+ *result |= CDRF_NOTIFYPOSTPAINT;
+ }
+ }
+ break;
+
+ case CDDS_POSTPAINT:
+ // we are deleting temp image of 0 index, which was
+ // added before items were drawn (in PREPAINT notify)
+ if (m_imageListState && m_imageListState->GetImageCount() > 0)
+ m_imageListState->Remove(0);