|
ThatsAlok wrote:
Why are you going after OLD C method such like creating your own link list and other collection, when there are dozens of Collection classes available in market such as STL or MFC Collection classes, that are much more optimized and fast.
You just have to implement you structure in that collection classes!.
I knew I was doing something wrong. That’s why I stopped at a certain point and said wait a minute, there has to be a better way. Can you point me to something explaining structures in collection classes?
Thank you
-------------------------------
|
|
|
|
|
Look for the STL (Standard Template Library) collection classes. The vector class behaves like a dynamically expandable array, if you want linked list like behaviour, there is the list class and so on. Using those classes is very simple.
vector <YourStruct> v;
You can then use methods on v to add and remove elements from the collection.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Sorry if I'm being a little dense here but still not clear. I understand that Arrays, Vectors, Linked Lists are all good for housing data. The thing I need is multiple columns.
If I may be so bold to speculate but to do what I need would I create a class to wrap together the collections and access the data via member functions? Or is there a pre written object?
Your example was hidden.
So could I do something as simple as?
(Sorry pseudo code here, I'm not anywhere near my developing environment)
<br />
struct WORKORDER <br />
{<br />
int WorkOrder; <br />
CString Date;<br />
Cstring SiteNumber;<br />
Cstring SiteContact;<br />
...<br />
} <br />
<br />
vector <WORKORDER> v;<br />
Referencing the data members like so
Int iWo = V[0].WorkOrder
I'm not opposed to doing a little work. I just don’t want to do work that’s well incorrect. Thanks for the help.
-------------------------------
|
|
|
|
|
Yes, you're on the right track. A vector can be used as a collection of *anything*, even a collection of vectors etc. So yes, you could store a collection of instances of your structure, so you'd get the multi column array functionality you wanted.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Ah okay, so its no where near as complicated as I was thinking.
Man, You and everyone else who helped are life savers.
-------------------------------
|
|
|
|
|
Yes, that's it. You create a structure that contains all the fields for one 'worker' (so contains all the data for one 'row'). And then you can use the vector:
std::vector<WORKORED> YourVector;<br />
WORKORDER Data;<br />
YourVector.push_back(Data);<br />
Then, to retrieve one data of the vector:
WORKORDER Data = YourVector[0];
Then you can work with the structure.
|
|
|
|
|
cedric moonen wrote:
Yes, that's it. You create a structure that contains all the fields for one 'worker' (so contains all the data for one 'row'). And then you can use the vector:
std::vector<workored> YourVector;
WORKORDER Data;
// Fill Data
//
//
YourVector.push_back(Data);
// Fill other structures
//
//
Then, to retrieve one data of the vector:
WORKORDER Data = YourVector[0];
Then you can work with the structure.
Perfect! Just what I needed to make the necessary connections in the old Gray matter.
Thank You, Cedric.
-------------------------------
|
|
|
|
|
sfdougl wrote:
Can you point me to something explaining structures in collection classes?
Yeap, just check out this link :-
http://www.codeproject.com/vcpp/stl/[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Thanks for the reading material. Your help is appreciated.
-------------------------------
|
|
|
|
|
ThatsAlok wrote:
sfdougl wrote:
Can you point me to something explaining structures in collection classes?
Yeap, just check out this link :-
http://www.codeproject.com/vcpp/stl/[^]
I found an article in the STL that explains Vectors quite well. Thought I would post it in case some else has this same problem.
A Presentation of the STL Vector Container - STL[^]
Thanks Everyone for you help.
-------------------------------
|
|
|
|
|
Alright, I'll take a stab.
The most simplistic form of a record is that provided by an C-structure, it has the advantage of being a fixed size (speed of access). It also means that it may waste memory, because irregardless of the actual size required, you have to allocate enough memory to store (a fixed size for) each record..
You can create a class that reads a record on a per-field basis....
I am sorry, but I can't explane more at this time (it is almost 4AM and my brain just locked up).
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
John R. Shaw wrote:
The most simplistic form of a record is that provided by an C-structure, it has the advantage of being a fixed size (speed of access). It also means that it may waste memory, because irregardless of the actual size required, you have to allocate enough memory to store (a fixed size for) each record..
Thanks John,
If I understand your post correctly that’s more or less what I did initially to solve the problem. A struct controlled by a class, but it just “felt” incorrect.
John R. Shaw wrote:
I am sorry, but I can't explane more at this time (it is almost 4AM and my brain just locked up).
Don’t worry, I have been toiling over this for a few days now. I'm in no real hurry, the boss is used to me laughing at his ridiculous deadlines.
Thanks for you input.
-------------------------------
|
|
|
|
|
|
Okay, will do, Thanks Ravi
-------------------------------
|
|
|
|
|
create a new mfc sdi project, in onDraw fuction add the following:
pDC->SetDCPenColor(RGB(0,0,0));
when compile, this error happens:
error C2039: 'SetDCPenColor' : is not a member of 'CDC'
according to msdn, CDC has this member. when i input these, there is even a auto completion.
how could this happen?
|
|
|
|
|
Requirements
Windows NT/2000/XP: Included in Windows 2000 and later.
Windows 95/98/Me: Unsupported.
1) Are you using Win 9x?
2) The code for SetDCPenColor is wrapped using
#if (_WIN32_WINNT >= 0x0500)
so you'd need to set the _WIN32_WINNT constant to at least 0x0500 (which should be the constant for Win2K) in the stdafx.h file in your project.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
Painted on the side of a dog trainer's van: SIT HAPPENS
|
|
|
|
|
set 0x0500 works.
thanks.
|
|
|
|
|
What version of the IDE are you using, because SetDCPenColor() does not exist.
CPen pen(PS_SOLID,1,0);
CPen* pOldPen = pDC->SelectObject(&pen);
... draw something
pDC->SelectObject(pOldPen)
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Ok- basic question:
Ive downloaded source files and the accompanying .ocx file for use in a basic visual c++ project. The .ocx file works.
Now- when i edit the source files a bit to add new functuality, how the heck do I recompile them using visual studio into a brand new .0cx file??? Im lost on this aspect.
rich
|
|
|
|
|
The same way you would any other program or dll.
If it came with a VC project file then that should not have a problem.
If it did not and it is VC code, you could try:
1) Create a new ALT COM AppWizard project, with the same name as the current ocx.
2) Add your files to the project. This will involve replacing the app-wizard generated files with your files.
3) Goto the project settings, find output file name (under the link tab) and replace the .dll extension with the .ocx extension.
4) Compile.
Suggestions (before you try above):
1) Create a simple ocx project, to get used to the process.
2) Try the above with copies of the original files, before using your modified files.
P.S. Andrew W. Troelsen is the author of a book on creating ALT COM (ocx) controls.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
1) Compile UNICODE version of app.
2) Copy character U+0428 from Character Map program.
3) Paste character in edit control, no problem.
4) Paste character in rich edit control, no problem.
5) Get text from edit control (TCHAR txt[128]):
txt[0] = 1064, txt[1] = 0;
6) Get text from rich edit control (TCHAR txt[128]):
txt[0] = 63, txt[1] = 10, txt[2] = 13;
Ok! What happened here?
The reverse is also true:
1) Set text in edit control (t[0]=1064,t[1]=0), no problem
2) Set text in rich edit control (t[0]=1064,t[1]=0), a problem. It displays '?', which is character 63.
Any ideas?
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Maybe try calling EM_GETTEXTMODE and find out if the contorl somehow got set to using ANSI instead of Unicode. It seems that thecontorl might accept any text, but when you retreive the text, it will return text in the format set with EM_SETTEXTMODE . Also, perhaps text should bet set to it with EM_SETTEXTEX instead of WM_SETTEXT .
|
|
|
|
|
Thanks! There does not seem to be a wrapper in the MFC control class for that one.
Text mode = TM_MULTICODEPAGE|TM_SINGLELEVELUNDO|TM_RICHTEXT;
The only thing I can determine from that, is that text is in richtext format. I believe that the rich edit control is entirely UNICODE internaly.
I am using GetRichEditCtrl().ReplaceSel(_T("some text")) only, to send text to the control.
I am using GetRichEditCtrl().GetLine(0,ubuf,128) only (as test), to get text from the control.
GetLine() retrieves wchar_t characters, but they are being translated to ANSI characters, when copied to the wchar_t array passed as an argument.
There is the possibility that it is a local problem, but that makes no since.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
|
I was just wondering, what is the proper way to embed data files within an exe in the VC++ development enviornment. I'd like to do it in a way that would allow the data to be accesed with a simple pointer if possible.
|
|
|
|