home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / MINSPLIT.ZIP / ChildFrm.cpp next >
Encoding:
C/C++ Source or Header  |  1998-08-11  |  4.0 KB  |  148 lines

  1. // ChildFrm.cpp : implementation of the CChildFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MinSplitSize.h"
  6.  
  7. #include "ChildFrm.h"
  8.  
  9. #include "MinSplitSizeView.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CChildFrame
  19.  
  20. IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
  21.  
  22. BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
  23.     //{{AFX_MSG_MAP(CChildFrame)
  24.     ON_WM_WINDOWPOSCHANGING()
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CChildFrame construction/destruction
  30.  
  31. CChildFrame::CChildFrame()
  32. {
  33.     // TODO: add member initialization code here
  34.     
  35. }
  36.  
  37. CChildFrame::~CChildFrame()
  38. {
  39. }
  40.  
  41. BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
  42. {
  43.     // TODO: Modify the Window class or styles here by modifying
  44.     //  the CREATESTRUCT cs
  45.  
  46.     return CMDIChildWnd::PreCreateWindow(cs);
  47. }
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CChildFrame diagnostics
  51.  
  52. #ifdef _DEBUG
  53. void CChildFrame::AssertValid() const
  54. {
  55.     CMDIChildWnd::AssertValid();
  56. }
  57.  
  58. void CChildFrame::Dump(CDumpContext& dc) const
  59. {
  60.     CMDIChildWnd::Dump(dc);
  61. }
  62.  
  63. #endif //_DEBUG
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CChildFrame message handlers
  67.  
  68. BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext) 
  69. {
  70.     m_wndSplitter.CreateStatic( this, 3, 3 );
  71.     m_wndSplitter.CreateView( 0, 0, RUNTIME_CLASS( CMinSplitSizeView ), CSize( 50, 50 ), pContext );
  72.     m_wndSplitter.CreateView( 0, 1, RUNTIME_CLASS( CMinSplitSizeView ), CSize( 50, 60 ), pContext );
  73.     m_wndSplitter.CreateView( 0, 2, RUNTIME_CLASS( CMinSplitSizeView ), CSize( 50, 70 ), pContext );
  74.     m_wndSplitter.CreateView( 1, 0, RUNTIME_CLASS( CMinSplitSizeView ), CSize( 60, 50 ), pContext );
  75.     m_wndSplitter.CreateView( 1, 1, RUNTIME_CLASS( CMinSplitSizeView ), CSize( 60, 60 ), pContext );
  76.     m_wndSplitter.CreateView( 1, 2, RUNTIME_CLASS( CMinSplitSizeView ), CSize( 60, 70 ), pContext );
  77.     m_wndSplitter.CreateView( 2, 0, RUNTIME_CLASS( CMinSplitSizeView ), CSize( 70, 50 ), pContext );
  78.     m_wndSplitter.CreateView( 2, 1, RUNTIME_CLASS( CMinSplitSizeView ), CSize( 70, 60 ), pContext );
  79.     m_wndSplitter.CreateView( 2, 2, RUNTIME_CLASS( CMinSplitSizeView ), CSize( 70, 70 ), pContext );
  80.  
  81.     m_wndSplitter.SetColumnInfo( 0, 50, 50 );
  82.     m_wndSplitter.SetColumnInfo( 1, 60, 60 );
  83.     m_wndSplitter.SetColumnInfo( 2, 70, 70 );
  84.     m_wndSplitter.SetRowInfo( 0, 50, 50 );
  85.     m_wndSplitter.SetRowInfo( 1, 60, 60 );
  86.     m_wndSplitter.SetRowInfo( 2, 70, 70 );
  87.     
  88.     return TRUE;
  89. }
  90.  
  91. void CChildFrame::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 
  92. {
  93.     //    Don't do anything if minimized.
  94.     if ( IsIconic() )
  95.     {
  96.         CMDIChildWnd::OnWindowPosChanging( lpwndpos );
  97.         return;
  98.     } // if
  99.  
  100.     //    Calculate the window rect if we have no client area.
  101.     CRect rc( 0, 0, 0, 0 );
  102.     CalcWindowRect( rc );
  103.  
  104.     //    Add on the minimum client width and height from the splitter.
  105.     int nMinWidth    = rc.Width() + m_wndSplitter.GetMinClientWidth();
  106.     int nMinHeight    = rc.Height() + m_wndSplitter.GetMinClientHeight();
  107.  
  108.     //    Get the current window size.
  109.     CRect rcWindow;
  110.     GetWindowRect( rcWindow );
  111.     GetParent()->ScreenToClient( rcWindow );
  112.  
  113.     //    If trying to size too small...
  114.     if ( lpwndpos->cx < nMinWidth )
  115.     {
  116.         //    If dragging left border right...
  117.         if ( rcWindow.left < lpwndpos->x )
  118.         {
  119.             //    How much over are we?
  120.             int nOver = nMinWidth - lpwndpos->cx;
  121.             
  122.             //    Adjust left coord.
  123.             lpwndpos->x -= nOver;
  124.  
  125.         } // if
  126.  
  127.         //    Fix width.
  128.         lpwndpos->cx = nMinWidth;
  129.     } // if
  130.  
  131.     //    If trying to size too small...
  132.     if ( lpwndpos->cy < nMinHeight )
  133.     {
  134.         //    If dragging top border down...
  135.         if ( rcWindow.top < lpwndpos->y )
  136.         {
  137.             //    How much over are we?
  138.             int nOver = nMinHeight - lpwndpos->cy;
  139.             
  140.             //    Adjust left coord.
  141.             lpwndpos->y -= nOver;
  142.         } // if
  143.         
  144.         //    Fix height.
  145.         lpwndpos->cy = nMinHeight;
  146.     } // if
  147. }
  148.