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 / propsht.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  98 lines

  1. // propsht.cpp : implementation of the CModalShapePropSheet class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "propdlg.h"
  15. #include "resource.h"
  16. #include "shapeobj.h"
  17. #include "colorpge.h"
  18. #include "stylepge.h"
  19. #include "preview.h"
  20. #include "propsht.h"
  21.  
  22. IMPLEMENT_DYNAMIC(CModalShapePropSheet, CPropertySheet)
  23.  
  24. BEGIN_MESSAGE_MAP(CModalShapePropSheet, CPropertySheet)
  25.     //{{AFX_MSG_MAP(CModalShapePropSheet)
  26.     ON_COMMAND(ID_APPLY_NOW, OnApplyNow)
  27.     //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29.  
  30. CModalShapePropSheet::CModalShapePropSheet(CWnd* pWndParent)
  31.     : CPropertySheet(AFX_IDS_APP_TITLE, pWndParent)
  32. {
  33.     AddPage(&m_stylePage);
  34.     AddPage(&m_colorPage);
  35. }
  36.  
  37. BOOL CModalShapePropSheet::OnInitDialog()
  38. {
  39.     BOOL bResult = CPropertySheet::OnInitDialog();
  40.  
  41.     // add the preview window to the property sheet.
  42.     CRect rectWnd;
  43.     GetWindowRect(rectWnd);
  44.     SetWindowPos(NULL, 0, 0,
  45.         rectWnd.Width() + 100,
  46.         rectWnd.Height(),
  47.         SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  48.     CRect rectPreview(rectWnd.Width() + 25, 25,
  49.         rectWnd.Width()+75, 75);
  50.     m_wndPreview.Create(NULL, NULL, WS_CHILD|WS_VISIBLE,
  51.         rectPreview, this, 0x1000);
  52.  
  53.     CenterWindow();
  54.     return bResult;
  55. }
  56.  
  57. void CModalShapePropSheet::SetSheetPropsFromShape(CShape* pShape)
  58. {
  59.     m_stylePage.m_nShapeStyle = pShape->m_shapestyle;
  60.     m_stylePage.SetModified(FALSE);
  61.  
  62.     m_colorPage.m_nColor = pShape->m_shapecolor;
  63.     m_colorPage.SetModified(FALSE);
  64.  
  65.     // Reflect the new shape properties in the controls of the
  66.     // currently active property page.
  67.     GetActivePage()->UpdateData(FALSE);
  68.  
  69.     UpdateShapePreview();
  70. }
  71.  
  72. void CModalShapePropSheet::SetShapePropsFromSheet(CShape* pShape)
  73. {
  74.     pShape->m_shapecolor = m_colorPage.m_nColor;
  75.     pShape->m_shapestyle = (SHAPE_STYLE)m_stylePage.m_nShapeStyle;
  76.  
  77.     m_colorPage.SetModified(FALSE);
  78.     m_stylePage.SetModified(FALSE);
  79. }
  80.  
  81. void CModalShapePropSheet::UpdateShapePreview()
  82. {
  83.     m_wndPreview.Invalidate();
  84.     m_wndPreview.UpdateWindow();
  85. }
  86.  
  87. void CModalShapePropSheet::OnApplyNow()
  88. {
  89.     Default();
  90.  
  91.     CFrameWnd* pFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
  92.     CView* pView = pFrameWnd->GetActiveFrame()->GetActiveView();
  93.     pView->SendMessage(WM_USER_CHANGE_OBJECT_PROPERTIES, 0, 0);
  94.     m_stylePage.SetModified(FALSE);
  95.     m_colorPage.SetModified(FALSE);
  96.     SendMessage(PSM_CANCELTOCLOSE);
  97. }
  98.