-
April 15th, 2005, 07:23 PM
#1
Get a pointer to other dialog window
Hello,
I have dialog based app. main window opens another 2 dialogs (A and B), i am looking for a way passing data and updating it from event on dialog A to B.
//pointer to B dialog
InfoDlg *IWnd = (InfoDlg*)GetParent(); //<-- i dont remember how to set pointer to other window not to parent
// send data to B
IWnd->m_number = 1234;
// update data in B
IWnd->UpdateData(FALSE);
Thanks for help...
-
April 15th, 2005, 09:23 PM
#2
Re: Get a pointer to other dialog window
Originally Posted by portnov
//pointer to B dialog
InfoDlg *IWnd = (InfoDlg*)GetParent(); //<-- i dont remember how to set pointer to other window not to parent
...
//Maybe like this
InfoDlg *IWnd = new COtherDlg;
-
April 16th, 2005, 03:52 AM
#3
Re: Get a pointer to other dialog window
Have the parent window handle access to the dialogs,
I am not sure how you are creating the dialogs in the parent so there are several possibilties.
so lets say the dialogs class are normal members of your main dialog class. then provide a public accessor
Code:
class MyDialog : public CDialog
{
public:
DialogB& GET_B() {return b;}
...
...
private:
DialogA a;
DialogB b;
}
//to make life simpler
__inline DialogB& GET_DIALOG_B()
{ return static_cast<MyDialog*>(AfxGetMainWnd())->GET_B();}
then to access b from a, just use
Code:
GET_DIALOG_B().KnockYourselfOut();
if you are creating the dialogs on the heap, then have GET_B() return a pointer instead
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
April 16th, 2005, 06:48 AM
#4
Re: Get a pointer to other dialog window
Originally Posted by souldog
Have the parent window handle access to the dialogs,
I am not sure how you are creating the dialogs in the parent so there are several possibilties.
Well, im my main dialog i have:
ADlg m_a;
m_a.Create(IDD_A_DIALOG, this);
m_a.ShowWindow(SW_SHOW);
BDlg m_b;
m_b.Create(IDD_B_DIALOG, this);
m_b.ShowWindow(SW_SHOW);
to acsess/change data in main from A or B i can:
MainDlg *Wnd = (MainDlg*)GetParent();
---
Wnd->whatever();
However i still have problem creating simple pointer from dialog A to Data in B dialog.
Thanks,
-
April 16th, 2005, 06:54 AM
#5
Re: Get a pointer to other dialog window
Originally Posted by Shadowflip
//Maybe like this
InfoDlg *IWnd = new COtherDlg;
Thnaks for idea but it isnt working.. - compiles fine, but getting : "An unsupported operation was attempted"
Last edited by portnov; April 16th, 2005 at 07:15 AM.
-
April 16th, 2005, 07:03 AM
#6
Re: Get a pointer to other dialog window
I assume m_a and m_b are members of your main dialog class.
Apparently you did not read my post
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
April 16th, 2005, 09:56 AM
#7
Re: Get a pointer to other dialog window
Finally i found simple solution - the easiest way to pass data from A to B is by making A, B's parent window...
Thanks for your help guys...
-
April 16th, 2005, 11:47 AM
#8
Re: Get a pointer to other dialog window
Making ADlg the parent of BDlg might solve your problem in access by using GetParent(), but it might not be the best practice. Modeless dialogs are usually given a parent of NULL if they're to float around the screen or maybe a CView derived class if they're to be embedded within a view. This could be important for redrawing purposes.
To pass information back and forth between them - keep pointers to those dialogs in the main dialog. Then each modeless dialog can refer to its parent, the main dialog and get reference to each other.
Code:
class CMainDlg : public CDialog {
...
// Attributes
protected:
CDialog* m_pDlgA; // Initialized to NULL in constructor, and assigned a value when ADlg is created
CDialog* m_pDlgB; // Same here
...
// Operations
public:
CDialog* GetDlgA() { return m_pDlgA; }
CDialog* GetDlgB() { return m_pDlgB; }
...
};
Jay
-
April 16th, 2005, 12:13 PM
#9
Re: Get a pointer to other dialog window
The truly easiest way is to have in dialog B member of appropriate type (a pointer to A class) and set it after creation of B but before DoModal (or Create) call for it.
Code:
class A: public CDialog
{...};
class B: public CDialog
{
public:
A* m_pA;
...
};
void A::OnCreateBClick()
{
B dlg;
dlg.m_pA = this;
dlg.DoModal();
}
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|