首页 > 代码库 > 【VC】Dialog 窗口任意分割子窗口。

【VC】Dialog 窗口任意分割子窗口。


用 Dialog 对话框来实现窗口的任意分割。


在资源中添加  Dialog 选择  IDD_FORMVIEW 资源。。分别新建FormViewOne,FormViewTwo FormViewThree 类,分别继承基类 CFormView。


class CMyFormViewOne : public CFormView
{
	DECLARE_DYNCREATE(CMyFormViewOne)

protected:
	CMyFormViewOne();           // 动态创建所使用的受保护的构造函数
	virtual ~CMyFormViewOne();

public:
	enum { IDD = IDD_FORMVIEW };
#ifdef _DEBUG
	virtual void AssertValid() const;
#ifndef _WIN32_WCE
	virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
};


public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);


public:
	CFrameWnd *m_pMyWnd;
	CSplitterWnd m_SplitterWnd;
	CSplitterWnd m_SplitterWnd2;



	|			|		|
	|			|	2	|
	|	  1		|||||||||||||||||
	|			|	3	|
	|			|		|


int CSplitDlgDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	CString strMyClass = AfxRegisterWndClass(CS_VREDRAW |CS_HREDRAW,
		::LoadCursor(NULL, IDC_ARROW),
		(HBRUSH) ::GetStockObject(WHITE_BRUSH),
		::LoadIcon(NULL, IDI_APPLICATION));

	// Create the frame window with "this" as the parent
	m_pMyWnd = new CFrameWnd;
	m_pMyWnd->Create(strMyClass,_T(""), WS_CHILD,
		CRect(0,0,200,200), this);
	m_pMyWnd->ShowWindow(SW_SHOW);	


	if (m_SplitterWnd.CreateStatic(m_pMyWnd,1, 2) == NULL) //1行2列
	{
		return -1;
	}	

	if(m_SplitterWnd2.CreateStatic(&m_SplitterWnd,2,1,WS_CHILD|WS_VISIBLE,m_SplitterWnd.IdFromRowCol(0,1)) == NULL)
	{
		return -1;
	}

	m_SplitterWnd.CreateView(0,0, RUNTIME_CLASS(CMyFormViewOne),
		CSize(100,100), NULL);

	m_SplitterWnd2.CreateView(0,0, RUNTIME_CLASS(CMyFormViewTwo),
		CSize(80,80), NULL);

	m_SplitterWnd2.CreateView(1,0, RUNTIME_CLASS(CMyFormViewThree),
		CSize(80,80), NULL);
 return 0;
}




在 OnInitDialog 函数中


	CRect rect;
	GetWindowRect(&rect);
	ScreenToClient(&rect);

	m_pMyWnd->MoveWindow(&rect);
	m_pMyWnd->ShowWindow(SW_SHOW);

去掉子窗口的滚动条的显示。。如下代码即可


void CMyFormViewOne::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	m_nMapMode = -1;
}



 



【VC】Dialog 窗口任意分割子窗口。