home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / stingray / gridfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-27  |  4.6 KB  |  181 lines

  1. // gridfrm.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Objective Grid C++ Library.
  5. // Copyright (C) 1995,1996 ClassWorks, Stefan Hoenig.
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to
  9. // the Objective Grid Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding
  12. // the Objective Grid product.
  13. //
  14.  
  15. #include "stdafx.h"
  16. #include "gridfrm.h"
  17.  
  18. #ifndef _GXCOMBO_H_
  19. #include "gxctrl.h"
  20. #endif
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. IMPLEMENT_DYNCREATE(CGridMDIFrameWnd, CMDIFrameWnd)
  28.  
  29. #define new DEBUG_NEW
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // Helpers for saving/restoring window state
  33.  
  34. static TCHAR BASED_CODE szSection[] =   _T("Settings");
  35. static TCHAR BASED_CODE szWindowPos[] = _T("WindowPos");
  36. static TCHAR BASED_CODE szFormat[] =    _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
  37.  
  38. static BOOL PASCAL NEAR ReadWindowPlacement(LPWINDOWPLACEMENT pwp, LPCTSTR szSection)
  39. {
  40.     CString strBuffer = AfxGetApp()->GetProfileString(szSection, szWindowPos);
  41.     if (strBuffer.IsEmpty())
  42.         return FALSE;
  43.  
  44.     WINDOWPLACEMENT wp;
  45.     int nRead = _stscanf(strBuffer, szFormat,
  46.         &wp.flags, &wp.showCmd,
  47.         &wp.ptMinPosition.x, &wp.ptMinPosition.y,
  48.         &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
  49.         &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
  50.         &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
  51.  
  52.     if (nRead != 10)
  53.         return FALSE;
  54.  
  55.     wp.length = sizeof wp;
  56.     *pwp = wp;
  57.     return TRUE;
  58. }
  59.  
  60. static void PASCAL NEAR WriteWindowPlacement(LPWINDOWPLACEMENT pwp, LPCTSTR szSection)
  61.     // write a window placement to settings section of app's ini file
  62. {
  63.     TCHAR szBuffer[255];
  64.  
  65.     wsprintf(szBuffer, szFormat,
  66.         pwp->flags, pwp->showCmd,
  67.         pwp->ptMinPosition.x, pwp->ptMinPosition.y,
  68.         pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
  69.         pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
  70.         pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
  71.  
  72.     AfxGetApp()->WriteProfileString(szSection, szWindowPos, szBuffer);
  73. }
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CGridMDIFrameWnd
  77.  
  78. CGridMDIFrameWnd::CGridMDIFrameWnd()
  79. {
  80. }
  81.  
  82. CGridMDIFrameWnd::~CGridMDIFrameWnd()
  83. {
  84. }
  85.  
  86.  
  87. BEGIN_MESSAGE_MAP(CGridMDIFrameWnd, CMDIFrameWnd)
  88.     //{{AFX_MSG_MAP(CGridMDIFrameWnd)
  89.     ON_WM_CLOSE()
  90.     ON_WM_NCACTIVATE()
  91.     //}}AFX_MSG_MAP
  92. END_MESSAGE_MAP()
  93.  
  94. //  ON_WM_ACTIVATEAPP()
  95. //  ON_WM_ACTIVATE()
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CGridMDIFrameWnd message handlers
  99.  
  100.  
  101. void CGridMDIFrameWnd::OnClose()
  102. {
  103.     // before it is destroyed, save the position of the window
  104.     if (m_sSection.GetLength() > 0)
  105.     {
  106.         WINDOWPLACEMENT wp;
  107.         wp.length = sizeof wp;
  108.         if (GetWindowPlacement(&wp))
  109.         {
  110.             wp.flags = 0;
  111.             if (IsZoomed())
  112.                 wp.flags |= WPF_RESTORETOMAXIMIZED;
  113.             // and write it to the .INI file
  114.             WriteWindowPlacement(&wp, m_sSection);
  115.         }
  116.     }
  117.     CMDIFrameWnd::OnClose();
  118. }
  119.  
  120. BOOL CGridMDIFrameWnd::ShowWindow(int nCmdShow)
  121. {
  122.     WINDOWPLACEMENT wp;
  123.  
  124.     if (m_sSection.GetLength() > 0 && ReadWindowPlacement(&wp, m_sSection))
  125.     {
  126.         wp.ptMaxPosition.x = 0;
  127.         wp.ptMaxPosition.y = 0;
  128.         if (nCmdShow != SW_SHOWNORMAL)
  129.             wp.showCmd = nCmdShow;
  130.         SetWindowPlacement(&wp);
  131.         return CWnd::ShowWindow(wp.showCmd);
  132.     }
  133.  
  134.     return CWnd::ShowWindow(nCmdShow);
  135. }
  136.  
  137. /*
  138. void CGridMDIFrameWnd::CreateOrActivateFrame(CDocTemplate* pTemplate,
  139.     CRuntimeClass* pViewClass)
  140. {
  141.     // If an instance of the class specified by pViewClass already exists,
  142.     // then activate the MDI child window containing
  143.     // the view.  Otherwise, create a new view for the document.
  144.  
  145.     CMDIChildWnd* pMDIActive = MDIGetActive();
  146.     ASSERT(pMDIActive != NULL);
  147.     CDocument* pDoc = pMDIActive->GetActiveDocument();
  148.     ASSERT(pDoc != NULL);
  149.  
  150.     CView* pView;
  151.     POSITION pos = pDoc->GetFirstViewPosition();
  152.     while (pos != NULL)
  153.     {
  154.         pView = pDoc->GetNextView(pos);
  155.         if (pView->IsKindOf(pViewClass))
  156.         {
  157.             pView->GetParentFrame()->ActivateFrame();
  158.             return;
  159.         }
  160.     }
  161.  
  162.     CMDIChildWnd* pNewFrame
  163.         = (CMDIChildWnd*)(pTemplate->CreateNewFrame(pDoc, NULL));
  164.     if (pNewFrame == NULL)
  165.         return;     // not created
  166.     ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWnd)));
  167.     pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
  168.     // MDITile(MDITILE_HORIZONTAL);
  169. }
  170. */
  171.  
  172. BOOL CGridMDIFrameWnd::OnNcActivate(BOOL bActive)
  173. {
  174.     // TRACE1("OnNcActivate(%d)\n", bActive);
  175.  
  176.     if (CGXGridCombo::GetComboBoxDropDown())
  177.         return TRUE;
  178.  
  179.     return CMDIFrameWnd::OnNcActivate(bActive);
  180. }
  181.