【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; }