|
take a look at std::sort
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I thought about this, but I'm not sure how to approach it. If I have a class:
class CRowData {
CString col1;
int col2;
}
and I defined a vector as:
std::vector<crowdata> vecRowData;
and I want to use std::sort, then I have to override the operator< and operator==. This means I can only sort on one variable in the operator< method. How can I specify which variable to sort on?
DP
|
|
|
|
|
Use std::sort that takes three arguments. The last one is a predicate - you can pass one predicate when you need to sort by col1, another for col2.
Since it seems that performance is important to you, note that while qsort just shuffles bits around during sorting, std::sort will perform assignments. Depending on members of your struct, it may have impact on perf. Post some results when you're done with this
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
there are many flavors of std::sort. some of them take what's called a 'predicate'. this is essentially a custom comparison function. so, you can sort on anything you like.
bool predicateFunction(const CMyStruct& a, const CMyStruct& b)
{
return (a is somehow less than b);
}
vector <CMyStruct> vec;
...
std::sort(vec.begin(), vec.end(), predicateFunction);
so, you just use different predicate functions when you want to sort in different ways (differnet members, direction, etc.)
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Thank you for the code snippet! It was just what I needed! I created two sort functions:
bool sortCol1(const CLabelItem& a, const CLabelItem& b)
{
return (a.m_strText < b.m_strText); // CString
}
bool sortCol2(const CLabelItem& a, const CLabelItem& b)
{
return (a.m_Addr < b.m_Addr); // DWORD
}
and did the sort comparision only on the STL modified code. Here are the results (in ticks) for 50000 rows:
Debug Release
qsort:
CString 55000 22000
DWORD 220 50
STL sort:
CString 1221 420
DWORD 750 220
Summary ( IMHO )
Use STL for code simplicity and maintenance and use STL sort unless the extra 150 ticks for DWORDs are important!
My thanks to all for all the help!
Derek
|
|
|
|
|
So the qsort is *much* slower for CString sorting? It's rather counter-intuitive, but still possible. Could you post your function that qsort calls back?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Well,... I "screwed up" again I guess I was comparing apples and oranges. The qsort method used the strcmp (C-runtime) function to compare strings. I used CString's operator> method to compare. Both give the same answer, but the CString was much faster. I didn't bother replacing the STL sort code with the strcmp code, because I'm sure it would be slower than qsort's.
Sorry for the misleading results!
Derek
|
|
|
|
|
Hello,
I just converted an article at the "other" site (http://www.codeguru.com/listview/VirtualListControl.html) from CArray to std:vector. The performance increased 5 times! The only section that I didn't like was the column sorting method. It uses the qsort() function to sort the columns. It seems there would be a more elegant (STL) method of doing this. There is a class defined for a row of data similar to this (shortened for clarity):
class CRowData {
CString col1;
int col2;
}
The qsort function calls the appropriate comparison function to sort on the desired member. It seems like there should be a way to do this using the STL. I would like to expand this example to include sorting on more than two columns as well.
Any ideas?
Thanks,
Derek
Doble Engineering
|
|
|
|
|
Where is the flag that I can set in MS Visual C++ that will allow me to have an instance of MS Visual C++ open, then double click a .dsw in Windows Explorer and have that workspace open in another instance of MS Visual C++? I know I have something set somewhere that allows this, I just cannot remember. Any help?
Roger Printy
Software Engineer
TeraNex
Orlando, FL
|
|
|
|
|
Is there a way using the C++ automation to find out the location of the project/file in the SourceSafe?
The only solution that I see for now is to find out the path of the project and than to parse the .dsp or .dsw file to find out the path of the project in the SourceSafe.
I would like to do this without parsing the .dsp or .dsw file...
Thanks.
Rasstislav
|
|
|
|
|
when trying to click on a listbox created in runtime over an edit control in a formview, the existing edit control under the listbox control gets a focus. so i can't select an item in a listbox. somebody help me...
by peng-you.
|
|
|
|
|
hmmmm
try either setting the z-order of the listbox to be in front of the edit control ... maybe destry the edit control ... disable it ... or use a combobox that allows the user to type stuff into the list control portfion and add some custom behaviour to stop the item being added to the list
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
How can I make my CFileDialog to accept directories and return the full path name of the directory. Something like what I get when I select File / New option in the MSDEV IDE and click on the "..." button next to Location Edit box ??
Sudha Shriram
|
|
|
|
|
You don't need CFileDialog for that. Use SHBrowseForFolder instead.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hi,
If you look on the menu of InternetExplorer:
FILE | SEND -> here you get a popup menu
i need to do the same but do not know how
m_menu.LoadMenu(IDR_MENU1);
SetMenu(&m_menu);
CMenu* pContextMenu;
//Get sub menu - index 0
pContextMenu = m_menu.GetSubMenu(0);
pContextMenu->AppendMenu(MF_STRING | MF_POPUP, ID_MENU_ADD, "NEW ITEM");
pContextMenu->AppendMenu(MF_STRING | MF_CHECKED, 5001, "NEW ITEM2");
this code will add two new items under the first position in my IDR_MENU1.
How can add new items to position "NEW ITEM2" ?
thank you
|
|
|
|
|
In your dialog editor, you do this by checking 'pop-up' for the item, then you can build a menu underneath it. I'm sure it can be done programatically, from memory by adding a menu to another, but I forget the details.
Christian
#include "std_disclaimer.h"
|
|
|
|
|
it can be done dynamically. i did it with the following code. (IDR_MENU1 - has only captions of my menu)
m_menu.LoadMenu(IDR_MENU1);
SetMenu(&m_menu);
CMenu* pContextMenu;
CMenu pPopMenu;
//Get sub menu - index 0
pContextMenu = m_menu.GetSubMenu(0);
pPopMenu.CreatePopupMenu ();
pPopMenu.AppendMenu (MF_STRING, 5001, "shortcut to desktop");
pPopMenu.AppendMenu (MF_STRING, 5001, "email");
pContextMenu->AppendMenu(MF_POPUP , (UINT) pPopMenu.m_hMenu , "SEND");
thanks
|
|
|
|
|
hi there
i want add an activex control into my project.
its a little bit complicated to explain.
on the start of my program i start all of my windows and minimized them to 0,0,1,1 most of them are CDialog
some CFrame... i dont use mfc ... only a very little bit.
now i want to insert a activex same way. start "minimized" without data. this works. but if i want to insert data. then i hang up.
how can i insert an activex "without mfc" ... or only little little bit of mfc ...
thx
|
|
|
|
|
Hi, I'm working with a composite control in Visual C++...
Among other things I have a button on the dialog..
The problem is that I can't get it to react on me pressing the enterbutton.
I've tried overloading the pretranslatormethod but that doesnt work so good....
HELP
|
|
|
|
|
Assign the IDOK identifier.
(By default the OK button captures the [Enter] key)
AEB
|
|
|
|
|
It doesnt work...I have tried...try it using a composite control...using a plain dialog..it works
/Pierre
|
|
|
|
|
Does anyone know how to pass parameters into an sql command?
Either prompting or just straight in?
Sample code or KB would be very useful.
Thankyou verymuch
Richard.:confused
|
|
|
|
|
try {
_CommandPtr cmd;
_ParameterPtr prmStudyNumber;
_ParameterPtr prmCadSysNumber;
_RecordsetPtr pRstCase = NULL;
TESTHR(cmd.CreateInstance(__uuidof(Command))); // Test a hresult
CString tempStr;
tempStr.Format("SELECT * FROM %s ;","CountPerCaseStatsCueType");
// CountPerCaseStatsCueType is a view "Query" in an access 2000 db that has 2 parameters
cmd->ActiveConnection = GetConnection(); // My function that returns a _ConnectionPtr that is open from a previous call
cmd->CommandText = _bstr_t(tempStr);
prmStudyNumber = cmd->CreateParameter(_bstr_t("StudyParam"),adInteger,adParamInput,-1,_variant_t((long)nStudy));
cmd->Parameters->Append(prmStudyNumber);
prmCadSysNumber = cmd->CreateParameter(_bstr_t("CadSysParam"),adInteger,adParamInput,-1,_variant_t((long)nCadSys));
cmd->Parameters->Append(prmCadSysNumber);
// NOTE: The Database will ignore the parameter names so you must place the parameters in the same order as you
// have defined in your view "query".
CStringEx str;
_variant_t var;
_variant_t v1(DISP_E_PARAMNOTFOUND,VT_ERROR);
_variant_t v2(DISP_E_PARAMNOTFOUND,VT_ERROR);
pRstCase = cmd->Execute(&v1,&v2,adCmdText);
while(!pRstCase->adoEOF) {
// Do something with the data
pRstCase->MoveNext();
}
}
catch (_com_error &e)
{
GenerateError(e.Error(), e.Description()); // My error message handler
}
catch( CException* e)
{
GenerateError(e);
}
catch (...)
{
m_pDoc->GetLog()->LogTime();
m_pDoc->GetLog()->Log("\nDATABASE ERROR: Unknown Exception in CCaseDataBase::GetCaseCoverageTypeStatisticsAll()");
}
I took this code out of one of my recent projects, I hope this helps.
John
|
|
|
|
|
CString strQuery = _T("");
strQry.Format(_T(sp_StoretClientFields_ps '%s', %d"), (LPCTSTR)strParam1, nParam2);
//strParam1 is String and nParam2 is numeric.
if you want see:
http://www.codeproject.com/useritems/caaadoclass1.asp
Here you can see a sample and a class, for use this.
If you want, please contact me at carlos.antollini@nixorcorp.com
Carlos Antollini.
|
|
|
|
|
Are there any reusable datetime classes that are freely distributed.
I'm currently using the tm struct & CTime in MFC to work with dates.
I'm looking for a good datetime class with validation on dates built-in.
Thanks,
Gerry.
|
|
|
|