home *** CD-ROM | disk | FTP | other *** search
/ Using Visual Basic 5 (Platinum Edition) / vb5.iso / ACTIVEX / SRDVID / DATA.1 / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-10  |  4.3 KB  |  167 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // mainfrm.cpp : Implementation of the CMainFrame class
  4. //
  5. /////////////////////////////////////////////////////////////////////////////
  6. //
  7. //  (C) Copyright Black Diamond Consulting, Inc 1996. All rights reserved.
  8. //
  9. //    You have a royalty-free right to use, modify, reproduce and 
  10. //    distribute the Sample Files (and/or any modified version) in 
  11. //    any way you find useful, provided that you agree that Black 
  12. //    Diamond Consulting has no warranty obligations or liability
  13. //    for any Sample Application Files which are modified. 
  14. //
  15. //    Revision History:
  16. //
  17. /////////////////////////////////////////////////////////////////////////////
  18.  
  19. #include "stdafx.h"
  20. #include <afxpriv.h>
  21. #include "mainfrm.h"
  22.  
  23. #ifndef __SVVIEWER_H__
  24.     #include "SVViewer.h"
  25. #endif
  26.  
  27. #ifndef __SVVIEW_H__
  28.     #include "SVView.h"
  29. #endif
  30.  
  31. #ifdef _DEBUG
  32. #undef THIS_FILE
  33. static char BASED_CODE THIS_FILE[] = __FILE__;
  34. #endif
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CMainFrame
  38.  
  39. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  40.  
  41. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  42.     //{{AFX_MSG_MAP(CMainFrame)
  43.     ON_WM_ERASEBKGND()
  44.     ON_WM_CREATE()
  45.     ON_WM_GETMINMAXINFO()
  46.     //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // arrays of IDs used to initialize control bars
  51.     
  52. static UINT BASED_CODE indicators[] =
  53. {
  54.     ID_SEPARATOR,           // status line indicator
  55.     ID_INDICATOR_CAPS,
  56.     ID_INDICATOR_NUM,
  57.     ID_INDICATOR_SCRL,
  58. };
  59.  
  60. static const char* WINDOW_SETTINGS_SECTION_NAME = "Window Settings";
  61. static const char* LOCATION_SETTING_NAME = "Location";
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CMainFrame construction/destruction
  65.  
  66. CMainFrame::CMainFrame()
  67. {
  68.     // TODO: add member initialization code here
  69. }
  70.  
  71. CMainFrame::~CMainFrame()
  72. {
  73. }                
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CMainFrame message handlers
  77.  
  78. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  79. {
  80.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  81.         return -1;
  82.  
  83.     if (!m_wndStatusBar.Create(this) ||
  84.         !m_wndStatusBar.SetIndicators(indicators,
  85.           sizeof(indicators)/sizeof(UINT)))
  86.     {
  87.         TRACE0("Failed to create status bar\n");
  88.         return -1;      // fail to create
  89.     }
  90.  
  91.     return 0;
  92. }
  93.  
  94. BOOL CMainFrame::OnEraseBkgnd(CDC* pDC) 
  95. {
  96.     CRect rect;
  97.     this->GetClientRect(rect);
  98.     pDC->FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
  99.  
  100.     return TRUE;
  101. }
  102.  
  103. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 
  104. {
  105.     char buffer [256];
  106.  
  107.     if (GetPrivateProfileString(WINDOW_SETTINGS_SECTION_NAME,
  108.                                 LOCATION_SETTING_NAME, 
  109.                                 "100 100 600 400", 
  110.                                 buffer, sizeof(buffer), AfxGetApp()->m_pszProfileName))
  111.     {
  112.         sscanf(buffer, "%i%i%i%i", &cs.x, &cs.y, &cs.cx, &cs.cy);
  113.     }    
  114.  
  115.     return CFrameWnd::PreCreateWindow(cs);
  116. }
  117.  
  118. BOOL CMainFrame::DestroyWindow() 
  119. {
  120.     char buffer [256];
  121.     CRect rect;
  122.  
  123.     this->GetWindowRect(&rect);
  124.  
  125.     sprintf(buffer, "%i %i %i %i", rect.left, rect.top, rect.Width(), rect.Height());
  126.  
  127.     WritePrivateProfileString(    WINDOW_SETTINGS_SECTION_NAME,
  128.                                 LOCATION_SETTING_NAME, 
  129.                                 buffer, AfxGetApp()->m_pszProfileName);    
  130.     
  131.     return CFrameWnd::DestroyWindow();
  132. }
  133.  
  134. void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
  135. {
  136.     CRect rect;
  137.     SIZE sz;
  138.  
  139.     CSVViewerView *pView = (CSVViewerView *)GetActiveView();
  140.     if( pView  && pView->IsKindOf(RUNTIME_CLASS(CSVViewerView)) )
  141.     {
  142.         pView->GetMaxViewSize(&sz);
  143.  
  144.         // if the initial view size is 0, then don't set the limit
  145.         if (sz.cx && sz.cy)
  146.         {
  147.             long lExStyle = GetWindowLong( m_hWnd, GWL_EXSTYLE );
  148.             long lStyle = GetWindowLong( m_hWnd, GWL_STYLE );
  149.  
  150.             rect.SetRect( 0, 0, sz.cx, sz.cy );
  151.             AdjustWindowRectEx( &rect, lStyle, TRUE, lExStyle );
  152.  
  153.             lpMMI->ptMaxTrackSize.x = rect.Width();
  154.             lpMMI->ptMaxSize.y = rect.Height();
  155.             
  156.             // Add in the status bar window height
  157.             m_wndStatusBar.GetWindowRect( &rect );
  158.             lpMMI->ptMaxSize.y += rect.Height();
  159.             
  160.             lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;
  161.             
  162.             lpMMI->ptMaxSize.x = min(lpMMI->ptMaxSize.x, lpMMI->ptMaxTrackSize.x);
  163.             return;
  164.         }
  165.     }
  166. }
  167.