Solved

Aligning splitter windows

Posted on 1998-05-28
10
448 Views
Last Modified: 2013-11-19
Hi experts :-)

I have a splitter window made of CScrollView & CEditView.  But the windows are not equally splitted. I want the windows to be splitted equally even when it's resized. i.e, maximize and restore.

Also I would  like to align(center) the buttons in cformview.

regards
P R A T H A P




0
Comment
Question by:chowdry
  • 5
  • 3
  • 2
10 Comments
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1315723
There is no easy way of achieving this.  I would look at adding some code to reposition the splitter when the frame has been resized then do a recalclayout to force the rest to resize.
0
 

Author Comment

by:chowdry
ID: 1315724
hi experts :-)

I had tried the following two ways.  still it didn't help me.

1st method
---------------
oncreateclient()
{
CRect rect;
      GetClientRect( &rect );
      
      BOOL rtn = msplitwnd.CreateStatic(this, 2, 1);
      rtn |= msplitwnd.CreateView(0, 0, RUNTIME_CLASS(CSecondView), CSize(rect.right/2, rect.bottom/2 ), pContext);
      rtn |= msplitwnd.CreateView(1, 0, RUNTIME_CLASS(CSplitwndView), CSize(100, 100), pContext);

}

2nd method
oncreate()
{
      m_wndToolBar.GetWindowRect( &toolrect );
      ScreenToClient( toolrect );

      m_wndStatusBar.GetWindowRect( &statusrect );
      ScreenToClient( statusrect );

      rect.bottom = rect.bottom ( toolrect.bottom + statusrect.bottom );

      msplitwnd.SetRowInfo( 0 , rect.bottom , 0 );
      msplitwnd.RecalcLayout();

}

regards
P R A T H A P
0
 

Author Comment

by:chowdry
ID: 1315725
Edited text of question
0
 

Author Comment

by:chowdry
ID: 1315726
Adjusted points to 25
0
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1315727
Have you tried creating them both with the same size say (10,10)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:chowdry
ID: 1315728
yes, first I had tried with CSize(100, 100).  Since the windows(panes) are not equally distributed (or) splitted, I had tried the other methods.
0
 
LVL 1

Expert Comment

by:speedup
ID: 1315729
Adjust points to 50, and I will help.
0
 

Author Comment

by:chowdry
ID: 1315730
hi speedy,

Iam waiting for u'r answer.

regards
P R A T H A P
0
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1315731
I've just had to do something simliar and setting both size to Rect.W1dth()/2 during creation worked?  ie both my tree and my list view were initially the same size! heres the code I used (which does look much like you were doing anyway!
      m_HorizontalSplitter.CreateStatic( m_pFrameWnd,1,2);
      m_HorizontalSplitter.CreateView(      0,0,
                                                            RUNTIME_CLASS( ExclTreeView ),
                                                            CSize(FrameRect.Width()/2,10),
                                                            NULL);
      m_HorizontalSplitter.CreateView(      0,1,
                                                            RUNTIME_CLASS( ExclListView ),
                                                            CSize(FrameRect.Width()/2,10),
                                                            NULL);

      m_pFrameWnd->RecalcLayout();

0
 
LVL 1

Accepted Solution

by:
speedup earned 50 total points
ID: 1315732
Hi, chowdry.
Here's code for you.

#include <afxpriv.h>

//Add member to CMainFrame
      CMySplitterWnd m_wndSplitter;      
      BOOL m_bInit;// initialized to be FALSE
//Add OnCreateClient()
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
      CRect rect;
      GetClientRect(&rect);
      if (!m_wndSplitter.CreateStatic(this,
            1, 2))          // TODO: adjust the number of rows, columns
      {
            TRACE0("Failed to create split bar ");
            return FALSE;    // failed to create
      }
      m_wndSplitter.CreateView( 0, 0,
            RUNTIME_CLASS( CMyEditView ),
            CSize( rect.Width() / 2, rect.Height() ),
            pContext );
      m_wndSplitter.CreateView( 0, 1,
            RUNTIME_CLASS( CMyScrollView ),
            CSize( rect.Width() / 2, rect.Height() ),
            pContext );
      m_bInit = TRUE;
      return TRUE;
}

//Add function to handle WM_SIZE
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
      CFrameWnd::OnSize(nType, cx, cy);
      if( m_bInit )
      {
            CMyEditView *pEditView = (CMyEditView *)m_wndSplitter.GetPane(
                  0, 0 );
            CMyScrollView *pScrollView = (CMyScrollView *)m_wndSplitter.GetPane(
                  0, 1 );
            CRect rect;
            GetClientRect( &rect );
            int x, y, w, h;
            x = GetSystemMetrics(SM_CXEDGE);
            y = GetSystemMetrics(SM_CYEDGE);
            w = ( rect.Width() - 3 * x ) / 2;
            h =  rect.Height() - GetSystemMetrics( SM_CYCAPTION )
                  - 2 * y;
            AFX_SIZEPARENTPARAMS layout;
            layout.hDWP = ::BeginDeferWindowPos(2);
            AfxRepositionWindow( &layout, pEditView->m_hWnd,
                  CRect( x, y, w + x, h ) );
            AfxRepositionWindow( &layout, pScrollView->m_hWnd,
                  CRect( x + w, y, cx - x, h ) );
            ::EndDeferWindowPos(layout.hDWP);
      }
}


NOTE:
1. You can adjust the sizes of views by the same way in OnSize()
2. In this way, you can't see the splitter bar.But I think you needn't to change views' size
by hand, right? If you really need to adjust size by hand, you can follow the following code.

//Derive CMySplitterWnd from CSplitterWnd
//And next
CMySplitterWnd m_wndSplitter;
//Add function
void CMySplitterWnd::DrawSplitter(const CRect & rect)
{
      CPaintDC dc(this);
      OnDrawSplitter(&dc, splitBox, rect);
}

//rewrite OnSize() like this
.
.
AfxRepositionWindow( &layout, pEditView->m_hWnd,
      CRect( ?, ?, ?, ? ) );
AfxRepositionWindow( &layout, pScrollView->m_hWnd,
      CRect( ?, ?, ?, ? ) );
.
CRect rectSplitter( ?,  ?, ?, ?);
m_wndSplitter.DrawSplitter( rectSplitter );


If there's some problem, contact me directly at chenbo@supresoft.com

Good Luck


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Rewrite URL With Encoded Characters 6 75
Turn a spreadsheet into a vba executable. 2 78
iSeries FTP Exit Program 8 122
VBA "SendKeys" Syntax for Multiple Keystrokes 7 103
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now