Click here to Skip to main content
15,891,942 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: GetItemText returns bad CString & can't change subitem color in CustomDraw Pin
Tomasz Sowinski5-Aug-04 7:39
Tomasz Sowinski5-Aug-04 7:39 
GeneralRe: GetItemText returns bad CString & can't change subitem color in CustomDraw Pin
Mike Landis5-Aug-04 9:10
Mike Landis5-Aug-04 9:10 
GeneralRe: GetItemText returns bad CString & can't change subitem color in CustomDraw Pin
Tomasz Sowinski5-Aug-04 9:27
Tomasz Sowinski5-Aug-04 9:27 
GeneralRe: GetItemText returns bad CString & can't change subitem color in CustomDraw Pin
Mike Landis5-Aug-04 9:57
Mike Landis5-Aug-04 9:57 
GeneralRe: GetItemText returns bad CString & can't change subitem color in CustomDraw Pin
Tomasz Sowinski5-Aug-04 10:14
Tomasz Sowinski5-Aug-04 10:14 
GeneralRe: GetItemText returns bad CString & can't change subitem color in CustomDraw Pin
Mike Landis5-Aug-04 10:49
Mike Landis5-Aug-04 10:49 
GeneralRe: GetItemText returns bad CString & can't change subitem color in CustomDraw Pin
Tomasz Sowinski5-Aug-04 11:03
Tomasz Sowinski5-Aug-04 11:03 
GeneralRe: GetItemText returns bad CString & can't change subitem color in CustomDraw Pin
Tomasz Sowinski6-Aug-04 1:17
Tomasz Sowinski6-Aug-04 1:17 
Mike Landis wrote:
On subclassing, I've been using the Wizard to define classes. Finish the dialog in the resource, Ctrl-W, New class, etc. I think it's sewn together right. If you bring up the Wizard over any of my dialogs, you immediately see the subclass, messages, member functions...

Yes, but this only takes care of subclassing the *dialog*. If you want to handle reflected notifications in list control, you'll also have to subclass it. Otherewise, nobody will scan its message map - it'll be plain Win32 control with no MFC window procedure behind. I guess haven't used ClassWizard's 'Member Vars' tab to associate CYourListCtrl with any control ID. How does DoDataExchange looks like in your dialog? It should have something like DDX_Control(pDX, IDC_LIST1, m_lst1);

Can you post example code or suggest a URL where strncpy is used to solve the longevity problem?

strncpy, or rather wcsncpy - because WinCE is Unicode only - skips over longevity. In your approach, you're trying to keep string data for some time, and you're just setting item.pszText to point inside your pool. But when your LVN_GETDISPINFO handler is called, list control itself has initialized pszText. It points to its internal buffer, managed by Windows. You can create the string you need on the fly, and instead of stuffing it into pool copy it into this buffer using wcsncpy. Here how it looks in my test app running just fine on hp1910:

void CTestListCtrl::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
	LV_DISPINFO* pdi = (LV_DISPINFO*)pNMHDR;<br />
	if (LVIF_TEXT & pdi->item.mask)<br />
	{<br />
		CString strItem;<br />
		strItem.Format(_T("Item %d - %d"), pdi->item.iItem, pdi->item.iSubItem);<br />
		<br />
		wcsncpy(pdi->item.pszText, strItem, pdi->item.cchTextMax);<br />
	}<br />
	*pResult = 0;<br />
}


You don't care about the lifetime of strItem, because it is copied before leaving OnGetdispinfo.

I'm sending the source of my test app to your email account. It's 12 kb zip file; solves all problems you've reported (handles NM_CUSTOMDRAW/LVN_GETDISPINFO in list control class and changes colors of list items).

Tomasz Sowinski -- http://www.shooltz.com

Alika masiaka!

GeneralRe: GetItemText returns bad CString &amp; can't change subitem color in CustomDraw Pin
Tomasz Sowinski5-Aug-04 2:18
Tomasz Sowinski5-Aug-04 2:18 
Generalthread stack overflow problem.. Pin
TssPrasad4-Aug-04 17:47
sussTssPrasad4-Aug-04 17:47 
GeneralRe: thread stack overflow problem.. Pin
palbano4-Aug-04 18:04
palbano4-Aug-04 18:04 
GeneralRe: thread stack overflow problem.. Pin
TssPrasad4-Aug-04 18:13
sussTssPrasad4-Aug-04 18:13 
GeneralRe: thread stack overflow problem.. Pin
Jijo.Raj4-Aug-04 19:01
Jijo.Raj4-Aug-04 19:01 
GeneralHelp needed!!!! Pin
pundit4-Aug-04 17:47
pundit4-Aug-04 17:47 
GeneralRe: Help needed!!!! Pin
Antti Keskinen4-Aug-04 22:15
Antti Keskinen4-Aug-04 22:15 
QuestionHow to distinguish file from directory ? Pin
Amarelia4-Aug-04 17:23
Amarelia4-Aug-04 17:23 
AnswerRe: How to distinguish file from directory ? Pin
PJ Arends4-Aug-04 17:52
professionalPJ Arends4-Aug-04 17:52 
AnswerRe: How to distinguish file from directory ? Pin
Shiva Prasad4-Aug-04 17:59
Shiva Prasad4-Aug-04 17:59 
GeneralRe: How to distinguish file from directory ? Pin
PJ Arends4-Aug-04 18:16
professionalPJ Arends4-Aug-04 18:16 
GeneralSpy ++ , Thread and Message Pin
Danny Gilbert4-Aug-04 17:23
Danny Gilbert4-Aug-04 17:23 
GeneralRe: Spy ++ , Thread and Message Pin
Ryan Binns4-Aug-04 18:21
Ryan Binns4-Aug-04 18:21 
GeneralRe: Spy ++ , Thread and Message Pin
Danny Gilbert5-Aug-04 4:12
Danny Gilbert5-Aug-04 4:12 
GeneralRe: Spy ++ , Thread and Message Pin
Ryan Binns5-Aug-04 17:15
Ryan Binns5-Aug-04 17:15 
GeneralRe: Spy ++ , Thread and Message Pin
Danny Gilbert5-Aug-04 18:23
Danny Gilbert5-Aug-04 18:23 
QuestionHow to use a functin in ANSI which is taking UNICODE standard ? Pin
Amarelia4-Aug-04 17:17
Amarelia4-Aug-04 17:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.