|
here is my code..
but in the callback function,two messageboxs contains empty string. do you know why?
when i insert an item to the tree, i had set item.lparam = info;
info is CString, which is .txt_2342_5/3/02 , type,size,and date combine in one stentence
i want to sort my tree by date, by size, and by type as window explore does.
any clue???
/*===============================================================================
Sorting a tree using CTreeCtrl::SortChildrenCB()
=================================================================================*/
CTreeCtrl *myTreeCtrl;
static int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
// lParamSort contains a pointer to the tree control.The lParam of an item is just its handle.
CTreeCtrl *pmyTreeCtrl = (CTreeCtrl*) lParamSort;
CString strItem1 = pmyTreeCtrl->GetItemText((HTREEITEM) lParam1);
CString strItem2 = pmyTreeCtrl->GetItemText((HTREEITEM) lParam2);
AfxMessageBox(strItem1);
AfxMessageBox(strItem2);
return strcmp(strItem2, strItem1);
}
//sorting trees
void CSMPprojectDlg::SortTreeItem()
{
// Sort the tree control's items using my callback procedure.
HTREEITEM hRoot = m_TreeCtrl.GetRootItem();
HTREEITEM hNextItem = m_TreeCtrl.GetNextItem(hRoot,1);
while( hNextItem != NULL )
{
m_TreeCtrl.SetItemData(hNextItem,(DWORD)hNextItem);
hNextItem = m_TreeCtrl.GetNextItem(hNextItem,1);
}
myTreeCtrl = &m_TreeCtrl;
TVSORTCB tvs;
tvs.hParent = m_TreeCtrl.GetRootItem();
tvs.lpfnCompare = MyCompareProc;
tvs.lParam = (LPARAM)myTreeCtrl;
m_TreeCtrl.SortChildrenCB(&tvs);
MessageBox("hello");
}
void CSMPprojectDlg::SortingAtree()
{
SortTreeItem();
}
|
|
|
|
|
here is the original code
void Compensate(float XCentroid, float ZCentroid,
float *CompensatedX, float *CompensatedZ)
{
double Dr = 0.0;
double LCentroidX = 0.0;
double LCentroidZ = 0.0;
double VectLength = 0.0;
double FRACTION = 0.009835;
double EXPONENT = 2.400;
LCentroidX = (double)XCentroid;
LCentroidZ = (double)ZCentroid;
VectLength = sqrt( (pow(LCentroidX, 2.0)) + (pow(LCentroidZ, 2.0)) );
Dr = FRACTION * ( pow(VectLength, EXPONENT) );
if ( VectLength != (double)0.0 )
{
*CompensatedX = (float)LCentroidX + ( Dr * ( LCentroidX / VectLength ) );
*CompensatedZ = (float)LCentroidZ + ( Dr * ( LCentroidZ / VectLength ) );
}
else
{
*CompensatedX = XCentroid;
*CompensatedZ = ZCentroid;
}
return;
}
so how can I reverse this algorithm? That is, based on CompensatedX and CompensatedZ, how can I get the original XCentroid and ZCentroid?
I tried the following, but it doesn't work.
CompensatedVect = sqrt(pow(CompensatedX, 2.0), pow(CompensatedZ, 2.0));
CompensatedDr = pow((CompensatedVect/FRACTION), 1/EXPONENT);
XCentroid = CompensatedX / (1 + CompensatedDr/CompensatedVect);
ZCentroid = CompensatedZ / (1 + CompensatedDr/CompensatedVect);
I hope I am posting it in the correct forum this time.
|
|
|
|
|
I wrote a #define macro and I would like to see the output
after it's preprocessed, is there a setting in VStudio
that would show the macro after it is expanded?
.dave.
David Hisel -- http://www.hisel.com/
|
|
|
|
|
From the Property Pages dialog:
- Expand the Configuration folder
- Expand the C/C++ folder
- Click the Preprocessor item
- Change the Generate Preprossed File to the desired setting (line numbers or not in the output file)
When you build the project, you will have preprocessed versions of your files with the .i extension.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
sorry, but didn't find item 4 (line numbers or not). should I include some C++ macros there?
|
|
|
|
|
What do you see as options on the Preprocessor page? The third item should be labelled "Generate Preprocessed File". You click in that and drop the combo down to see the options.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
I did a Project->Settings->C/C++ -> Category: Preprocessor, and what I see is:
Preprocessor definitions (edit box)
UnDefined symbols: (check box, followed by an edit box)
Additional include directories: (edit box)
Ignore standard include paths (check box).
What did I miss?
|
|
|
|
|
Oh. Are you running VS6? I'm running VS.NET.
If you're running VS6, what you need to know is the following:
- Create preprocessor file - add /P to the CL call
- Create preprocessor file (with line numbers) - add /EP and /P to the CL call
Therefore, either look through for the pages for this option or manually add it.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
got it. Thank you, Tom.
In VS6, it's add /P or /EP (output is the output window of VS6) in Project Options of Project->Settings->C/C++ ->Category: Preprocessor.
|
|
|
|
|
No problem, Lucy. This is tremendously valuable in learning how those magic MFC and ATL macros work.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
the Property Pages, do you mean Project->Settings from the main menu?
Also, I am using VStudio 6 Enterprise Edition, if that helps.
.dave.
David Hisel -- http://www.hisel.com/
|
|
|
|
|
Sorry. I use VS.NET and forget that most don't. Look at my response to Lucy where I explain (as well as I can withouut the VS6 environment installed) how to do this in VS6.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Hello,
In my MFC application I have two similar dialog boxes. Each have a List Control Box and each has a varaible (of type CListCtrl) associated to them. One of them works fine but I get a Debug Assertion error on the first of these four lines in the second dialog.
m_MyListControl2.InsertItem(0, Line1, 0)
m_MyListControl2.SetItemText(0, 1, Line2);
m_MyListControl2.SetItemText(0, 2, Line3);
m_MyListControl2.SetItemText(0, 3, Line5);
The dialog boxes all have the same header files and the contents of DoDataExchange() are similar too.
Does anyone know why this is happening?
Thanks,
Aoife
|
|
|
|
|
if you didn't make those calls in OnInitDialog then it's because they haven't been created yet.
|
|
|
|
|
But the first dialog box isn't mentioned in OnInitDialog and it works fine. Could it be because there is two of them?
Thanks,
|
|
|
|
|
What does the debug assertion say. Not only does it usually print text about why it asserted, but if you look at the source code where the assert was raise, it sometimes gives you information about what you need to do to correct the problem.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
It says that the "Debug Assertion Failed" in file winctrl.cpp at line 547.
void CListCtrl::DrawItem(LPDRAWITEMSTRUCT)
{
ASSERT(FALSE);
}
This is a MFC\src file.
It gives no other reason as to why its happening.
Thanks
|
|
|
|
|
Then it looks like your list control is marked as owner drawn but you aren't handling the DrawItem routine to draw it.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I'm a newbie, so could you please explain how I can fix this?
Thanks,
Aoife
|
|
|
|
|
in the resource editor, open your dialog, double click the listbox then find and un-check the box that says "Owner Drawn" .
-c
I don't care, and you can't make me.
|
|
|
|
|
Worked perfectly!
I feel a bit thick that I didn't know that, but I'm so happy that I have finally got my application working that I don't care!
Thanks a million Chris.
Aoife
|
|
|
|
|
If I pass a quoted string variable to the LPVOID argument of a method it accepts it but if I pass a CString to the LPVOID augument I get a compiler error, cannot convert from 'CString' to 'LPVOID'. Can anyone help me with getting the data from a CString into an LPVOID data type?
Kyle
|
|
|
|
|
Convert first to LPCTSTR then maybe LPSTR then to LPVOID.
|
|
|
|
|
Tom Archer shared this answer with me so I wanted to share it with others. Thanks Tom!
It's easy. Just call the CString::GetBuffer function. Here's an example where I have a function that takes an LPVOID and another function that calls it twice (once passing a hard coded literal and then with a CString). Note that I'm using VC7. You might need to call GetBuffer(0) in VC6.
void CallTest()
{
Test("abc");
CString str = "def";
Test(str.GetBuffer()); // This is what you need to do in your case.
}
void Test(LPVOID lp)
{
AfxMessageBox((const char*)lp);
}
That should set you up.
Cheers,
Tom
It did! Thanks again Tom.
|
|
|
|
|
You're welcome, mate. Like I say in the Acknowledgements section of my C# book, being able to share code and help each other on sites like this is one very big reason that programming remains fun after all these years.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|