home *** CD-ROM | disk | FTP | other *** search
/ Chip Special: HTML & Java / Chip-Special_1997-01_HTML-a-Java.bin / actvx31.sdk / coresdk / inetsdk / samples / urlpad / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-24  |  4.1 KB  |  146 lines

  1. //=------------------------------------------------------------------------=
  2. // MainFrm.Cpp
  3. //=------------------------------------------------------------------------=
  4. // Copyright 1992-1996 Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // implementation of the CMainFrame class
  13. //
  14.  
  15. #include "stdafx.h"
  16. #include "superpad.h"
  17. #include "mainfrm.h"
  18.  
  19.  
  20. IMPLEMENT_DYNCREATE(CMainFrame, CMDIFrameWnd)
  21. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  22.     //{{AFX_MSG_MAP(CMainFrame)
  23.     ON_WM_CREATE()
  24.     ON_WM_CLOSE()
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. static UINT BASED_CODE buttons[] =
  29. {
  30.     // same order as in the bitmap 'toolbar.bmp'
  31.     ID_FILE_NEW, ID_FILE_OPEN, ID_FILE_SAVE, 0,
  32.     ID_EDIT_CUT, ID_EDIT_COPY, ID_EDIT_PASTE, 0,
  33.     ID_FILE_PRINT, ID_APP_ABOUT,
  34. };
  35.  
  36. static UINT BASED_CODE indicators[] =
  37. {
  38.     0, ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL,
  39. };
  40.  
  41. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  42. {
  43.     if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  44.         return -1;
  45.     if (!m_wndToolBar.Create(this) ||
  46.         !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  47.         !m_wndToolBar.SetButtons(buttons, sizeof(buttons)/sizeof(UINT)))
  48.     {
  49.         return -1;      // fail to create
  50.     }
  51.     if (!m_wndStatusBar.Create(this) ||
  52.         !m_wndStatusBar.SetIndicators(indicators,
  53.         sizeof(indicators)/sizeof(UINT)))
  54.     {
  55.         return -1;      // fail to create
  56.     }
  57.     return 0;
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // Helpers for saving/restoring window state
  62.  
  63. static TCHAR BASED_CODE szSection[] = _T("Settings");
  64. static TCHAR BASED_CODE szWindowPos[] = _T("WindowPos");
  65. static TCHAR szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
  66.  
  67. static BOOL PASCAL NEAR ReadWindowPlacement(LPWINDOWPLACEMENT pwp)
  68. {
  69.     CString strBuffer = AfxGetApp()->GetProfileString(szSection, szWindowPos);
  70.     if (strBuffer.IsEmpty())
  71.         return FALSE;
  72.  
  73.     WINDOWPLACEMENT wp;
  74.     int nRead = _stscanf(strBuffer, szFormat,
  75.         &wp.flags, &wp.showCmd,
  76.         &wp.ptMinPosition.x, &wp.ptMinPosition.y,
  77.         &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
  78.         &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
  79.         &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
  80.  
  81.     if (nRead != 10)
  82.         return FALSE;
  83.  
  84.     wp.length = sizeof wp;
  85.     *pwp = wp;
  86.     return TRUE;
  87. }
  88.  
  89. static void PASCAL NEAR WriteWindowPlacement(LPWINDOWPLACEMENT pwp)
  90.     // write a window placement to settings section of app's ini file
  91. {
  92.     TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
  93.  
  94.     wsprintf(szBuffer, szFormat,
  95.         pwp->flags, pwp->showCmd,
  96.         pwp->ptMinPosition.x, pwp->ptMinPosition.y,
  97.         pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
  98.         pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
  99.         pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
  100.     AfxGetApp()->WriteProfileString(szSection, szWindowPos, szBuffer);
  101. }
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104.  
  105. void CMainFrame::InitialShowWindow(UINT nCmdShow)
  106. {
  107.     WINDOWPLACEMENT wp;
  108.     if (!ReadWindowPlacement(&wp))
  109.     {
  110.         ShowWindow(nCmdShow);
  111.         return;
  112.     }
  113.     if (nCmdShow != SW_SHOWNORMAL)
  114.         wp.showCmd = nCmdShow;
  115.     SetWindowPlacement(&wp);
  116.     ShowWindow(wp.showCmd);
  117. }
  118.  
  119. void CMainFrame::OnClose()
  120. {
  121.     // before it is destroyed, save the position of the window
  122.     WINDOWPLACEMENT wp;
  123.     wp.length = sizeof wp;
  124.     if (GetWindowPlacement(&wp))
  125.     {
  126.         wp.flags = 0;
  127.         if (IsZoomed())
  128.             wp.flags |= WPF_RESTORETOMAXIMIZED;
  129.         // and write it to the .INI file
  130.         WriteWindowPlacement(&wp);
  131.     }
  132.  
  133.     CMDIFrameWnd::OnClose();
  134. }
  135.  
  136. /////////////////////////////////////////////////////////////////////////////
  137.  
  138. /////////////////////////////////////////////////////////////////////////////
  139. // MyShowPane( LPCSTR text )
  140. // This displays the progress notification on the status bar
  141. void CMainFrame::MyShowPane( LPCSTR text )
  142.     m_wndStatusBar.SetPaneText(0,text,TRUE) ;
  143. }
  144.  
  145.