home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / propdlg / minifrm.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  96 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #include "shapeobj.h"
  14. #include "resource.h"
  15. #include "colorpge.h"
  16. #include "stylepge.h"
  17. #include "propsht2.h"
  18. #include "minifrm.h"
  19. #include "mainfrm.h"
  20.  
  21. BEGIN_MESSAGE_MAP(CShapePropSheetFrame, CMiniFrameWnd)
  22.     //{{AFX_MSG_MAP(CShapePropSheetFrame)
  23.     ON_WM_CREATE()
  24.     ON_WM_CLOSE()
  25.     ON_WM_SETFOCUS()
  26.     ON_WM_ACTIVATE()
  27.     //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29.  
  30. CShapePropSheetFrame::CShapePropSheetFrame()
  31. {
  32.     m_pModelessShapePropSheet = NULL;
  33. }
  34.  
  35. int CShapePropSheetFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  36. {
  37.     if (CMiniFrameWnd::OnCreate(lpCreateStruct) == -1)
  38.         return -1;
  39.  
  40.     m_pModelessShapePropSheet = new CModelessShapePropSheet(this);
  41.     if (!m_pModelessShapePropSheet->Create(this,
  42.         WS_CHILD | WS_VISIBLE, 0))
  43.     {
  44.         delete m_pModelessShapePropSheet;
  45.         m_pModelessShapePropSheet = NULL;
  46.         return -1;
  47.     }
  48.  
  49.     // Resize the mini frame so that it fits around the child property
  50.     // sheet.
  51.     CRect rectClient, rectWindow;
  52.     m_pModelessShapePropSheet->GetWindowRect(rectClient);
  53.     rectWindow = rectClient;
  54.  
  55.     // CMiniFrameWnd::CalcWindowRect adds the extra width and height
  56.     // needed from the mini frame.
  57.     CalcWindowRect(rectWindow);
  58.     SetWindowPos(NULL, rectWindow.left, rectWindow.top,
  59.         rectWindow.Width(), rectWindow.Height(),
  60.         SWP_NOZORDER | SWP_NOACTIVATE);
  61.     m_pModelessShapePropSheet->SetWindowPos(NULL, 0, 0,
  62.         rectClient.Width(), rectClient.Height(),
  63.         SWP_NOZORDER | SWP_NOACTIVATE);
  64.  
  65.     return 0;
  66. }
  67.  
  68. void CShapePropSheetFrame::OnClose()
  69. {
  70.     // Instead of closing the modeless property sheet, just hide it.
  71.     CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  72.     pMainFrame->HideModelessPropSheet();
  73. }
  74.  
  75. void CShapePropSheetFrame::OnSetFocus(CWnd* /*pOldWnd*/)
  76. {
  77.     // Forward focus to the embedded property sheet
  78.     ASSERT_VALID(m_pModelessShapePropSheet);
  79.     m_pModelessShapePropSheet->SetFocus();
  80. }
  81.  
  82. void CShapePropSheetFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
  83. {
  84.     CMiniFrameWnd::OnActivate(nState, pWndOther, bMinimized);
  85.  
  86.     // Forward any WM_ACTIVATEs to the property sheet...
  87.     // Like the dialog manager itself, it needs them to save/restore the focus.
  88.     ASSERT_VALID(m_pModelessShapePropSheet);
  89.  
  90.     // Use GetCurrentMessage to get unmodified message data.
  91.     const MSG* pMsg = GetCurrentMessage();
  92.     ASSERT(pMsg->message == WM_ACTIVATE);
  93.     m_pModelessShapePropSheet->SendMessage(pMsg->message, pMsg->wParam,
  94.         pMsg->lParam);
  95. }
  96.