Ally86
asked on
MFC --- How to access a parents variable
Hi,
I'm working on a mfc application, where a parent dialog creates a child dialog as a ui thread. Unfortunately I'm having problems in knowing quite how to access this variable. I need to access the variable as it updates. It is updated through the functions "ON_TIMER" from the parent dialog.
What I'm thinking the easiest way to do what I need to acheive would be to somehow pass the current time variable to the child dialog, and then update it using an "ON_TIMER" function from within the child dialog.
I'm a little confused as to how to do this though.
At the simplest terms what i need to do is,
Check a user entered variable in the child dialog against a time variable in the parent dialog.
Any help would be very very much appreciated!!
Thanks
I'm working on a mfc application, where a parent dialog creates a child dialog as a ui thread. Unfortunately I'm having problems in knowing quite how to access this variable. I need to access the variable as it updates. It is updated through the functions "ON_TIMER" from the parent dialog.
What I'm thinking the easiest way to do what I need to acheive would be to somehow pass the current time variable to the child dialog, and then update it using an "ON_TIMER" function from within the child dialog.
I'm a little confused as to how to do this though.
At the simplest terms what i need to do is,
Check a user entered variable in the child dialog against a time variable in the parent dialog.
Any help would be very very much appreciated!!
Thanks
ASKER
Thanks for your reply,
how would I forward the WM_Timer to the child?
Thanks
how would I forward the WM_Timer to the child?
Thanks
Hello,
you need the m_hWnd window-handle from the child.
How do you create it? Using DoModal() or Create?
Stefan
you need the m_hWnd window-handle from the child.
How do you create it? Using DoModal() or Create?
Stefan
ASKER
Hi,
I'm creating it using Create.
my code looks like this...
create = new nexus();
if(create != null)
{
BOOL ret = create->Create(IDD_DIALOG4 , this);
if(!ret)
AfxMessageBox("Create failed");
create->ShowWindow(SW_SHOW );
}
This I believe is creating a modeless dialog, there is an updated double variable which I need to pass into this dialog.
Thanks for your help so far!
I'm creating it using Create.
my code looks like this...
create = new nexus();
if(create != null)
{
BOOL ret = create->Create(IDD_DIALOG4
if(!ret)
AfxMessageBox("Create failed");
create->ShowWindow(SW_SHOW
}
This I believe is creating a modeless dialog, there is an updated double variable which I need to pass into this dialog.
Thanks for your help so far!
hello,
you are nearly done.
::OnTimer()
{
create->OnTimer(0);
}
stefan
you are nearly done.
::OnTimer()
{
create->OnTimer(0);
}
stefan
ASKER
This will pass the variables within OnTimer onto the new modeless dialog?
Thanks
Thanks
Hello...
ähh... no sorry. forgot about that.
This was only to inform the client about action.
What type is it?
If int you can pass it with OnTimer();
Stefan
ähh... no sorry. forgot about that.
This was only to inform the client about action.
What type is it?
If int you can pass it with OnTimer();
Stefan
ASKER
its a type double variable that I need to pass.
What I've now got is...
In the parent dialog
The child dialog is created using Create.
And in the OnTimer ...
create->PassTimer(timer);
Now this should pass the variable through to
the child dialog?
Which will receive the variable in the function ...
void PassTimer(double timer){
curTime = timer;
}
Doesn't seem to be working tho...
Thanks for your help so far
What I've now got is...
In the parent dialog
The child dialog is created using Create.
And in the OnTimer ...
create->PassTimer(timer);
Now this should pass the variable through to
the child dialog?
Which will receive the variable in the function ...
void PassTimer(double timer){
curTime = timer;
}
Doesn't seem to be working tho...
Thanks for your help so far
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much, really helped out!
to access the variable you should pass a pointer to it in the DoModal or Create
::DoModal(int *_Variable);
Call it with
dlg.DoModal(&m_Variable);
But this way you must pull it.
Better to forward the WM_Timer to the child.
Stefan