C++ VC實現對話方塊視窗任意分割

來源:互聯網
上載者:User

標籤:

    最近寫MFC的程式,想在對話方塊裡實現視窗的任意分割。現在網路資料一大抄,找個東西實在麻煩。總算這個很簡單,很快就搞定了,寫下來做個筆記。
    個人認為簡單問題最好就是直接貼原始碼,一看就明白,說來說去反而弄不清楚,那我就少廢話了,自己看吧,注釋很清楚。

先來張圖片

1. 建立一個MFC對話方塊程式MySplitterDlg。 再插入兩個Dialog資源 ,這裡一定要選擇IDD_FORMVIEW類別的對話方塊,分別建立類CMyFormView0 和CMyFormView1,基類別選CDialog,一定要選擇CFormView。

2. CMySplitterDlg中增加WM_CREATE的訊息響應,編輯OnCreate()

int CMySplitterDlg::OnCreate(LPCREATESTRUCT lpCreateStruct){    if (CDialog::OnCreate(lpCreateStruct) == -1)        return -1;    // Because the CFRameWnd needs a window class, we will create a new one. I just copied the sample from MSDN Help.    // When using it in your project, you may keep CS_VREDRAW and CS_HREDRAW and then throw the other three parameters.    //需要註冊視窗類別    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_pMyFrame = new CFrameWnd;    m_pMyFrame->Create(strMyClass,"", WS_CHILD,   CRect(0,0,300,300), this);    m_pMyFrame->ShowWindow(SW_SHOW);    // and finally, create the splitter with the frame as the parent    m_cSplitter.CreateStatic(m_pMyFrame,1, 2); //在Frame裡切分視圖視窗為1×2,就是一行兩列    m_cSplitter.CreateView(0,0, RUNTIME_CLASS(CMyFormView0),   CSize(100,100), NULL);//第一行一列    m_cSplitter.CreateView(0,1, RUNTIME_CLASS(CMyFormView1), CSize(100,100), NULL);//第一行二列     return 0;}

3. 在CMySplitterDlg::OnInitDialog()中顯示Frame

int CMySplitterDlg::OnInitDialog(){CDialog::OnInitDialog();GetWindowRect(&cRect);ScreenToClient(&cRect);m_pMyFrame->MoveWindow(&cRect);m_pMyFrame->ShowWindow(SW_SHOW);return TRUE;}

C++ VC實現對話方塊視窗任意分割

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.