|
has anyone ever seen a wrapper for a list control or tree control that can act as an STL container?
i'm dealing with a CListCtrl right now, and i noticed that it would be great to be able to do something like:
foreach(m_listCtrl.begin(), m_listCtrl.end(), do_something_with_selected_items);
or, to load items:
m_listCtrl.insert(lvitem);
m_listCtrl.push_back(lvitem);
you could treat a list control as a vector. and you could treat a CTreeCtrl as a tree (duh) of some kind. maybe you could sort the list control with std::sort, etc..
i don't need this functionality, i just thought it would be a really slick bit of code.
-c
Image tools: ThumbNailer, Bobber, TIFFAssembler
|
|
|
|
|
It would be a nice contribution (volunteers? ). Anyway, I think this should be modelled after std::list rather than std::vector .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
if i knew anything about the internals of an STL container, i would've written it myself before giving away the idea. maybe i'll take a look at your map for inspiration
-c
Image tools: ThumbNailer, Bobber, TIFFAssembler
|
|
|
|
|
Chris Losinger wrote:
has anyone ever seen a wrapper for a list control or tree control that can act as an STL container?
How about this:
WINSTL[^].
-Nick Parker
|
|
|
|
|
|
Another way to look at this is to turn it on its head and say use a virtual list box which accessed items directly in the STL vector etc.
There are many advantages to this approach. eg. No parallel copies of the data to maintain and keep in sync, faster population of the control as it doesn't need to copy the data, more efficient memory use etc.
I've written a tree control that works like this. It uses an abstract container class to request the items it needs to display, and has absolutely no knowledge of where the data elements live or what they are. You can see this in the ClassView, Ascii Chart and Skeleton trees in ED.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
NEw custom property pages should be added to the device manager's property sheet using WTL. I used CPropertyPageImpl<> base class for this. Property page is not being displayed. IF new tab in the devicemanager prperties dialog box is clicked application is crashing.
Rajani
|
|
|
|
|
Hi there,
I am working on CStatic control of VC++. I want to load Bitmap on the CStatic control with Transparent Background. For that I have created the Object of CBitmap. But It seems that CBitmap is not having transparent property. Can anybody show me the way, how to make CBitmap object transparent? I am creating Bitmap with CretateBitmap() method and after that I am Loading Bitmap to the CBitmap Object with LoadBitmap() method. These are the basic steps required to load Bitmap to the newly created Bitmap, but I don't know how to make it Transparent? Is there anybody who knows the trick? Please, show me the way...
Thanx in Advance,
Regards,
Kav
India
|
|
|
|
|
|
Hello everybody:
I was wondering if ther is a way to use the cin.getline() function when you use string objects. With the code snipet below I get the following error:
error C2664: 'class std::basic_istream<char,struct std::char_traits<char> > &__thiscall std::basic_istream<char,struct std::char_traits<char> >::getline(char *,int,char)' : cann
ot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
hwproject.exe - 1 error(s), 0 warning(s)
I always encounter this problem and I don't know what to do to solve this. Is there a better way to do this with string objects? Can you tell me what I did wrong with the code below? Any answer is more than welcome.
#include <string><br />
#include <iostream><br />
using namespace std;<br />
<br />
void main()<br />
{<br />
int itemNum;<br />
string Desc;<br />
cout << "Enter Item Number: ";<br />
cin >> itemNum;<br />
cout << "Enter Description: ";<br />
cin.getline(Desc, sizeof(Desc), (char)"\n");<br />
}
Luis E. Cuadrado
)
|
|
|
|
|
One solution is std::getline().
string sInput;
std::getline(cin, sInput);
Kuphryn
|
|
|
|
|
Thanks for replying Kuphryn. I gave it a try and the program complies but when I run it, the variable where I store the value using the std::getline() function doesn't show up when I use cout.
#include <iostream>
#include <string>
using namespace std;
void main()
{
string itemID;
string Desc;
cout << "Enter ID: ";
cin >> itemID;
cout << "Enter Description: ";
getline(cin, Desc);
cout << "itemID: " << itemID << endl;
cout << "Desc: " << Desck << endl;
}
This is the output that I got.
Enter ID: 222
Enter Description: matches
itemID: 222
Desc:
I'm asuming that there are some kind of garbage collecting thing that I have to do here, is it? Let me know what you think.
Thanks for your help,
Luis E.
Luis E. Cuadrado
)
|
|
|
|
|
Hola Luis,
There are two problems, one of them is not your fault:std::getline is broken in MSVC++ 6.0. See here[^] for a fix.
- (this assumes you've installed the previous fix) After reading the
int , there are extra characters pending to be read in the first line (at least, the terminating '\n' ): eat this before going for the description:
#include <iostream>
#include <string>
using namespace std;
void main()
{
string itemID;
string Desc;
cout << "Enter ID: ";
cin>>itemID;
cout << "Enter Description: ";
getline(cin, Desc);
getline(cin, Desc);
cout << "itemID: " << itemID << endl;
cout << "Desc: " << Desc << endl;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hola Joaquín,
Thank you for your response. I did exactly what you told me and it works. Thank you for pointing me out to that Microsoft site and for your help.
Another question that I have is, if I want to do that in a loop. Do I need to flush or wipe-out the stream that I'm using? The reason that I'm asking is that I put everything in a loop except the cout statements and the loops keeps going and it doesn't stop. I step over the code and I noticed that there still data, aparently in the stream. Have you experience this before?
Thanks,
Luis E.
Luis E. Cuadrado
)
|
|
|
|
|
I have the STL distributed with VC6, but I need a fixed version that doesn't leak memory and resources like that one does.
Does anyone know of any other (preferably free) replacement libraries?
I have tried STLPort (which improved resource leask but increased memory leaks) and I have tried SGI, but that wouldn't compile. Any other ideas?
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Derek Lakin wrote:
need a fixed version
Do you have tried the fixes from Dinkumware[^]?
They also sell a STL, I think. But I have never tried that.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Thanks for the link . Sometimes you can overlook the most obvious solutions
I'll try it out and let you know how I get on.
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
I tried all of the fixes and it made things worse, so I used all the fixes apart from the stream-related ones and it improved the problem drastically.
Still not all fixed though
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
What type of problems do you have? Where are you leaking memory?
For me, std::string seems sometimes to have those problems, but it has never been so bad that I have to fix it, that is, you can't see it in 'Task Manager', but VC++6 complains.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
The problems I had experienced were mainly danlging pointer errors.
Since first trying the fixes I have since removed those related to streams and have now managed to completely erradicate any errors
I'm just left now with 2 small memory leaks (1,864 bytes), which aren't STL related, and 16 resource leaks that aren't really leaks, it's just that DevPartner Studio picks them up on application exit, but they get freed when the MFC libraries are unloaded.
Thanks for your help
Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.
Salamander Software Ltd.
|
|
|
|
|
Derek Lakin wrote:
The problems I had experienced were mainly danlging pointer errors.
ahh.. BoundsChecker complaints? i'm not sure those problems are actually problems. BC complains about a lot of stuff that isn't a real problem.
-c
Image tools: ThumbNailer, Bobber, TIFFAssembler
|
|
|
|
|
Derek Lakin wrote:
which improved resource leask but increased memory leaks
Depending on a define STLPORT will hold a chunk of memory until the progam ends to improve the speed of allocations. This will look to memory leak tooks as a real leak but it is not. There are a couple of discussions in their forum about this topic. Here is one: http://www.stlport.com/dcforum/DCForumID6/1181.html[^]
John
|
|
|
|
|
**[EDIT] Figured out how to do it myself. [/EDIT]**
Hey, I was looking at the IE Deskband Tutorial and it shows how to add a button to your deskband. But I am not sure how to add another button to this, can anyone help me out? THanks.
Here is what is in the tutorial:
TCHAR* pCaption = _T("Get Quote");<br />
int iIndex = ::SendMessage(m_hWnd, TB_ADDSTRING, 0,(LPARAM)pCaption);<br />
<br />
HICON hMotley = LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_MOTLEY));<br />
m_hImageList = ImageList_Create(16,16, ILC_COLOR16, 1, 0);<br />
int iImageIndex = ImageList_AddIcon(m_hImageList, hMotley);<br />
DestroyIcon(hMotley);<br />
::SendMessage(m_hWnd, TB_SETIMAGELIST, 0, (LPARAM)m_hImageList);<br />
<br />
TBBUTTON Button;<br />
ZeroMemory((void*)&Button, sizeof(TBBUTTON));<br />
Button.idCommand = IDM_GETQUOTE;<br />
Button.fsState = TBSTATE_ENABLED;<br />
Button.fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT;<br />
Button.dwData = 0;<br />
Button.iString = iIndex;<br />
Button.iBitmap = 0;<br />
::SendMessage(m_hWnd, TB_INSERTBUTTON, 0, (LPARAM)&Button);<br />
|
|
|
|
|
I have a calss that have a member variable of type ofstream, I would like to initialize this variable in constructor.
MyClass
{
MyClass(ofstream& Logger) { m_Logger = Logger; }
private:
ofstream m_Logger;
}
But seems like there is no assignment operator for ofstream.
Any idea how can i do this?
|
|
|
|
|
Anonymous wrote:
MyClass<br />
{<br />
MyClass(ofstream& Logger) { m_Logger = Logger; }<br />
<br />
private:<br />
ofstream m_Logger;<br />
}
Why not using
MyClass<br />
{<br />
MyClass(ofstream& Logger) { m_Logger = Logger; }<br />
<br />
private:<br />
ofstream& m_Logger;<br />
}
instead ... Using a reference is even faster than creating a new stream...
Greeting, Ralph
|
|
|
|