|
I'm using CWinFormControl to create instances of .Net UserControls.
CWinFormsControl<myproject::mycontrol xmlns:myproject="#unknown"> m_control;
m_control.CreateManagedControl( WS_CHILD | WS_VISIBLE, rect, this, IDC_HOSTCONTROL );
This works fine. The problem occurs when I try to destroy the control. I need a deterministic call to the 'MyControl' finalizer, so I wrote the following:
m_control.DestroyWindow();
System::GC::Collect();
This code does not cause the Finalize\Dispose code to be called on 'MyControl'. In fact, 'MyControl' sticks around in memory until the MFC app closes. What am I doing wrong here?
Thanks,
Aaron
|
|
|
|
|
tags.
This function destroys variable0 and variable1 upon completion:
void variableCopy0(variable variable0, variable variable1) {
int time0;
variable1.numTimes = variable0.numTimes;
for (time0 = 0; time0 < variable0.numTimes; time0++) {
dateCopy1(variable0.dates[time0], variable1.dates[time0]);
variable1.values[time0] = variable0.values[time0];
};
};
I call it with the following code:
vars = new variable [numVars + maxInterventions + 1];
for (var0 = 0; var0 < numVars + maxInterventions + 1; var0++) {
vars[var0].setUp(inVars[var0].numTimes);
variableCopy0(inVars[var0], vars[var0]);
};
Upon return, vars[var0] and inVars[var0] are also destroyed. I want to keep them. How do I do that. Here's the class definition:
class variable {
public:
double *values;
date *dates;
int time0;
int numTimes;
variable() {
numTimes = -1;
};
variable(int inTimes) {
values = new double [inTimes + 20];
dates = new date [inTimes + 20];
numTimes = inTimes;
};
void setUp(int inTimes) {
values = new double [inTimes + 20];
dates = new date [inTimes + 20];
numTimes = inTimes;
};
~variable() {
delete [] values;
delete [] dates;
cout << "got into variable destructor" << '\n';
};
};
Phred
|
|
|
|
|
try passing by reference
void variableCopy0(variable &variable0, variable &variable1)
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Thank you very much. That worked.
|
|
|
|
|
Fred Andres wrote: This function destroys variable0 and variable1 upon completion:
void variableCopy0(variable variable0, variable variable1)
Yes it does, because the scope of those variables is the function.
The original variables you pass remain unaltered.
You need to pass by reference. Try something like
void variableCopy0(<code>const variable &</code>variable0, variable <code>&</code>variable1) {
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have the following code:
int numAmt;
string preFix;
numAmt = 10;
preFix = numAmt.ToString();
How come I can't convert the intger 10 to string '10' using the ToString function provided by the .NET framwork?
Quecumber256
|
|
|
|
|
|
Quecumber256 wrote: How come I can't convert the intger 10 to string '10' using the ToString function provided by the .NET framwork?
Good question why you can't.
Your C# code works just fine for me.
C# Discussion Board[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
While I was reading some C++ code, I saw a code snippet which declared an object like this:
#include <string>
#include <cassert>
#include "BaseGameEntity.h"
#include "Locations.h"
class State;
class Miner : public BaseGameEntity
{
private:
State* m_pCurrentState;
.....
};
Another way of declaring an object is to include the header file and then declare the object in the class:
#include <string>
#include <cassert>
#include "BaseGameEntity.h"
#include "Locations.h"
#include "State.h"
class Miner : public BaseGameEntity
{
private:
State m_pCurrentState;
.....
};
Yes, in the first code snippet, an object pointer is declared while in the second one, it is a normal object.
Other than that,is there difference between these 2 ways of declaring an object?
When should either method be used?
|
|
|
|
|
KaKa' wrote:
Yes, in the first code snippet, an object pointer is declared while in the second one, it is a normal object.
Other than that,is there difference between these 2 ways of declaring an object?
The first code snippet, you have forward declared the class. So you don't need to include the corresponding header file. If both classes are independent one, it doesn't matter. Both code snippet work well.
Well, it does matter when you have two classes which circular dependency. In that case, your second code snippet won't work. Check out this link[^] for more information. So, in summery, both code snippets are not exactly the same in all conditions.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Thanks alot Jijo......that explains alot
For the second code snippet with the class forward declaration, does this method work if the forward declared class file is located in another directory?
|
|
|
|
|
In MSDN it says:
When the user allocates their own buffer to accommodate OFN_ALLOWMULTISELECT, the buffer cannot be larger than 2048 or else everything gets corrupted (2048 is the maximum size).
So in a Unicode program, do it mean only 1024/MAX_PATH (3 at most) can be opened once?
|
|
|
|
|
|
|
Hi all,
I have web browser object in my dialog, and i run flash advertisement in it.
problem is some of the flash advertisement steal the focus from my dialog, so if i am typing inside an edit box and advertisement is changed, focus is being steal from my edit to the internet explorer server object.....
is there a way to prevent it?
thanks
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
You could try handling the WM_KILLFOCUS message and reset the focus back to your edit control if the browser object was the one that grabbed the focus from the edit control.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
thank you for your reply...
i tried what you said but the problem is that clicking on the advertisemnt should launch a web page
but if i click the advertisement and the kill focus from the edit is called, the focus is set back to the edit and the web page is never launched...
how can i bypass that?
thanks again
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
You should be able to check if the user switched the focus (via the keyboard or mouse) or if the ad window grabbed the focus.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
thanks for the help....
how do i during OnKillFocus obtain mouse or keyboard click?
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
Let's say we have:
some functions f1, f2, ..., fn (like sin, cos, tan etc.)
a number like 5 (or a variable like x).
and the array char* a[] = { 'f1', '(', 'f2', '(', ..., '(', 'fn', '(', '5', ')', ')', ..., ')', ')' } .
I want to calculate the f1(f2(...(fn(5))...)) .
I know how to do this with RPN and stacks (even using arrays of pointers to functions), but I'm looking for the fastest way (and I believe this is using arrays of pointers to functions and WITHOUT using RPN and stacks)
(I have the ability to include brackets [] where needed in the array)
modified on Sunday, November 30, 2008 7:10 AM
|
|
|
|
|
C++ can't do that. If you want to solve a function, you need to write it in the source code and compile it like any other part of a program.
|
|
|
|
|
Hi,
would any one have any tips re: Setting the font and Color of a Multiline edit control well to be more specfic
is it possible while processing the WM_CTLCOLOREDIT in a Multiline edit control
to set the font and or color of a line or selected text in a Multiline edit control
|
|
|
|
|
Not as far as I know. I use a rich edit control if I want to do that.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Ok
thankx I dont really know GDI that well
However what if I send a message and send EM_SETRECT to the edit
control then get dc of the contol "edit multiline thats is"
selct the font and color I want into the the DC and do a DrawText
is the rectangle parm of the DrawText a rectangle within the DC of
the Edit multiline ???
|
|
|
|
|
Sorry
For the earlier post if I use EM_POSFROMCHAR
To get the X,Y cords of the where I want to highlite the text
then TextOut with those x,y cords
My questions then becommes does anyone have an example
EM_POSFROMCHAR as the documentation on MSDN is not clear
|
|
|
|