|對話框窗口切分|

-------------------------------------------------------------------------------------------
|對話框窗口切分|
-------------------------------------------------------------------------------------------
.h文件


CFrameWnd *m_pMyFrame;
CSplitterWnd m_cSplitter;
CSplitterWnd m_cSplitterone;
virtual BOOL OnInitDialog(); 
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);


.cpp文件中


BOOL CLoadAdjustmentInventoryDlg::OnInitDialog()
{
CDialog::OnInitDialog();


CRect cRect;
GetWindowRect(&cRect);
ScreenToClient(&cRect);
m_pMyFrame->MoveWindow(&cRect);
m_pMyFrame->ShowWindow(SW_SHOW);
return TRUE;  // return TRUE unless you set the focus to a control
// 異常: OCX 屬性頁應返回 FALSE
}


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


// TODO:  在此添加您專用的創建代碼
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,2, 1); //在Frame裏切分視圖窗口爲1×2,就是一行兩列
m_cSplitterone.CreateStatic(&m_cSplitter,1,2,WS_CHILD|WS_VISIBLE,m_cSplitter.IdFromRowCol(1,0));
m_cSplitter.CreateView(0,0, RUNTIME_CLASS(CThereAreStockSegmentationDlg),CSize(100,100), NULL);//第一行一列


m_cSplitterone.CreateView(0,0, RUNTIME_CLASS(CThereAreStockSegmentationoneDlg),CSize(100,100), NULL);
m_cSplitterone.CreateView(0,1, RUNTIME_CLASS(CThereAreStockSegmentationtwoDlg),CSize(100,100), NULL);//第一行二列


return 0;
}


說說切分後不能移動,不能拖拉 
第1步:首先要創建一個新的CSplitterWnd派生類,它將完成鎖定分割器的行爲,我們把這個類稱爲CFixedSplitter。
class CFixedSplitter: public CSplitterWnd{};
第2步:使用ClassWizard在CFixedSplitter類中增加句柄來處理WM_LBUTTONDOWN,WM_MOUSEMOVE和WM_SETCURSOR消息。這些消息的具體實現見下面的代碼。它們達


到了鎖定分割器的目的。


void CFixedSplitter::OnLButtonDown(UINT nFlags, CPoint point)
{
//迴避標準的CSplitterWnd處理過程CSplitterWnd::OnLButtonDown(UINT nFlags, CPoint point);
CWnd::OnLButtonDown(nFlags, point);
}


void CFixedSplitter::OnMouseMove(UINT nFlags, CPoint point)
{
//迴避標準的CSplitterWnd::OnMouseMove(nFlags, point);  
CWnd::OnMouseMove(nFlags, point);  
}


BOOL CFixedSplitter::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
//迴避標準的CSplitterWnd::OnSetCursor(pWnd, nHitTest, message);  
return CWnd::OnSetCursor(pWnd, nHitTest, message); 
}
最後把CSplitterWnd m_cSplitter聲明,修改爲:CFixedSplitter m_cSplitter; 完成!
-------------------------------------------------------------------------------------------
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章