|
It seems to work, but crashes when I exit with Ok or the system menu.
The UI comes up just fine! If I comment out AddItem1, it exits fine:
BOOL CSortListCtrlTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
(void)m_ctlList.SetExtendedStyle( LVS_EX_FULLROWSELECT );
m_ctlList.SetHeadings( _T("Name,120;Date of Birth,90;Score,50;Score,200") );
CStringArray pArray;
int iArraySize = 4;
pArray.Add("ccc");
pArray.Add ("ppp");
m_ctlList.AddItem1(pArray, iArraySize , 0);
return TRUE;
}
and
int CSortListCtrl::AddItem1( CStringArray &pArray, int iArraySize , int nPos)
{
int nIndex = InsertItem(LVIF_TEXT|LVIF_STATE, 0, "abc",0,LVIS_SELECTED,0,0);
ASSERT(nIndex != -1);
if (nIndex < 0) return(nIndex);
return(nIndex);
}
I dont use any of the info I passed in (for testing). I dont do anything fancy. This is the barest code with which it crashes in OnDestroy
which has only CDialogs destroy in it. If I comment out the InsertItem it exits fine. if I use instead
int nIndex = InsertItem( 0, "abv");
, it still crashes
What shall I look at here that might be the problem?
Appreciate your help,
ns
|
|
|
|
|
What crashes - are you getting an ASSERT or GPF? Look at the call stack at the crash point and check where exactly problem is located.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
memory cant be read.
(I hope theres enough info here for you to advise me...)
call stack points to:
void CSortListCtrl::FreeItemMemory( const int iItem )
{
ItemData* pid = reinterpret_cast<ItemData*>( CListCtrl::GetItemData( iItem ) );
LPTSTR* arrpsz = pid->arrpsz;
for( int i = 0; i < m_iNumColumns; i++ )
delete[] arrpsz[ i ];
delete[] arrpsz;
delete pid;
VERIFY( CListCtrl::SetItemData( iItem, NULL ) );
}
which is from their AddItem (I want to make my own)
int CSortListCtrl::AddItem( LPCTSTR pszText, ... )
{
const int iIndex = InsertItem( GetItemCount(), pszText );
LPTSTR* arrpsz = new LPTSTR[ m_iNumColumns ];
arrpsz[ 0 ] = new TCHAR[ lstrlen( pszText ) + 1 ];
(void)lstrcpy( arrpsz[ 0 ], pszText );
va_list list;
va_start( list, pszText );
for( int iColumn = 1; iColumn < m_iNumColumns; iColumn++ )
{
pszText = va_arg( list, LPCTSTR );
ASSERT_VALID_STRING( pszText );
VERIFY( CListCtrl::SetItem( iIndex, iColumn, LVIF_TEXT, pszText, 0, 0, 0, 0 ) );
arrpsz[ iColumn ] = new TCHAR[ lstrlen( pszText ) + 1 ];
(void)lstrcpy( arrpsz[ iColumn ], pszText );
}
va_end( list );
VERIFY( SetTextArray( iIndex, arrpsz ) );
return iIndex;
}
Do I need this arrpsz stuff? Can I get rid of their freememory function? Its used by them in:
BOOL CSortListCtrl::DeleteItem( int iItem )
{
FreeItemMemory( iItem );
return CListCtrl::DeleteItem( iItem );
}
::DeleteAllItems();
}
I wont be needing to delete any items so I am paring down their class.
Appreciate your help,
ns
|
|
|
|
|
OoPs! Also used in:
void CSortListCtrl::OnDestroy()
{
for( int iItem = 0; iItem < GetItemCount(); iItem ++ )
FreeItemMemory( iItem );
CListCtrl::OnDestroy();
}
Appreciate your help,
ns
|
|
|
|
|
I have no idea how exactly CSortListCtrl works. Did you create this class yourself or downloaded from the net?
When program crashes, check the 'pid' and 'arrpsz'. Probably one of them is NULL.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
THe article and demo are from CP
http://www.codeproject.com/listctrl/sortlistctrl.asp
. I didnt call their AddItem (earlier post)where the arrpsz stuff is getting set or used - I used my little AddItem1
which does nothing except inserItem in the first column. So I'm sure the variables you mentioned are null.
Looks like I cant replace their AddItem, since I have no clue what this pid stuff is, therefore cant use it in my AddItem1.
So my challenge is to (try to) extend their AddItem so it can take in an array also, which is what I'll use to insert my items. I can ignore the arguments they pass in, and leave all the arrpsz stuff intact so it doesnt get unhappy. Thanks for pointing me in the right direction. THe call stack is useful! Never used it before...
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
I have no clue what this pid stuff is
The 'pid' variable in function causing the crash is item data. Each row in listview can have associated 32-bit value - you use GetItemData/SetItemData for that. CSortListCtrl apparently stores the pointer to some array (probably in the call to SetTextArray). pid is just the retrieved pointer. If you don't call original AddItem, then pid will be NULL and your app will die.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Hmmm.Okay. Thank you for that info.
Their addItem has one 'fixed' input variable, and unlimited optionals. I will have my subItem texts in an array and wanted to pass in an array but modifying their code is beyond my present capabiities. So I have to figure out how best to pass in my array the way they want it:
AddItem(pArray[0], pArray[1], pArray[2].......pArray[n])
which is how they want it. Its not at all obvious to me how I can loop on an index when passing in the array in this fashion.
My problem is that for one database where I get my subitem texts from, there is a particular 'n' value, and a different 'n' for a different database.So I cant hard code the AddItem parameter list. And I cant loop on an index in the argument list....
thanks,
ns
|
|
|
|
|
Their version of AddItem uses variable argument list and va_xxx stuff because they must provide convenient syntax for list controls containing different # of columns. Read the docs on va_start, va_end and va_arg and you'll get the idea what's going on. Passing array instead of array elements should be trivial.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Trying. I cant strip out their pid and arrpsz stuff safely, and its tied in with their variable optionals. Heres my attempt:
int CSortListCtrl::AddItem2( CString pArray[], int ArraySize)
{
const int iIndex = InsertItem( GetItemCount(), pArray1[0] );
LPTSTR* arrpsz = new LPTSTR[ ArraySize ];
arrpsz[ 0 ] = new TCHAR[ lstrlen( pArray1[0] ) + 1 ];
(void)lstrcpy( arrpsz[ 0 ], pArray1[0] );
for( int iColumn = 1; iColumn < ArraySize; iColumn++ )
{
CListCtrl::SetItemText( iIndex, iColumn, pArray1[iColumn] );
arrpsz[ iColumn ] = new TCHAR[ lstrlen( pArray1[iColumn] ) + 1 ];
(void)lstrcpy( arrpsz[ iColumn ], pArray1[iColumn] );
}
VERIFY( SetTextArray( iIndex, arrpsz ) );
return iIndex;
}
Appreciate your help,
ns
|
|
|
|
|
You don't need to strip anything; just change the way arguments are passed. Your code looks OK; I'd use CStringArray instead of CString[].
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
I cant thank you enough. This exchange was very instructive. I used CStringArray like you said and it works, plus no crashes!
This is a little sample I tried before I use this class in my main project, but I wanted to tailor it so I could use it -
my pArray is going to come from reading in the all values of one row of a database into a CStringArray.
Now the next thing I have to do is figure out how to get all the values of a particular column out of the listcontrol. - ah GetItemText()
I thank you very much for all the help you have been giving me , and the patience
Appreciate your help,
ns
|
|
|
|
|
Hurrah for CStringArray ! (And thanks to Tomasz! )
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Tomasz did a lot for my confidence. Never in a million years did I dream that I'd have the courage to modify extremely foreign looking stuff like va_arg etc, but its demystified. Tons of sections in this CP class where I am clueless, but its like a daily learning process, so theres hope! Thanks for CStringArray. Quite friendly to use.
Appreciate your help,
ns
|
|
|
|
|
Hi , I'm writing an activex to apply skins to dialogs ,etc..
but I don't Know how to get the hwnd of the container of the activex (i.e. the dialog box)
Any I dea would be helpful
thanks in advansed
|
|
|
|
|
Spy++
then ::FindWindow(), ::EnumWindow()
Normal hacking procedure.
sometimes it helps to look at the IL generated code
a MS guy on develop.com "answering" .NET issues
|
|
|
|
|
Try:
AfxGetMainWnd()->GetSafeHwnd();
Nitron
_________________________________________--
message sent on 100% recycled electrons.
|
|
|
|
|
getparent()
etc...?
"... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away" biz stuff about me
|
|
|
|
|
Hi all!
I'm trying to write an Mail server using VC6.
It's OK for mail with Text only, but bot with formatted text, mail with Images ....!
Can any one tell me how to display a formatted mail as Netscape mail or Outlook express does.
what ActivexControol Can I use for mail editor and and mail displayer.
NNH
|
|
|
|
|
Search for the browser control!
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
The webbrowser control that was suggested to you is fine, but it could well mean you are open too viruses etc.
Consider using the thumbnail control as well.
Note it isn't near as powerful as the webbrowser control, but good for previews.
Regardz
Colin J Davies
Sonork ID 100.9197:Colin
You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining.
Said by Roger Wright about me.
|
|
|
|
|
|
Hi all!
I connect to Internet by personal Computer though PSTN via a modem.
Does anyone know How to get the actual IP Address of such a computer like mine?(not get by localhost 127.0.0.01)
Thanks in advance.
NNH
|
|
|
|
|
http://www.codeproject.com/internet/ipenum.asp
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
If you don't want to do it through code, you just want to know for your reference, then use winipcfg (win9x) or ipconfig (NT/2k/xp)
Signature space for rent. Apply by email to....
|
|
|
|