home *** CD-ROM | disk | FTP | other *** search
- // gridfrm.cpp : implementation file
- //
-
- // This is a part of the Objective Grid C++ Library.
- // Copyright (C) 1995,1996 ClassWorks, Stefan Hoenig.
- // All rights reserved.
- //
- // This source code is only intended as a supplement to
- // the Objective Grid Classes Reference and related
- // electronic documentation provided with the library.
- // See these sources for detailed information regarding
- // the Objective Grid product.
- //
-
- #include "stdafx.h"
- #include "gridfrm.h"
-
- #ifndef _GXCOMBO_H_
- #include "gxctrl.h"
- #endif
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- IMPLEMENT_DYNCREATE(CGridMDIFrameWnd, CMDIFrameWnd)
-
- #define new DEBUG_NEW
-
- /////////////////////////////////////////////////////////////////////////////
- // Helpers for saving/restoring window state
-
- static TCHAR BASED_CODE szSection[] = _T("Settings");
- static TCHAR BASED_CODE szWindowPos[] = _T("WindowPos");
- static TCHAR BASED_CODE szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
-
- static BOOL PASCAL NEAR ReadWindowPlacement(LPWINDOWPLACEMENT pwp, LPCTSTR szSection)
- {
- CString strBuffer = AfxGetApp()->GetProfileString(szSection, szWindowPos);
- if (strBuffer.IsEmpty())
- return FALSE;
-
- WINDOWPLACEMENT wp;
- int nRead = _stscanf(strBuffer, szFormat,
- &wp.flags, &wp.showCmd,
- &wp.ptMinPosition.x, &wp.ptMinPosition.y,
- &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
- &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
- &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
-
- if (nRead != 10)
- return FALSE;
-
- wp.length = sizeof wp;
- *pwp = wp;
- return TRUE;
- }
-
- static void PASCAL NEAR WriteWindowPlacement(LPWINDOWPLACEMENT pwp, LPCTSTR szSection)
- // write a window placement to settings section of app's ini file
- {
- TCHAR szBuffer[255];
-
- wsprintf(szBuffer, szFormat,
- pwp->flags, pwp->showCmd,
- pwp->ptMinPosition.x, pwp->ptMinPosition.y,
- pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
- pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
- pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
-
- AfxGetApp()->WriteProfileString(szSection, szWindowPos, szBuffer);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridMDIFrameWnd
-
- CGridMDIFrameWnd::CGridMDIFrameWnd()
- {
- }
-
- CGridMDIFrameWnd::~CGridMDIFrameWnd()
- {
- }
-
-
- BEGIN_MESSAGE_MAP(CGridMDIFrameWnd, CMDIFrameWnd)
- //{{AFX_MSG_MAP(CGridMDIFrameWnd)
- ON_WM_CLOSE()
- ON_WM_NCACTIVATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // ON_WM_ACTIVATEAPP()
- // ON_WM_ACTIVATE()
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridMDIFrameWnd message handlers
-
-
- void CGridMDIFrameWnd::OnClose()
- {
- // before it is destroyed, save the position of the window
- if (m_sSection.GetLength() > 0)
- {
- WINDOWPLACEMENT wp;
- wp.length = sizeof wp;
- if (GetWindowPlacement(&wp))
- {
- wp.flags = 0;
- if (IsZoomed())
- wp.flags |= WPF_RESTORETOMAXIMIZED;
- // and write it to the .INI file
- WriteWindowPlacement(&wp, m_sSection);
- }
- }
- CMDIFrameWnd::OnClose();
- }
-
- BOOL CGridMDIFrameWnd::ShowWindow(int nCmdShow)
- {
- WINDOWPLACEMENT wp;
-
- if (m_sSection.GetLength() > 0 && ReadWindowPlacement(&wp, m_sSection))
- {
- wp.ptMaxPosition.x = 0;
- wp.ptMaxPosition.y = 0;
- if (nCmdShow != SW_SHOWNORMAL)
- wp.showCmd = nCmdShow;
- SetWindowPlacement(&wp);
- return CWnd::ShowWindow(wp.showCmd);
- }
-
- return CWnd::ShowWindow(nCmdShow);
- }
-
- /*
- void CGridMDIFrameWnd::CreateOrActivateFrame(CDocTemplate* pTemplate,
- CRuntimeClass* pViewClass)
- {
- // If an instance of the class specified by pViewClass already exists,
- // then activate the MDI child window containing
- // the view. Otherwise, create a new view for the document.
-
- CMDIChildWnd* pMDIActive = MDIGetActive();
- ASSERT(pMDIActive != NULL);
- CDocument* pDoc = pMDIActive->GetActiveDocument();
- ASSERT(pDoc != NULL);
-
- CView* pView;
- POSITION pos = pDoc->GetFirstViewPosition();
- while (pos != NULL)
- {
- pView = pDoc->GetNextView(pos);
- if (pView->IsKindOf(pViewClass))
- {
- pView->GetParentFrame()->ActivateFrame();
- return;
- }
- }
-
- CMDIChildWnd* pNewFrame
- = (CMDIChildWnd*)(pTemplate->CreateNewFrame(pDoc, NULL));
- if (pNewFrame == NULL)
- return; // not created
- ASSERT(pNewFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWnd)));
- pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
- // MDITile(MDITILE_HORIZONTAL);
- }
- */
-
- BOOL CGridMDIFrameWnd::OnNcActivate(BOOL bActive)
- {
- // TRACE1("OnNcActivate(%d)\n", bActive);
-
- if (CGXGridCombo::GetComboBoxDropDown())
- return TRUE;
-
- return CMDIFrameWnd::OnNcActivate(bActive);
- }
-