|
|
Doing your lengthy process on a separate thread is the recommended way
to go.
If you don't want to use multiple threads, then your lengthy process needs
to periodically pump all Windows messages so the UI will remain
responsive.
Here's an example MFC message pump (implemented in the application class)
void CMyWinApp::PumpWaitingMessages()
{
MSG msg;
while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if ( !PumpMessage( ) )
{
break;
}
}
}
A Win32 message pump could be something like
MSG msg;
while ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
Note that you'll want to disable any UI components that you don't want the user
to mess with during the lengthy process.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello everyone,
In the case when function in derived class is virtual, but function in base class is not virtual, when we make base class pointer pointing to derived class' instance, the function in base will be invoked.
I am confused why not the function in Derived class is invoked (this is my question).
When making base pointer pointing to derived class' instance, the layout of derived class should begin with vtable of functions of derived class (virtual function of foo in Derived class in the sample), and the base pointer is pointing to the layout, so when invoking the derived class version function could be found in vtable and it should be invoked. How compiler process this situation internally?
class Base {
public:
void foo()
{
cout << "Base foo " << endl;
}
};
class Derived: public Base {
public:
virtual void foo()
{
cout << "Derived foo " << endl;
}
};
int main()
{
Derived d;
Base* pb = dynamic_cast<base*>(&d);
pb->foo();
pb = static_cast<base*>(&d);
pb->foo();
pb = &d;
pb->foo();
return 0;
}
</base*></base*>
thanks in advance,
George
|
|
|
|
|
Hi,
If my memory serves me well,
Because the foo function of the base class isn't virtual, the address isn't placed in the virtual function table. So when te linker needs to link all functions it knowns to uses the known base::foo address. So when you cast an derived object back to the base class it behaves as an object of the base class. It doesn't matter whether there is a function Derived:foo in the vtable the compiler/linker is hardlinked to Base::Foo.
codito ergo sum
|
|
|
|
|
It's nothing to do with the linker. The pointer pb is a pointer to a Base and in Base the foo function isn't virtual .
Steve
|
|
|
|
|
I agree, thanks Steve!
regards,
George
|
|
|
|
|
Thanks BadKarma,
My question is answered.
regards,
George
|
|
|
|
|
pb is a pointer to a Base , and in the Base class the foo function isn't virtual . This is exactly the behaviour you'd expect.
Steve
|
|
|
|
|
Thanks Steve,
My question is answered.
regards,
George
|
|
|
|
|
dear all friends
the following is my code..i would like to assign value of one array to another array, but why gbest_Ind couldn't be assigned value from p? thanks for your help.
minValue = fitness[0];//fitness is a 10 elements array
for (int count = 0;count<10;count++)
{
if (fitness[count] == minValue )
{
minValue = fitness[count];
gbest_Ind = count;//gbest_Ind is an array of [1][3][4]
}
}
for (int j = 0; j<3; j++)
for (int k = 0; k<4; k++)
{
gbest1[gbest_Ind][j][k]=p[gbest_Ind][j][k];//p is an array of [10][3][4],
}
Li Zhiyuan
|
|
|
|
|
gbest_Ind = count;//gbest_Ind is an array of [1][3][4]
is gbest_Ind an array like your comment suggests or is it an int like this line of code suggests?
|
|
|
|
|
gbest_Ind is an int variable which declared in header file,sorry for my previous mistake
and gbest1 is a [1][3][4] array
Li Zhiyuan
|
|
|
|
|
gbest1[gbest_Ind][j][k]=p[gbest_Ind][j][k];//p is an array of [10][3][4],
and
gbest1 is an array of [1][3][4], so the only valid value for gbest_Ind is 0?
|
|
|
|
|
no, actually gbest_Ind valid value is from 0-9, i just want to use one of 10,and then assign one of 10 p value to gbest1[1][3][4], here when gbest_Ind get a value, and then p [10][3][4] use this value to assign the array to gbest1[1][3][4],how to do it? thanks a lot, i cost two days already, still couldn't get solution.
Li Zhiyuan
|
|
|
|
|
Still not sure what the problem is but, try this
this supposes that array p and array gbest1 are declared something like array[10][3][4]
minValue = fitness[0];
for (int count = 0;count<10;count++)<br />
{ <br />
if (fitness[count] <= minValue )
{<br />
minValue = fitness[count];<br />
gbest_Ind = count;
}<br />
}<br />
<br />
for (int j = 0; j<3; j++)<br />
{
for (int k = 0; k<4; k++)<br />
{<br />
gbest1[gbest_Ind][j][k]=p[gbest_Ind][j][k];
} <br />
}
|
|
|
|
|
Hi friends, plz tell me how can I add controls like -> Buttons to the Child Window.
I have created a SDI, I now I want to add some text to it, & also some button to take input from the users, plzzz tell me how to to this...
Thanx in advance ...
|
|
|
|
|
Can you use of CreateWindow or CButton class?
|
|
|
|
|
tina- wrote: I have created a SDI...
What class is the view derived from?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i have used the following code
<br />
CButton mybutton;<br />
RECT r;<br />
r.left=100;<br />
r.top=100;<br />
r.right=500;<br />
r.bottom=500;<br />
mybutton.Create("Button",BS_CHECKBOX ,r,this,100);<br />
mybutton.Invalidate();<br />
mybutton.UpdateWindow();<br />
mybutton.ShowWindow(SW_SHOW);<br />
|
|
|
|
|
tina- wrote: mybutton.Create("Button",BS_CHECKBOX ,r,this,100);
What is this ?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: What is this?
pointer to the parent window, or is that the place i m committing mistake ?
how shall i get the pointer to the parent window ?
|
|
|
|
|
tina- wrote: pointer to the parent window...
Which is a?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
<br />
void CChildView::OnPaint() <br />
{<br />
CPaintDC dc(this);
<br />
<br />
CButton mybutton;<br />
RECT r;<br />
r.left=100;<br />
r.top=100;<br />
r.right=500;<br />
r.bottom=500;<br />
mybutton.Create("Button",BS_CHECKBOX ,r,this,100);<br />
mybutton.Invalidate();<br />
mybutton.UpdateWindow();<br />
mybutton.ShowWindow(SW_SHOW);<br />
}<br />
<br />
|
|
|
|
|
DavidCrow wrote: What class is the view derived from?
-> CWnd
|
|
|
|
|
Of course it is, just like any UI component. But more specifically, what class is the view derived from?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|