When I understand your question correctly, your two dialogs do not know of each other, but are both pages of tab control. So, your question would actually be: How can I get a pointer to Dlg1 while being in a member function of Dlg2?
There are several ways to do that, some more elegant than others:
1. You can deposite a pointer to Dlg1 in a global pointer variable and access that from Dlg2. For example:
Dlg1* ptrToDlg1 = 0;
ptrToDlg1 = this;
extern Dlg1* ptrToDlg1;
CString fileName = ptrToDlg1->GetFileName();
Normally we try to avoid global pointers whenever possible. So here's a more elegant way:
b) At some place you create your two dialogs; probably in some code of your tab control. That is the write place to tell Dlg2 about where Dlg1 is:
Dlg1* ptrDlg1 = new Dlg1 (...);
Dlg2* ptrDlg2 = new Dlg2 (...);
Now Dlg2 has a pointer to Dlg1 and can ask it at the right moment for the filename. ...
This is pretty much a long and detailed version of what Maximilien posted in Solution 1. I just thought, this might be the missing link and help you on your way.
[EDIT after OP amended his source code]
Here is a very detailed description of the changes you need to make.
In your Dlg2 class, add a function Dlg2::SetDlg1ptr (Dlg1* pDlg1) with code:
void Dlg2::SetDlg1Ptr (Dlg1* pDlg1)
m_ptrToDlg1 = pDlg1;
and add in the header file of Dlg2:
void SetDlg1Ptr (Dlg1* pDlg1);
You call this function in the constructor of MyTabCtrl:
m_Dialog = new MyDlg1();
m_Dialog = new MyDlg2();
From this moment on Dlg2 can call member functions of Dlg1 via this pointer.
Next, change your OnBnClickedButton6 function in Dlg1:
if (FileDlg.DoModal() == IDOK)
m_pathName = FileDlg.GetPathName();
and add the member variable m_pathName in Dlg2.h.
PCTSTR GetPathName () const;
Then add an accessor function to m_pathName
PCTSTR Dlg1::GetPathName () const
And finally, you can access the path name in OnBnClickedButton2:
ShellExecute (NULL, .... , m_ptrDlg1->GetPathName(), ...);