2342G456DI8
2342G456DI8

Reputation: 1809

Embedded dialog in Tab Control cannot work in second dialog, MFC

I have following code which works in the main dialog, but cannot work in the second (or third) dialog. The thing is that I want each page of the tab control can show a embedded dialog, it's similar to property page.

First I create two dialog, IDD_DIALOG1 and IDD_DIALOG2.Then I change the style of them to child and border to None. After that I add CDialog class to each of them.

In my MainDialog.h, I have the following code:

#include "Dialog1.h"
#include "Dialog2.h"
...
public:
    CDialog1 m_para1;
    CDialog2 m_para2;
    CTabCtrl m_TabCtrl;

In my MainDialog.cpp, I use the following code to embed the dialo in the OnInitDialog:

m_TabCtrl.InsertItem(0, _T("TAB1"));
m_TabCtrl.InsertItem(1, _T("TAB2"));
m_para1.Create(IDD_DIALOG1,GetDlgItem(IDD_MAINDIALOG));
m_para2.Create(IDD_DIALOG2,GetDlgItem(IDD_MAINDIALOG));

CRect rs;
m_TabCtrl.GetClientRect(&rs);

rs.top+=37;
rs.bottom+=8;
rs.left+=13;
rs.right+=7;

m_para1.MoveWindow(&rs);
m_para2.MoveWindow(&rs);

m_para1.ShowWindow(TRUE);
m_para2.ShowWindow(FALSE);


m_TabCtrl.SetCurSel(1);

By using this way, It can work in this case. But if I want to use this method in my SecondDialog, the non-main dialog, it cannot work. Can someone help me out? Thanks in advance.

Upvotes: 0

Views: 1534

Answers (1)

user1393258
user1393258

Reputation:

When you create a modeless dialog box, try this:

m_para1.Create(IDD_DIALOG1,&m_TabCtrl);
m_para2.Create(IDD_DIALOG2,&m_TabCtrl);

The second parameter of the Create function is a point to the parent window object (of type CWnd) to which the dialog object belongs. The return type of the GetDlgItem function is HWND.

See following: http://msdn.microsoft.com/en-us/library/tc46f3be.aspx
http://msdn.microsoft.com/en-us/library/kc6x1ya0.aspx

Upvotes: 1

Related Questions