home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c05 / lab04 / baseline / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  4.0 KB  |  180 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "diff.h"
  6.  
  7. #include "splitter.h"
  8. #include "MainFrm.h"
  9. #include "diffdoc.h"
  10. #include "diffview.h"
  11.  
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CMainFrame
  19.  
  20. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  21.  
  22. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  23.     //{{AFX_MSG_MAP(CMainFrame)
  24.     ON_WM_CREATE()
  25.     ON_WM_DROPFILES()
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29. static UINT indicators[] =
  30. {
  31.     ID_SEPARATOR,           // status line indicator
  32.     ID_INDICATOR_CAPS,
  33.     ID_INDICATOR_NUM,
  34.     ID_INDICATOR_SCRL,
  35. };
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CMainFrame construction/destruction
  39.  
  40. CMainFrame::CMainFrame()
  41. {
  42.     // TODO: add member initialization code here
  43.     
  44. }
  45.  
  46. CMainFrame::~CMainFrame()
  47. {
  48. }
  49.  
  50. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  51. {
  52.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  53.         return -1;
  54.     
  55.     if (!m_wndToolBar.Create(this) ||
  56.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  57.     {
  58.         TRACE0("Failed to create toolbar\n");
  59.         return -1;      // fail to create
  60.     }
  61.  
  62.     if (!m_wndStatusBar.Create(this) ||
  63.         !m_wndStatusBar.SetIndicators(indicators,
  64.           sizeof(indicators)/sizeof(UINT)))
  65.     {
  66.         TRACE0("Failed to create status bar\n");
  67.         return -1;      // fail to create
  68.     }
  69.  
  70.     // TODO: Delete these three lines if you don't want the toolbar to
  71.     //  be dockable
  72.     m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  73.     EnableDocking(CBRS_ALIGN_ANY);
  74.     DockControlBar(&m_wndToolBar);
  75.  
  76.     // TODO: Remove this if you don't want tool tips
  77.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  78.         CBRS_TOOLTIPS | CBRS_FLYBY);
  79.  
  80.     return 0;
  81. }
  82.  
  83. BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
  84.     CCreateContext* pContext)
  85. {
  86.         //
  87.         //    For the difference application, we will create a
  88.         //    static splitter window    with 2 side by side panes.
  89.         //    
  90.     if(!m_wndSplitter.CreateStatic(this,1,2,WS_CHILD))
  91.     {
  92.         return FALSE;
  93.     }
  94.  
  95.     SIZE size;                                  
  96.     CRect rect;     
  97.     GetClientRect(&rect);   
  98.         
  99.         //
  100.         //    Calculate the size of the splitter panes
  101.         //
  102.     size.cx = (rect.right - m_wndSplitter.GetSplitterWidth())/2;
  103.     size.cy = rect.bottom;
  104.  
  105.         //
  106.         //    Provide each pane with its own view, the same in this case
  107.         //    but could be different    
  108.         //
  109.     m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CDiffView),size, pContext);
  110.     m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CDiffView),size, pContext);
  111.     //SetActiveView((CView *)m_wndSplitter.GetPane(0,1));
  112.   
  113.     m_wndSplitter.ShowWindow(SW_SHOWNORMAL);
  114.     m_wndSplitter.UpdateWindow();
  115.  
  116.     return TRUE;
  117. }
  118.  
  119. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  120. {
  121.     // TODO: Modify the Window class or styles here by modifying
  122.     //  the CREATESTRUCT cs
  123.  
  124.     return CFrameWnd::PreCreateWindow(cs);
  125. }
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CMainFrame diagnostics
  129.  
  130. #ifdef _DEBUG
  131. void CMainFrame::AssertValid() const
  132. {
  133.     CFrameWnd::AssertValid();
  134. }
  135.  
  136. void CMainFrame::Dump(CDumpContext& dc) const
  137. {
  138.     CFrameWnd::Dump(dc);
  139. }
  140.  
  141. #endif //_DEBUG
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CMainFrame message handlers
  145.  
  146. void CMainFrame::OnDropFiles(HDROP hDropInfo) 
  147. {
  148.     UINT nFileCount = ::DragQueryFile (hDropInfo,
  149.                                         0xFFFFFFFF,
  150.                                         NULL, 0 );
  151.     ASSERT (nFileCount !=0);
  152.  
  153.     // we must have at least two files for this function;
  154.     // we will grab only the first two
  155.  
  156.     if (nFileCount >= 2)
  157.     {
  158.         CString File1;
  159.         CString File2;
  160.  
  161.         ::DragQueryFile (hDropInfo,
  162.                         0,
  163.                         File1.GetBufferSetLength (_MAX_PATH),
  164.                         _MAX_PATH);
  165.         File1.ReleaseBuffer();
  166.  
  167.         ::DragQueryFile (hDropInfo,
  168.                         1,
  169.                         File2.GetBufferSetLength (_MAX_PATH),
  170.                         _MAX_PATH);
  171.         File2.ReleaseBuffer();
  172.  
  173.         ((CDiffDoc *)GetActiveDocument())->
  174.                             RunComparison (File1, File2);
  175.  
  176.         ::DragFinish(hDropInfo);
  177.     }
  178.  
  179. }
  180.