|
friend bool operator<(const CData &l, const CData &r)
This is wrong. Now you have no CData objects inside the set but pointers, or more precise - integer values [addresses]. So the usual address [integer] comparision takes place.
You can pass a comparator to the set ctor. A comparator is an object that acts as a function;
struct cmp
{
bool operator () (const CData *p, const CData *q)
{
if (p->priority_) return true;
return p->priority_ == q.priority_ && p->group_;
}
};
typedef std::set < CData*, cmp > DataCollecton_t;
--
=====
Arman
|
|
|
|
|
Thanks for all the replies Arman!
i will try it out.
thanks again!
newbie
|
|
|
|
|
If you store pointers in a set, the set is ordered by the pointer values (the addresses) and not by the values of your objects. You can either provide a customized comparer function object as the second template parameter or use the boost::ptr_set.
Regards,
Tim
|
|
|
|
|
You have to pass your own comparer function object , otherwise the set will use the standard pointer comparison one (based on their addresses). I made a little test. Code is not elegant but it shows the point
class Atest
{
friend struct comp;
public:
Atest(int i, char c)
{
_i = i;
_c = c;
}
bool comp( Atest * pb)
{
return ( _c < pb->_c) ? true : false;
}
void dump(FILE * fp)
{
fprintf(fp, "{%d,%c}\n", _i, _c);
}
private:
int _i;
char _c;
};
struct comp : public binary_function<Atest *, Atest *, bool>
{
bool operator()(const Atest * pa, const Atest * pb) const
{
return (pa->_c < pb->_c) ? true: false;
}
};
int main(int argc, char* argv[])
{
Atest at1(5,'v'), at2(6,'a');
std::set< Atest *, comp> s;
s.insert(&at1);
s.insert(&at2);
std::set< Atest *, comp>::iterator it;
for (it = s.begin(); it != s.end(); it++)
{
(*it)->dump(stdout);
}
return 0;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks Pallini and Tim!
i will try to write some code using what u have posted.
thanks!
newbie
|
|
|
|
|
Hi
in vc++, In my application i am showing my data in list control box from data bases , now my requirment is that when i double click on an individual
data in list box an specific event is fired.
i am using LBN_DBLCLK but its not work properly. can any one told me
how we can do this
Regard's
Kaushik
|
|
|
|
|
Y_Kaushik wrote: i am using LBN_DBLCLK but its not work
Why it didnt work can you explain more?
|
|
|
|
|
Guruji
In this case suppose 10 item come from database suppose its iD
10
11
12
13
20
Now my requirment is that when i bouble click 10 a specific action perform and when double click 11 action perform for id 11 but
in my case its fail
so can u told me in detail
Regard's
Kaushik
|
|
|
|
|
Do you need to this code?
void CDialogDlg::OnLbnDblclkList1()
{
switch(m_List.GetCurSel())
{
case 0:
MessageBox("A");
break;
case 1:
MessageBox("B");
break;
case 2:
MessageBox("C");
break;
}
}
if its not your answer can your more explain,please
|
|
|
|
|
Hi
MSDN says
This message is sent only by a list box that has the LBS_NOTIFY style.
|
|
|
|
|
Y_Kaushik wrote: i am using LBN_DBLCLK but its not work properly.
Why not? Remember, the quality of answer you receive is directly proportional to the amount of relevant information that you provide.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have a populated multiline edit control. I wish to read one line at a time from it and do some manipulation on it. According to CEdit documentation on MSDN i have implemented the logic as below:-
LRESULT l_numEvents = ::SendMessage(hwnd, (UINT)EM_GETLINECOUNT, 0, 0);
LRESULT llinelength = ::SendMessage(hwnd, (UINT)EM_LINELENGTH, index, 0);
//Set the first word of this buffer to the llinelength, in TCHARs, of the buffer
<br />
<br />
llinelength = ::SendMessage(hwnd, (UINT)EM_GETLINE, index, (LPARAM)(LPCTSTR)tbuffer);<br />
<br />
I wish to know how do i set the first word of this buffer to llinelength of the buffer.
|
|
|
|
|
Like this...
WORD llinelength = ::SendMessage(hwnd, (UINT)EM_LINELENGTH, index, 0);
*((WORD*)tbuffer) = llinelength;
|
|
|
|
|
tom groezer wrote: I wish to know how do i set the first word of this buffer to llinelength of the buffer.
*(LPINT)tbuffer = llinelength;
SendMessage(hwnd, EM_GETLINE, index, (LPARAM)tbuffer);
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi, everyone!
I want to realize an application which can get file's content through dragging mouse. Now I had get the list of files in a list-control. How to realize this function? Plz give me some idea. Thx!
|
|
|
|
|
Do you want to see content of files when they are dragging on your program?
|
|
|
|
|
No. I need to develop an application which can take a file from PDA to PC. The file saved in PDA had been listed in a list-box of my program. When the user drag an icon of a file from the list-box to desktop, my program get the file's name and then get it from PDA. That's all I must develop.
|
|
|
|
|
I had known I must use the API:DoDragDrop(). But I don't know how to implement the interface of IDataObject and IDropSource. Would u be kind to give me some advice? The context of this calling of DoDragDrop is in a Dialog. So whether I must add declerations of IDataObject and IDropSource in the header file as I do in C#? I need some help. Thx!
|
|
|
|
|
|
Thx for you introduce me this article. But I want to know more knowledge about this. Because my goal is to drag file into desktop, I wonder this method can't work.
|
|
|
|
|
Well I saw your answer previous drag with explorer or destop of a program on the codeproject you need to search.;)
|
|
|
|
|
i have a CDialog ,1 button for print i have a print but i need a button for print preview !How i have read all codeproject stuf but nothing ...
this is my code for print :
CPrintDialog dlgPrint(FALSE,PD_ALLPAGES,this);
if (dlgPrint.DoModal()==IDOK)
{
// ** Attach the printer DC from the dialog
// ** to a CDC object
CDC dcPrint;
dcPrint.Attach(dlgPrint.GetPrinterDC());
// ** Create and fill a DOCINFO structure
DOCINFO myPrintJob;
myPrintJob.cbSize = sizeof(myPrintJob);
myPrintJob.lpszDocName = "MyPrintJob";
myPrintJob.lpszOutput = NULL;
myPrintJob.lpszDatatype = NULL;
myPrintJob.fwType = NULL;
// ** Start the printing document
if (dcPrint.StartDoc(&myPrintJob)>=0)
{
// ** Start a page
dcPrint.StartPage();
CString sQuestion;
m_question.GetWindowText(sQuestion);
CString sText;
sText = "Command";
CString sText1;
sText1 = "Display :";
////////////////////////////////////////////////////////////////////////////////////////
dcPrint.TextOut(2000,350,sText);
dcPrint.TextOut(300,500,sText1);
// ** Throw the page
dcPrint.EndPage();
// ** Close the document
dcPrint.EndDoc();
}
// ** Delete the printer device context
dcPrint.DeleteDC();
}
Bravoone
|
|
|
|
|
|
No i need something more easy...is to hard for me !you see my code for print ?! i need something like that ...easy not so complicate !can you help me ?!
Bravoone
|
|
|
|
|
some times ago (I think two years ago) I had this problem I wanted to have a preview before print so I explain for you but before it(you can also use of printer driver if you dont have a real printer or dont access to it see this thread[^] ) I calculate dimension for pages like A4,A3,... and convert to screen and then use of a handle to display device context (hdc) sent my datas with BitBlt to screen and it worked and finaly sent my datas to printer like this
PRINTDLG pd;
...
m_Image.BitBlt(pd.hDC,100,134,640,480,0,0,SRCCOPY);
|
|
|
|