|
tsk. Tomasz, you just made me use STL for the first time. I lost my STL virginity.
I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
FYI, so you can rip it to pieces (and I know you're gonna hate the CString):
std::map<CString,int> l;
map <CString, int> :: const_iterator matching_item;
l.insert( map <CString, int> :: value_type ( CString("bob"), 20 ));
l.insert( map <CString, int> :: value_type ( CString("alf"), 23 ));
l.insert( map <CString, int> :: value_type ( CString("fred"), 19 ));
l.insert( map <CString, int> :: value_type ( CString("steve"), 12 ));
l.insert( map <CString, int> :: value_type ( CString("stu"), 45 ));
l.insert( map <CString, int> :: value_type ( CString("jon"), 2 ));
l.insert( map <CString, int> :: value_type ( CString("jim"), 543 ));
matching_item = l.find ( CString("jon"));
int d = matching_item->second;
thanks for your help!
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Am i right in thinking that I can use any of my own defined classes in STL? provided I include things like comparison operators, etc etc ??
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Yes. AFAIR, std::map requires only operator < - it's actually a tree, while MFC maps are hashtables.
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Jon Hulatt wrote:
know you're gonna hate the CString
I'm not going to hate CString. If something works, let it work
Just FYI, STL has the std::string class.
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Tomasz Sowinski wrote:
Just FYI, STL has the std::string class
This much I know. But the app is heavily MFC right now; CFile, CStdioFile, CAsyncSocket, etc etc.
What i'm using the map for is to turn mime-type strings into default file extensions. I'm now using a <CString,CString>> pair for the map, the first is the type (eg. CString("application/x-msword")) and the second is the default file extension (eg. CString("doc")). My source data, which ultimately came from a Socket, is currently in a big char buffer. But I can't see that std::map<LPCSTR,LPSTR> would do what i wanted, because two pointers to "application/x-msword" point to the same data, but probably in different places, so the internal comparisons won't work.
Really, I probably should never have used char buffers. But I understand them, whereas this STL thing is new to me (i've avoided it for as long as possible!!!). So, in the short term for this project, since it's use of MFC already means it runs like a lubricated turd, I might as well just make life easier by creating a CString out of my LPCSTR.
thanks again
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Jon Hulatt wrote:
I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
I think I found my new sig.
I'll just mention that it's easier to insert into a map like this:
l[CString("bob")] = 20;
l[CString("alf")] = 23;
You can also extract like this, but the downside is if the item you try to extract does not exist, it will be created, so you need to do this:
if (l.end() != l.find(Cstring("bob")))
assert(20 == l[CString("bob")]);
You've inspired me, I'll finally pull it together and write my set/map article today.
P.S. when you post STL code or anything else that uses templates, don't forget to turn off HTML in the post, so all the code is posted.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Could anyone give some indication about interpreting the nSide parameter of OnSizing (WM_SIZING) in a MFC application?
It looks like taking random values.
rechi
|
|
|
|
|
Works as advertised on my machine. Are you getting values other than WMSZ_xxx flags?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
I get WMSZ_xxx flags in strange combinations.
For example, i use top-right corner to resize and i get WMSZ_BOTTOMLEFT activated. It doesn't have any sense for me.
rechi
|
|
|
|
|
Strange. I can't reproduce it here. Did you override WM_NCHITTEST?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
I didn't do anything but writing OnSizing for a dialog window.
rechi
|
|
|
|
|
I'm tested this with dialog - and everything works OK. Are you using some 3rd party resizable dialog class?
BTW: you don't have your monitor rotated 180 degrees, do you?
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
It's an ordinary resizing dialog.
The combinations are so confusing that it shouldn't work even if i would rotate the TV 180 degrees.
rechi
|
|
|
|
|
What do you mean by 'combinations'? WMSZ_xxx are not bit flags - they're just numbers from 1..8 range. If you're using bitwise operators for testing, you may get strange results.
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Now it's clear; i've been using them as bit flags.
Thanks!
rechi
|
|
|
|
|
beginner
hi im trying to get this code to work, so it would create a table with the alphabet and then allow me to access it using a cipher technique called vigenere. most of the code below is a mess and i cant make sense of it
any help would be appreciated
//fill- create a table 26 by 26 with the alpabet in each row
for (row= 0; row<=25; row++)
{
for (col=0; col=25 =; col++)
{
ch++; ch> 'z'; ch = 'a';
}
}
// access
m_typed = table[row][key]
|
|
|
|
|
I have to change the color if a item on list control, once the user does a double click on it. I have handled the double click and i have the item and subitem details. How can i go abt after this to chage the color of that item
Ganesh M Ramaswamy
|
|
|
|
|
If you want items to have different colors, you'll need to custom-draw the list control. There should be articles about that right here on CodeProject - look in the 'List Control' section.
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
Yeah.But the thing is i am not getting a WM_CUSTOMDRAW when double click is made on list control. Am i missing something. Should i get WM_CUSTOMDRAW for double click on item also. thanks for ur time.
|
|
|
|
|
Try to invalidate item rectangle. You can get it from CListCtrl::GetItemRect.
Tomasz Sowinski -- http://www.shooltz.com ** If you're going to rape, pillage and burn, be sure to do things in that order. **
|
|
|
|
|
|
Hi!
I made an ATL composite control with ATL wizzard .
I want to place my custom draw slider on it . In the slider class it is defined
BEGIN_MESSAGE_MAP(CClipSlider, CSliderCtrl)
...
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdraw)
It seems that the parent ATL control does not reflect the message NM_CUSTOMDRAW
How Can I make this to work???or other way to have my custom draw slider??
Thankx
xxx
|
|
|
|
|
REFLECT_NOTIFICATIONS needs to be in your parent window class and REFLECTED_NOTIFY_CODE_HANDLER needs to be in your child window class.
ON_NOTIFY_REFLECT is from MFC.
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?
|
|
|
|
|
Call GetDocument() from your view classes to get a pointer to your document class and call GetActiveView() from the main frame window class to get a pointer to the active view. Also use GetNextView() from the doc class to iterate through all your views
Nish
One Nish is trouble enough.
Imagine 16 of me, dancing wild...
:jig::jig::jig::jig:
:jig::jig::jig::jig:
:jig::jig::jig::jig:
:jig::jig::jig::jig:
|
|
|
|
|
sory,but i dont understand:i have a SDI app,and lets say member variable
int x
in CTestView class,and i want to load variable
int y
in CTestDoc class with x and do something with y,for example
y+=10;
How to do that?i need this for some ODBC code when using CRecordset *m_pSet from CTestView in CLeftView and CTestDoc
classes.
|
|
|
|