|
Hi again,
here a snipit from MSDN:
The comparison function has the following form:
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort);
The lParam1 parameter is the 32-bit value associated with the first item being compared, and the lParam2 parameter is the value associated with the second item. These are the values that were specified in the lParam member of the items' LVITEM structure when they were inserted into the list. The lParamSort parameter is the same value passed to the LVM_SORTITEMS message.
U have to fill the params associated with the items/subitems first.
For instance, pointer to the DataClass instance. Then u can get/compare
everything from inside the class.
I had implemented today, and this is the fastest and easiest way to do
sorting in a listcontrol.
Marco
|
|
|
|
|
>>U have to fill the params associated with the items/subitems first.
>>For instance, pointer to the DataClass instance. Then u can get/compare
>>everything from inside the class.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Thanks ! I have tried it.
But I still got some problems on this lParam1 and lParam2.
That is, when I implement the Compare Function just like the sample from MSDN,
as follows:
int CALLBACK CSortListCtrl::CompareFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamData)
{
CSortListCtrl* pListCtrl = reinterpret_cast<csortlistctrl*>( lParamData );
ASSERT( pListCtrl->IsKindOf( RUNTIME_CLASS( CListCtrl ) ) );
CString strItem1 = pListCtrl->GetItemText( lParam1, pListCtrl->m_iSortColumn );
CString strItem2 = pListCtrl->GetItemText( lParam2, pListCtrl->m_iSortColumn );
return strcmp(strItem2, strItem1);
}
I always got lParam1 and lParam2 the SAME !! That is, the Compare Function is always comparing the same thing ! (The first item always ! And I found the lParam1 and lParam2 are always 0 !!)
The following is how I added items to my list control:
/// m_CtrlEntryList is of type CSortListCtrl, which is also of type CListCtrl
//// add subitem 0 first
m_CtrlEntryList.InsertItem( iItemNo, szString );
LV_ITEM lvitem;
ZeroMemory( &lvitem, sizeof( lvitem ) );
/// then add subitem 1 ~ 3
lvitem.mask = LVIF_TEXT;
lvitem.iItem = iItemNo;
lvitem.pszText = szString;
lvitem.iSubItem = iSubItemNo;
lvitem.lParam = iItemNo; // <------ I DO specify this lParam
m_CtrlEntryList.SetItem( &lvitem );
I used something like above to add items to my list control, and it really worked and displayed fine. I don't know why when I get them compared, the 2 parameters passed to compare function are always 0.
Anything wrong ?
|
|
|
|
|
I found one sample for sorting list control on this web site. The URL is:
http://www.codeproject.com/listctrl/sortlistctrl.asp
And, I have also tried his codes. His codes are fine and I found he did "Add Items" to his list control something like this:
/// CSortListCtrl is derived from CListCtrl
int CSortListCtrl::AddItem( LPCTSTR pszText, ... )
{
//..... skipped
VERIFY( CListCtrl::SetItem( iIndex, iColumn, LVIF_TEXT, pszText, 0, 0, 0, 0 ) );
///... skipped
}
Why not just use something like:
this->SetItem( iIndex, iColumn, LVIF_TEXT, pszText, 0, 0, 0,0 ) ); ???
So, I should use something like CListCtrl::SetItem(.....) to add my items ?
|
|
|
|
|
Hello,
try to use "SetItemData()" instead of "xx.lParam=xx".
Marco
|
|
|
|
|
Thanks ! It really helps. Now the 2 parameters passed in are different.
But, I still got trouble on sorting result. The sorting result is very weird.
I have traced in my compare function and I thought it should get the right result but actually it doesn't.
My Compare function is something like the following:
int CALLBACK CSortListCtrl::CompareFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamData)
{
int r = 0;
CSortListCtrl* pListCtrl = reinterpret_cast<csortlistctrl*>( lParamData );
ASSERT( pListCtrl->IsKindOf( RUNTIME_CLASS( CListCtrl ) ) );
CString strItem1 = pListCtrl->GetItemText( lParam1, pListCtrl->m_iSortColumn );
CString strItem2 = pListCtrl->GetItemText( lParam2, pListCtrl->m_iSortColumn );
if ( pListCtrl->m_bSortAscending ) // ascending sort
r = strcmp( strItem1, strItem2 );
else
r = strcmp( strItem2, strItem1 );
return r;
}
I have tested an original sequence of alphabet of a specified column like:
M, H, D, V (4 chars)
If ascending sort on 1st time, it would get right result like: D, H, M, V
but when next time I want to sort descendingly, it is wrong !! (i.e, the sequence is NOT V, M, H, D, but something else instead. )
And another run of ascending sort, it got another weird sequence again !!
(I have modified adding items to something like the following:
/// insert sub-item 0
m_CtrlEntryList.InsertItem( iItemNo, szString );
/// insert sub-items 1~3
m_CtrlEntryList.SetItem( iItemNo, iSubItemNo, LVIF_TEXT, szString, 0, 0, 0, 0 );
/// as you suggested, this lParam should be unique, right ?
m_CtrlEntryList.SetItemData( iItemNo, ( DWORD ) iItemNo );
|
|
|
|
|
What exactly is the difference between a dialog box and a form? Why would one use the one and not the other?
|
|
|
|
|
By a form do you mean Winforms, or an SDI/MDI app ? A dialog does not allow you to have floating toolbars, nor does it support doc/view. A dialog is best for simpler apps, or apps that do not use doc/view.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Sorry, stupid of me..
I meant to ask why one would choose to derive a class from CFormView instead of CDialog. My fellow programmer asked me and I realized I have no idea why one would need to use CFormView at all. We are both new at Visual C++ programmers and there are still many holes that need filling.
|
|
|
|
|
No worries - I should have realised. The answer is the same - floating toolbars, doc/view, etc, all useful for a more complex app, but a CFormView allows you to mix that with designing a window full of controls in the resource editor.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
thank you!
|
|
|
|
|
I want to have a line in 80th column of my view which is derived from CView. This is to be used as an 80th column marker. I will be grateful to you if anybody can help me in solving this problem.
|
|
|
|
|
You're going to have to draw it in the erasebackground call, the issue is figuring out where it is, if you have a non-fixed width font.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Sir,
I cannot find anything called erasebackground function anywhere in vc++. Can you suggest me a similar function which i can use with my view which is derived from CView. My exact problem is like this. Suppose, I am drawing a line at 80th column, and if I am increasing the font size, the line comes to some 30th or 35th column and not 80th column. This I want to update on change of the font size. I have a function OnChangeFont() which will be executed when user changes the font.
Thank You and expecting a positive reply.
Krishna Raj.
|
|
|
|
|
WM_ERASEBKGRND, from memory.
You'll need to measure the string to figure out where to draw your line, and as I said, that will not always be 80 columns because different characters have different widths, all you can do is shoot for an average.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
How to correctly implement subj?
|
|
|
|
|
Hi,
I want to use map<string,string> in my program but I don't want it sort for me and I would like to have a NoCase comparation. Can I do that? how?
Thanks
|
|
|
|
|
No. A map is always sorted.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
error C2065: 'MIIM_STRING' : undeclared identifier
Why am I getting this error? I didn't before, but suddenly all my system-tray projects do. I've got WindownXP and I've installed the Microsoft Platform SDK (May 2002). Is there something wrong with my VC++ settings, since MIIM_STRING should exist since Windows98 or something. I am also experiencing other weirdnesses like this:
'DialogBoxParamA' : cannot convert parameter 4 from 'long (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int
This error suddenly came up in one of my projects which previously compiled just fine. The param is a DLGPROC which is declared (and the definition is similar) like this:
INT_PTR CALLBACK ConfigDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
This is correct according to the Platform SDK Documentation. INT_PTR is a long obviously but DialogBoxParamA wants it to be an int. What's up?!
And I'm sure there are other things; I haven't bothered opening up all my old projects just to check...
Please help me. I'm desperate
Sprudling
|
|
|
|
|
For some reason neither the VC++ SP5 upgrade or the Platform SDK install managed to setup the correct include and lib directories in VC++.
Sprudling
|
|
|
|
|
Hello,
simple question:
Can i make a shadow in my custom cursor, like the standard cursor's ?
OS : Win2000
Marco
|
|
|
|
|
Hi, i'm using VC++ 6.0 I have add the file "myprogram.exe" to my project's resource and the file's ID is "IDR_FILE1" I want a program with a button that, when pressed, will copy the file "myprogram.exe" to the targeted directory of my chosen, for example "c:\\test " What code should I write in the on button pressed function to make this work.
thank you so much for your help.
|
|
|
|
|
Check the codeproject MFC FAQ for code allowing to choose a directory. Then CopyFile(oldfilename,newfilename,FALSE); .
Hope this helps...
~RaGE();
|
|
|
|
|
I try do a webbrowser with WebBrowser2 control but I get some errors or uninstpected behaviour. I cannot find any tutorial how to use WebBrowser2 with MFC.
Do you know about any?
My main problem is, that when I press back button and there aren't any more back .html pages. A message box pops up from nowhere. How can I handle this?
|
|
|
|
|
I need to supply a data structure to a new thread as parameter when a create it. How can I do that ??
I have declared the thread as:
DWORD WINAPI CopyFolder(void* p_pvThreadParameter)
and I create it using the following instruction:
l_hCopyFolderThread = CreateThread(NULL, 0, CopyFolderThread, this, 0, &l_dwThreadId);
As fourth parameter, as you can see, I have supplied "this": so the tread can used public members of the class that has created it. This methods work correctly but i don't like it !!!! I prefer to supply to each thread its parameters !!!
I have tried to supply a point to a data structure (casting it to void). But this doesn't work !!!!
How can I do ??
Thank you very much !!!
Cristiano Galeazzi
|
|
|
|
|
I have tried to supply a point to a data structure (casting it to void). But this doesn't work !!!!
Why does it not work? It should.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|