|
Thanks, that did the trick. Guess you can tell I'm new at this. Seemed obvious once you provided the answer. Of course, doesn't it always?
Thanks again for the speedy reply.
|
|
|
|
|
Hi,
Can anyone explain the following problem, to do with CArray and CPtrArray?
My member variables are:
CArray<CMyClass,CMyClass> m_objects;
CPtrArray m_pointers;
I try to initialize them like this:
for(int i = 0; i < 5; i++){
m_objects.Add(CMyClass());
m_objects[i].m_nMember = i;
m_pointers.Add((void*) &m_objects[i]);
}
In my paint function, I just loop through the pointers, cast them and output the value of m_nMember. Like this:
for(int i = 0; i < m_pointers.GetSize(); i++){
int value = ((CMyClass*) m_pointers.GetAt(i))->m_nMember;
//draw value to the screen
}
I'd expect the output to be: 0 1 2 3 4, but it's not; 1 to 4 are always correct, but the first value is always nonsensical.
I was able to solve the problem by using a different initialization:
for(int i = 0; i < 5; i++){
m_objects.Add(CMyClass());
m_objects[i].m_nMember = i;
}
m_pointers.SetSize(m_objects.GetSize());
for(i = 0; i < m_objects.GetSize(); i++){
m_pointers.SetAt(i, (void*) &m_objects[i]);
}
But still I would like to understand why the first approach doesn't work. Anyone have a clue? Is it a bug or something?
Thanks,
Tom
|
|
|
|
|
The CArray is a dynamic array. If you add data to it and the currently allocated memory is already full, the storage is reallocated and the data are copied to the new memory (using copy constructors for classes).
Because you have not specified the length of the array in advance, the initial length was only 1 and the array was reallocated before inserting the second item - so your first pointer points to nowhere => it's wrong to use pointers to container data this way.
Also it is good practice to allocate the array using SetSize(), if you know the required size in advance.
Pavel
Sonork 100.15206
|
|
|
|
|
Can Anyone tell me how to call Stored Procedures of SQL Server in DAO
Samir Sood
|
|
|
|
|
I need to find the mac address of all the machines in the network. I already know the ip address from the DNS table. Can someone tell me how to use the ip address to find its corresponding mac address? Thank you.
|
|
|
|
|
|
You can use the ARP utility.
|
|
|
|
|
HI,
Did you have seen some materials or VC++ source code about
CD image file system: ISO or udf ?
Any information or ideas?
Thanks a lot!
chen
|
|
|
|
|
Did you bother to search codeproject? Maybe this[^] helps
...if you're under 8 or younger. Chris Maunder, the Lounge
|
|
|
|
|
Hello ,everyone,
I want to simulate an animal's movement on a specified terrain.
According to the terrain's changement,I can also change the
animal's moving direction and velocity.
Besides,the animal behaves in random on the rerrain.
In the first step.we can just take the animal as one point.
Anyone has any good idea or code example for me?
thanks a lot.
wang
|
|
|
|
|
what sort of animals?
flocking behavior? herd movement?
slugs are always nice.
cats would probably be kinda hard-- they go all over.
|
|
|
|
|
hi,
I think in the first step,we can simulate a slug's random movement.
All your advices are good.
Do you have any idea?
thank you so much for your quick reply.
weiwei
wang
|
|
|
|
|
The majority of stuff I've seen is heuristic mitigation of plain ol' random walks. (such as modeling ant trails for finding optimum paths instead of using simulated annealing.)
Maybe you are more interested in the AI stuff though that focuses on goals and desired behavior. (The random walk stuff is usually used to further some other goal than modeling the qualitative behavior of an animal.)
Game developer resources/books are probably what you want right?
Or are you just trying to model animal movement as part of an ecological simulation? (that's where the random walk stuff is employed)
In any case, Google is your friend.
|
|
|
|
|
take a look at the Terrarium source over at www.gotdotnet.com. for a better approach you will need to dig into some more advanced studies. look here [^]
...if you're under 8 or younger. Chris Maunder, the Lounge
|
|
|
|
|
I created a dialog template using the resource editor, I've change its style to Child and No Border. Now I want to create a class for this template, which inherit from CDialogBar.
The problem is: when use ClassWizard to do this, there is no CDialogBar in the selection for the base class. If I select CDialog there and replace CDialog using CDialogBar manually, later when I want to add any function to my dialogbar class, class wizard will pop those for CDialog.
What do you do? Thanks a lot!
|
|
|
|
|
Probably there are 'CDialog' references in MFC-generated code (message map etc). Also, you can delete .clw file - it will be recreated by ClassWizard.
What exactly do you want to override in CYourDialogBar?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
For example, I have an edit box in my dialog bar. Some time ago, I have created an edit class which will allow the edit box to accept numbers only.
Now, I want to subclass the CEdit using my CNumEdit.
When the edit box is in a dialog, I do this in OnInitDialog(). Which is what classwizard will point me to. But instead, I should do it in Create() since CDialogBar don't have OnInitDialog().
Maybe I should use the "Class Info" tab of the class Wizard to select "Window" message only, since I know CDialogBar is not dialog, but a CWnd instead.
|
|
|
|
|
I belive CDialogBar will get WM_INITDIALOG. Lack of entry in message list in ClassWizard is just a VC IDE problem. You can always add the entry to message map manually - just have a look at some CDialog-derived class in your program.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
no, it doesn't. When I compiled the code, VC++ will complain that OnInitDialog is not a member of CDialogBar, and it leads me to see the declaration. It is not there indeed.
|
|
|
|
|
So just don't call CDialogBar::OnInitDialog in CYourDlgBar::OnInitDialog
However, if all you need is edit subclassing, just provide your own Create. Catching WM_INITDIALOG doesn't make sense if all you need is this single operation.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
I wonder what you usually do when you want a dialog bar in your application? How do you create the class when you are done with the dialog template?
|
|
|
|
|
lucy wrote:
How do you create the class when you are done with the dialog template?
I'd just create the class without IDE help. Or - I'd select 'generic CWnd' and replace CWnd with CDialogBar later in .h and .cpp.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
|
I have a large data strucutre that is used in an embedded C application. I have replicated the strucutre in VC++ and put a class wrapper around it. This data structure contains mostly basic data types. However there are a few fields that are fixed length arrays (char []) as string placeholders.
I need to transport this structure to VBA. I have used IDL in order to solve this before. But I was wondering if you guys have any other reccommendations. ?
We are using an excel spread sheet as a tag list for our product. I will use this data to generate a binary file that will be used by our embedded software to configure hardware at run-time.
Any suggestions would be appreciated, until then Im using IDL.
Ryan Baillargeon
|
|
|
|
|
I know that we ususally put standard MFC includes, but what other things ?
.h files that are never really touched ? .h files that are really global ? even if it offers interface to classes from files that don't need it ( or want it ) ?
Problem is that when I need to add a .h in the stdafx.h it recompiles everything! no a good thing ! ( will recompile the precompile header )
I usually try to limit the stuff that I put in the stdafx.h, and limit the includes in the .h files of my projects, and use a much as possible forward declaration, and put the includes in the .cpp files.
any thoughts, suggestions, ideas ?
Thanks.
Max.
|
|
|
|