Link to home
Start Free TrialLog in
Avatar of marcus78
marcus78

asked on

CListCtrl and Unicode(?) Problem

This little bug's got me stumped. I've got a listctrl that I'm dynamically creating in a formview. It is a report style listctrl, which allows the editing of the items.  

I'm handling the EndLabelEdit message with the message maps, in the formview:
ON_NOTIFY(LVN_ENDLABELEDITA,IDC_REPOSITORY, OnEndlabeleditRepository)
     ON_NOTIFY(LVN_ENDLABELEDITW,IDC_REPOSITORY, OnEndlabeleditRepository)

I ended up using these, as a solution to a previous question I asked, where handling LVN_ENDLABELEDIT was not enough to catch the message.

Up to this point, things work fine, and I can handle and validate the edited text.  The problem is here:

void CMyView::OnEndlabeleditRepository(NMHDR* pNMHDR, LRESULT* pResult)
{
 CMyView::OnEndlabeleditRepository(pNMHDR, pResult);
 LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;    
 CString strText = pDispInfo->item.pszText;
 //do something with the text...
 *pResult = TRUE;
}

If I was to enter "Test" then
pDispInfo->item.pszText = T\0e\0s\0t\0
so strText ends up equalling "T"

I think this is a UNICODE issue, and I don't currently have the preprocessor _UNICODE defined.  But it's my understanding that a CString should take this and convert it correctly, right?

This works correctly on Win98, and I get this problem on WinNT.

Any ideas on how to remedy this?

Thanks,
Marcus
ASKER CERTIFIED SOLUTION
Avatar of migel
migel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peterchen092700
peterchen092700

Windows NT uses UNICODE internally (all API calls with ANSI parameters get converted to Unicode).

I guess the solution is something around

CString str;
if (::IsWindowUnicode(lisctrl.m_hWnd)) {
  // migel's code here
}
else
  str = pDispInfo->item.pszText;

Peter
also you can separate notifications handler for
LVN_ENDLABELEDITA and
LVN_ENDLABELEDITW
Avatar of marcus78

ASKER

Migel,

This is what I'm looking for. Thanks!

Marcus