Re: ComboBox DeleteItem() not being called for all items?

Tech-Archive recommends: Fix windows errors by optimizing your registry



To add to what I wrote in previous message (not related to your main problem, but might be worth writing):

AndersG wrote:

> I finally got the time to investigate further and this is what I have:

void CLpCombo::DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct)
{
// Delete CString pointed to by item.
TRACE("\nDeleting %d from control %d (%s)",
lpDeleteItemStruct->itemID,
lpDeleteItemStruct->CtlID,
*((CString*)lpDeleteItemStruct->itemData));

delete (CString*)lpDeleteItemStruct->itemData;


When you have a %s and you want to pass a CString, it now works, but is considered not very safe.
It works because of some "magic" in the internal design of CString, but if you have a %s and variable argument list, is better to explicitly static_cast to LPCTSTR, or use CString::GetString() method, e.g.

CString str;
int x;
int y;
TRACE("Some data: %d, %s, %d", x, str.GetString(), y );

So, I would adjust your code a bit like this:

void CLpCombo::DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct)
{
// Get custom CString pointer from lpDeleteItemStruct
CString * pstr =
reinterpret_cast<CString *>( lpDeleteItemStruct->itemData );

// Trace deletion
TRACE("\nDeleting %d from control %d (%s)",
lpDeleteItemStruct->itemID,
lpDeleteItemStruct->CtlID,
pstr->GetString()));

// Free previously allocated CString
delete pstr;
}


Giovanni
.



Relevant Pages

  • Re: Inheritance
    ... CString GetTeammascot(); ... int FindTeam; // Get the index for a particular team given their team name by looping through list ... class glider: public monoplane { ... Given this hierarchy, I can probably come up with actual planes that don't fit it. ...
    (microsoft.public.vc.mfc)
  • Re: Newbie: out of memory issues
    ... Heres the problem code:: Lots of array handling with objects.. ... You should use CString. ... char out2; ... BOOL swe_date_conversion(int year, int month, int day, int hour, int cal, double & ...
    (microsoft.public.vc.mfc)
  • Re: How To Refresh tree
    ... > pane tree control to Right pane list control which contain Tree Item, ... > CString strItemQry; ... > int nItemPriKey = GetItemPrimaryKey; ... > // check for any sub chield under sub chield ...
    (microsoft.public.vc.mfc)
  • Re: CStringArray
    ... void InsertName(int modNum, int location, const CString & name) ... ATLASSERT(ValidIndexes(modNum, location)); ... CString GetName(int modNum, int location) const ...
    (microsoft.public.vc.mfc)
  • Re: CStringArray
    ... void InsertName(int modNum, int location, const CString & name) ... CString GetName(int modNum, int location) const ...
    (microsoft.public.vc.mfc)