- int existingExtent = (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT, 0, 0L);
- HDC dc = GetWindowDC(GetHwnd());
- HFONT oldFont = 0;
- if (GetFont().Ok() && GetFont().GetResourceHandle())
- oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle());
-
- GetTextMetrics(dc, &lpTextMetric);
- SIZE extentXY;
- ::GetTextExtentPoint(dc, (LPTSTR) (const wxChar *)s, s.Length(), &extentXY);
- int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);
-
- if (oldFont)
- ::SelectObject(dc, oldFont);
-
- ReleaseDC(GetHwnd(), dc);
- if (extentX > existingExtent)
- SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(extentX), 0L);
- return;
- }
- else
- {
- int largestExtent = 0;
- HDC dc = GetWindowDC(GetHwnd());
- HFONT oldFont = 0;
- if (GetFont().Ok() && GetFont().GetResourceHandle())
- oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle());
-
- GetTextMetrics(dc, &lpTextMetric);
- int i;
- for (i = 0; i < m_noItems; i++)
- {
- int len = (int)SendMessage(GetHwnd(), LB_GETTEXT, i, (LONG)wxBuffer);
- wxBuffer[len] = 0;
- SIZE extentXY;
- ::GetTextExtentPoint(dc, (LPTSTR)wxBuffer, len, &extentXY);
- int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);
- if (extentX > largestExtent)
- largestExtent = extentX;
- }
- if (oldFont)
- ::SelectObject(dc, oldFont);
-
- ReleaseDC(GetHwnd(), dc);
- SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L);
+ int nIndex = (int)::WinSendMsg( GetHwnd()
+ ,LM_INSERTITEM
+ ,MPFROMLONG((LONG)(i + nPos))
+ ,(MPARAM)asItems[i].c_str()
+ );
+
+ wxOwnerDrawn* pNewItem = CreateItem(nIndex);
+
+ pNewItem->SetName(asItems[i]);
+ pNewItem->SetFont(GetFont());
+ m_aItems.Insert(pNewItem, nIndex);
+ ::WinSendMsg( GetHwnd()
+ ,LM_SETITEMHANDLE
+ ,(MPARAM)((SHORT)nIndex)
+ ,MPFROMP(pNewItem)
+ );
+ m_nNumItems += nItems;