我切分窗口是这么做的
CRect rc;
GetClientRect(&rc);
CSize PaneSize(rc.Width()/3, rc.Height());m_wndSplitter.CreateStatic(this,1,2);m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CMyView), PaneSize, pContext);m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CMyView), PaneSize, pContext);问题1:如何隐藏分割条
问题2:如何在两个窗口里显示不同的内容?比如用DrawText输出不同的文本.
问题3:在视类中处理WM_LBUTTONDOWN消息时,如何知道点击的是左边的窗口或是右边的窗口?
CRect rc;
GetClientRect(&rc);
CSize PaneSize(rc.Width()/3, rc.Height());m_wndSplitter.CreateStatic(this,1,2);m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CMyView), PaneSize, pContext);m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CMyView), PaneSize, pContext);问题1:如何隐藏分割条
问题2:如何在两个窗口里显示不同的内容?比如用DrawText输出不同的文本.
问题3:在视类中处理WM_LBUTTONDOWN消息时,如何知道点击的是左边的窗口或是右边的窗口?
问题2:如何在两个窗口里显示不同的内容?比如用DrawText输出不同的文本.
是这样,你看你切分窗口在切分后是不是指向了一个视图类,你的CMyView。只要指向不同的视图类就可以了,这样在不同的视图类里操作显示的得内容也就不同。
问题3:在视类中处理WM_LBUTTONDOWN消息时,如何知道点击的是左边的窗口或是右边的窗口?既然指向了不同的视图类,如果要区分,安我的理解应该有2个办法:
1、直接用m_wndSplitter.m_SplitterWnd->GetPane(0,1)
这样去获得“具体的”切分后的指针。
例:CRightView* pRV=(CRightView*)pMF->m_SplitterWnd->GetPane(0,1);2、使用当前窗口--------GetActiveView
CMainFrame* pMF=(CMainFrame*)AfxGetApp()->m_pMainWnd; //先通过获取当前框架指针
CView * active = pMF->GetActiveView();
这样,鼠标在什么地方,就应该得到什么指针。-----------------------------------
(LPCTSTR lpszPathName, BOOL bMakeVisible)
{
// destroy the current view along with its document
AfxGetMainWnd()->GetDlgItem(AFX_IDW_PANE_FIRST)->DestroyWindow();CWinThread* pThread = AfxGetThread();
pThread->m_pMainWnd = NULL;CDocument* pDocument = NULL;
CFrameWnd* pFrame = NULL;
BOOL bCreated = FALSE; // => doc and frame created
BOOL bWasModified = FALSE;if (m_pOnlyDoc != NULL)
{
// already have a document -- reinit it
pDocument = m_pOnlyDoc;
if (!pDocument->SaveModified())
return NULL; // leave the original onepFrame = (CFrameWnd*) AfxGetMainWnd();
ASSERT(pFrame != NULL);
ASSERT_KINDOF(CFrameWnd, pFrame);
ASSERT_VALID(pFrame);
}
else
{
// create a new document
pDocument = CreateNewDocument();
ASSERT(pFrame == NULL); // will be created below
bCreated = TRUE;
}if (pDocument == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return NULL;
}
ASSERT(pDocument == m_pOnlyDoc);pFrame = (CFrameWnd*) AfxGetMainWnd();// create our view
CCreateContext context;
context.m_pCurrentFrame = NULL; // pFrame
context.m_pCurrentDoc = pDocument;
context.m_pLastView = NULL;
context.m_pNewDocTemplate = this;
context.m_pNewViewClass = m_pViewClass;CWnd *pView = pFrame->CreateView(&context);
if (!pView)
return NULL;if (lpszPathName == NULL)
{
// create a new document
SetDefaultTitle(pDocument);// avoid creating temporary compound file when starting
// up invisible
if (!bMakeVisible)
pDocument->m_bEmbedded = TRUE;if (!pDocument->OnNewDocument())
{
// user has been alerted to what failed in OnNewDocument
TRACE0("CDocument::OnNewDocument returned FALSE.\n");
if (bCreated)
pFrame->DestroyWindow(); // will destroy document
return NULL;
}
}
else
{
CWaitCursor wait;// open an existing document
bWasModified = pDocument->IsModified();
pDocument->SetModifiedFlag(FALSE); // not dirty for openif (!pDocument->OnOpenDocument(lpszPathName))
{
// user has been alerted to what failed in OnOpenDocument
TRACE0("CDocument::OnOpenDocument returned FALSE.\n");
if (bCreated)
{
pFrame->DestroyWindow(); // will destroy document
}
else if (!pDocument->IsModified())
{
// original document is untouched
pDocument->SetModifiedFlag(bWasModified);
}
else
{
// we corrupted the original document
SetDefaultTitle(pDocument);if (!pDocument->OnNewDocument())
{
TRACE0("Error: OnNewDocument failed after trying to open
a document - trying to continue.\n");
// assume we can continue
}
}
return NULL; // open failed
}
pDocument->SetPathName(lpszPathName);
}pThread->m_pMainWnd = pFrame;InitialUpdateFrame(pFrame, pDocument, bMakeVisible);
pFrame->RecalcLayout();return pDocument;
}
http://www.vccode.com/vcfile/show.php?id=882
找了一下,因为自己也没这样做过,最后在VCCode里看到个翻译的文章,
解决办法如下:
----------------------
唯一的方法是重载OnDrawSplitter()函数。在其构造函数中有一个标记决定是否隐藏分割条。像下面这样做。
void CSplitterWndEx::OnDrawSplitter(CDC *pDC, ESplitType nType,
const CRect &rectArg)
{
if (pDC == NULL)
{
RedrawWindow(rectArg, NULL, RDW_INVALIDATE|RDW_NOCHILDREN);
return;
}
/**
* If you want to see the splitter window,
* Use the base class's drawing funcion;
* otherwise, fill the Splitter with the View's color.
*/
if(m_Visible)
{
CSplitterWnd::OnDrawSplitter(pDC,nType,rectArg);
return;
}
ASSERT_VALID(pDC);
CRect rect = rectArg;
CPen WhitePen;
WhitePen.CreatePen( PS_SOLID,
PEN_WIDTH,
GetSysColor(COLOR_WINDOW));
pDC->SelectObject(&WhitePen);
pDC->Rectangle(rect);
}
下一步是在窗口大小改变时隐藏分割条。为了达到这个功能,我们需要重载下面的函数:CSplitterWnd::OnMouseMove(UINT /*nFlags*/, CPoint pt);
CSplitterWnd::StartTracking(int ht);
CSplitterWnd::OnDrawSplitter(CDC* pDC, ESplitType nType,const CRect& rectArg);
CSplitterWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
CSplitterWnd::OnMouseWheel(UINT fFlags, short zDelta, CPoint point);
需要分割条时,在构造函数中用FALSE,正常显示时用TRUE或者不用参数。
例子:
隐藏分隔条:
CSplitterWndEx splitter(FALSE); //Set visible to FALSE.
splitter.CreateStatic(this,1,2);
splitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),
CSize(120,120),pContext);
splitter.CreateView(0,1,RUNTIME_CLASS(CTextView),
CSize(128,0),pContext);
正常显示:
CSplitterWndEx splitter(TRUE); // Set visible to TRUE
// (or)
CSplitterWndEx splitter; // Default is TRUE.
// Use the splitter.
splitter.CreateStatic(this,1,2);
splitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),
CSize(120,120),pContext);
splitter.CreateView(0,1,RUNTIME_CLASS(CTextView),
CSize(128,0),pContext);
---------------------------------------------看来也只有这样了。