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

  1. // PropSheet.cpp : implementation file
  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 "propsht.h"
  15. #include "EnrolDlg.h"
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CEnrollSheet
  25.  
  26. // IMPLEMENT_DYNAMIC(CEnrollSheet, CPropertySheet)
  27.  
  28. CEnrollSheet::CEnrollSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  29.     :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  30. {
  31.     //{{AFX_DATA_INIT(CEnrollSheet)
  32.         // NOTE: the ClassWizard will add member initialization here
  33.     //}}AFX_DATA_INIT
  34.     AddControlPages();
  35. }
  36.  
  37. CEnrollSheet::CEnrollSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  38.     :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
  39. {
  40.     //{{AFX_DATA_INIT(CEnrollSheet)
  41.         // NOTE: the ClassWizard will add member initialization here
  42.     //}}AFX_DATA_INIT
  43.     AddControlPages();
  44. }
  45.  
  46. CEnrollSheet::~CEnrollSheet()
  47. {
  48. }
  49.  
  50. void CEnrollSheet::AddControlPages()
  51. {
  52.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  53.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  54.     m_psh.dwFlags |= PSP_USEHICON;
  55.     m_psh.hIcon = m_hIcon;
  56.  
  57.     m_coursepage.m_pCourseRDC=&m_CourseRDC;   // the cursor is available inside Course dlg
  58.     m_sectionpage.m_pCourseRDC=&m_CourseRDC;  // the cursor is available inside Section dlg
  59.  
  60.     AddPage(&m_coursepage);
  61.     AddPage(&m_sectionpage);
  62.     AddPage(&m_instructpage);
  63.     AddPage(&m_studentpage);
  64. }
  65.  
  66. void CEnrollSheet::DoDataExchange(CDataExchange* pDX)
  67. {
  68.     CPropertySheet::DoDataExchange(pDX);
  69.     //{{AFX_DATA_MAP(CEnrollSheet)
  70.         // NOTE: the ClassWizard will add DDX and DDV calls here
  71.     //}}AFX_DATA_MAP
  72. }
  73.  
  74. BEGIN_MESSAGE_MAP(CEnrollSheet, CPropertySheet)
  75.     //{{AFX_MSG_MAP(CEnrollSheet)
  76.     ON_WM_SYSCOMMAND()
  77.     ON_WM_QUERYDRAGICON()
  78.     //}}AFX_MSG_MAP
  79. END_MESSAGE_MAP()
  80.  
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CEnrollSheet message handlers
  83.  
  84. BOOL CEnrollSheet::OnInitDialog()
  85. {
  86.     RECT r={ 0,0,150,30 };   // must create the control common to all prop pages
  87.     m_CourseRDC.Create(NULL,_T("Courses"),
  88.                        WS_VISIBLE | WS_CHILD, r, this, IDC_RDCCOURSE);
  89.     m_CourseRDC.SetDataSourceName(_T("Student Registration"));
  90.     m_CourseRDC.SetSql(_T("SELECT * from Course"));
  91.     m_CourseRDC.SetUserName(_T("admin"));
  92.     m_CourseRDC.SetPassword(_T(""));
  93.     m_CourseRDC.SetCursorDriver(2); // server side cursor
  94.  
  95.  
  96.     CPropertySheet::OnInitDialog(); // init the sheet before getting ClientRect
  97.  
  98.     GetClientRect(&r);
  99.     r.bottom-=4;r.top=r.bottom-30;  // place 30x150 control in
  100.     r.left+=2;r.right=r.left+150;   // left-bottom sheet corner
  101. //  m_CourseRDC.MoveWindow(&r,FALSE); //IOleObject::SetExtend() does not work on RDC2.0
  102.     ::MoveWindow(m_CourseRDC.m_hWnd,r.left,r.top,r.right-r.left,r.bottom-r.top, FALSE);
  103.  
  104.     // Add "About..." menu item to system menu.
  105.  
  106.     // IDM_ABOUTBOX must be in the system command range.
  107.  
  108.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  109.     ASSERT(IDM_ABOUTBOX < 0xF000);
  110.  
  111.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  112.     CString strAboutMenu;
  113.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  114.     if (!strAboutMenu.IsEmpty())
  115.     {
  116.         pSysMenu->AppendMenu(MF_SEPARATOR);
  117.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  118.     }
  119.  
  120.     // Set the icon for this dialog.  The framework does this automatically
  121.     // when the application's main window is not a dialog
  122.     SetIcon(m_hIcon, TRUE);         // Set big icon
  123.     SetIcon(m_hIcon, FALSE);        // Set small icon
  124.  
  125.     return TRUE;
  126. }
  127.  
  128. void CEnrollSheet::OnSysCommand(UINT nID, LPARAM lParam)
  129. {
  130.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  131.     {
  132.         CAboutDlg dlgAbout;
  133.         dlgAbout.DoModal();
  134.     }
  135.     else
  136.     {
  137.         CPropertySheet::OnSysCommand(nID, lParam);
  138.     }
  139. }
  140.  
  141. // The system calls this to obtain the cursor to display while the user drags
  142. // the minimized window.
  143. HCURSOR CEnrollSheet::OnQueryDragIcon()
  144. {
  145.     return (HCURSOR) m_hIcon;
  146. }
  147.  
  148. /////////////////////////////////////////////////////////////////////////////
  149. // CEnrollSheet event handlers
  150. BEGIN_EVENTSINK_MAP(CEnrollSheet, CPropertySheet)
  151.     ON_DSCNOTIFY(CEnrollSheet, IDC_RDCCOURSE, OnDSCNotify)
  152. END_EVENTSINK_MAP()
  153.  
  154. //////////////////////////////////////////////////////
  155. // This function is called each time the event was fired in IDC_RDCCOURSE control
  156. // We use it to adjust COURSE & STUDENT query parameters in
  157. // course & section pages
  158. //
  159. BOOL CEnrollSheet::OnDSCNotify(DSCSTATE nState, DSCREASON nReason, BOOL* pBool)
  160. {   // Course RDC's state changed
  161.     if(nReason==dscMove && nState==dscDidEvent) // row moved in course cursor
  162.     {   // notify datasources in all pages about the move
  163.         m_coursepage.OnCourseChanged();
  164.         m_sectionpage.OnCourseChanged();
  165.     }
  166.     return TRUE;  // event handled
  167.  
  168. }
  169.