在VC中实现控件容器

在VC6中设计器不提供类似Delphi,.Net中的容器的控件Panel组件,因此做复杂界面的时候比较麻烦,为了模拟容器控件的效果,我们可以通过创建一个无边框的Dialog,将其停靠到主界面上来仿真。代码示意如下。

BOOL CDivideSettingDetail::OnInitDialog()
{
CCommDlg::OnInitDialog();

CWnd* pWnd = GetDlgItem( IDC_TRAIN );
CRect rect;
pWnd->GetWindowRect( &rect );
ScreenToClient( &rect );

InitTrainDetail();
TrainDetail.Create(IDD_015_1, this);
TrainDetail.ShowWindow( WS_VISIBLE | WS_CHILD );
TrainDetail.SetWindowPos( pWnd, 0, rect.top, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER );
TrainDetail.ShowWindow(SW_SHOW);

上面的IDC_TRAIN是一个用来定位的控件,设计时将它设置为不可见即可