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

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