|
It seems to be so easy to use in this case "CString::MakeReverse()" that I tought there should be some tricky stuff.
|
|
|
|
|
How do you delete all items in a CListBox object?
|
|
|
|
|
I believe you are looking for MyListBox.ResetContent();
-Jack
To an optimist the glass is half full.
To a pessimist the glass is half empty.
To a programmer the glass is twice as big as it needs to be.
|
|
|
|
|
Yes that's the one
Thanks!
|
|
|
|
|
I need some help with sort function in Visual C++.
Here is the situation :
I have a variable "m_strEditData" whose type is CString. I want to sort the string and move the data to another CString "m_strResultData".
I want this to be an inline code and not called as a function. Can anyone help me with this?
Greatly appreciated.
M
|
|
|
|
|
Do you mean sorting the characters your string is composed of? If so, this should do:
#include <algorithm>
...
m_strResultData=m_strEditData;
int nLength=m_strResultData.GetLength();
LPSTR buffer=m_strResultData.GetBuffer(nLength);
std::sort(buffer,buffer+nLength);
m_strResultData.ReleaseBuffer();
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you.
The Sort worked but as I was testing I rank into a situation (explained below). Is there a way to solve it.
Input data---> acbde
After sort function---> abcde
This is fine. But if I enter in input data
Input data----> This is my dog
Output ===> Sort all the characters together.
Is there a way to just sort only on the first character.
The result of my example after the sort would be :
"dog is my This".
Is this easily possible?
Thank you
M
|
|
|
|
|
This can be done, but involves a little more work. Here's an outline of the method:
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
...
std::vector<std::string> v;
std::istringstream istr((LPCSTR)m_strEnterData);
for(;;){
std::string s;
istr>>s;
if(s.empty())break;
v.push_back(s);
}
std::sort(v.begin(),v.end());
m_strDisplayResult="";
for(std::vector<std::string>::const_iterator it=v.begin();
it!=v.end();
++it){
if(it!=v.begin())m_strDisplayResult+=" ";
m_strDisplayResult+=it->c_str();
} (Sort of, I haven't compiled this.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you. I am going to review it and try to understand it.
I am not familiar with Vector operation but I am excited about learning it. I have a book. I will read more and will let you know.
Thank you
M
|
|
|
|
|
Thank you. I am going to review it and try to understand it.
I'm glad you decided to do so. STL can help you be more productive and write more robust code. Usually, trying to do this kind of things by hand results in off-by-one errors and mistakes like that.
In case you're interested, Christian Grauss has written several tutorials on different aspects of STL. Check them out at the STL section here at CodeProject. Good luck!
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
Which function in CListBox returns the selected items textstring?
|
|
|
|
|
CString buff;
GetText(GetCurSel(), buff);
GetSelCount(); will return the number of selected items in a listbox if it's a multi-selection enabled.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Thanks
|
|
|
|
|
CListBox::GetText;
CString str;
m_list.GetText(m_list.GetCurSel(),str);
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
Anyone knows a homepage with downloadable CRC64/CRC128/CRC256 C/C++ source code?
Thanks
Dominik
|
|
|
|
|
Hi All,
Is there a trick to handeling windows messages in a CButton derrived class that is owned by a CView Class??
Right now I am handeling the messages in the CView class, and I am finding it to be messy code that is not very OOP.
Any help is appreciated.
Thanks, Paul
|
|
|
|
|
Anonymous wrote:
Right now I am handeling the messages in the CView class, and I am finding it to be messy code that is not very OOP.
That's MFC for ya. What messages are you handling? It is possible to use message reflection to handle many messages in the CButton -derived class if that would be appropriate.
--------
People they come together
People they fall apart.
No one can stop us now
'cause we are all made of stars... -- Moby, We are all made of stars
|
|
|
|
|
WM_MOUSEMOVE is the message I was hoping to handle.
Started reading about reflections, but wasn't sure if that was what I needed. Is it as simple as adding an ON_WM_MOUSEMOVE_REFLECT() message handler to my CButton class? Probably NOT !!
Do I need to do anything to set up the parent window??
Thanks again
|
|
|
|
|
Anonymous wrote:
WM_MOUSEMOVE is the message I was hoping to handle.
Oh, well that's sent directly to your button anyway, so you should have no problem handling it in your CButton -derived class. The only thing i can think of that might get tricky with this would be if you wanted to know when the mouse was moved outside of the button, since you'll no longer recieve messages then. Two solutions to this are mouse capture (if the user will be holding a mouse button down) or setting a timer and periodically checking the mouse position (appropriate for "hot tracking", etc.).
--------
People they come together
People they fall apart.
No one can stop us now
'cause we are all made of stars... -- Moby, We are all made of stars
|
|
|
|
|
Hmmmm
Actually it's a CBitmapButton derrived class, but I don't believe that would matter.
This is how I created it in the view class
fbOpen.Create(_T(""), BS_OWNERDRAW, rect, GetSafeOwner(), IDC_NEW_BUTTON)
and this is my message handler in my derrived class
void CBitmapFlipButton::OnMouseMove(UINT nFlags, CPoint point)
{
AfxMessageBox("The Mouse has moved, Yahoo !!",
MB_OK);
CButton::OnMouseMove(nFlags, point);
}
Please let me know if something is wrong. Otherwise I will keep searching for an example.
Thank you for you time shog, and every one else posting.
|
|
|
|
|
Anonymous wrote:
and this is my message handler in my derrived class
And it isn't getting called? Check the message map i guess, otherwise it looks fine.
--------
People they come together
People they fall apart.
No one can stop us now
'cause we are all made of stars... -- Moby, We are all made of stars
|
|
|
|
|
Figured it out with spy++
Didn't get any WM_MOUSEMOVE messages until the cursor was over the titlebar.
Changed the buttons create function to use the this pointer inplace of GetParent() for the pParentWnd parameter and it seems to be working. Hope there are no side effects.
|
|
|
|
|
|
why ReleaseDC is not saving my information.
|
|
|
|