- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
PropPageCntrDlg.cpp
上传用户:lc8096
上传日期:2007-01-02
资源大小:40k
文件大小:8k
源码类别:
ActiveX/DCOM/ATL
开发平台:
Visual C++
- // PropPageCntrDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "PropPageCntr.h"
- #include "PropPageCntrDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CPropPageCntrDlg dialog
- CPropPageCntrDlg::CPropPageCntrDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPropPageCntrDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CPropPageCntrDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CPropPageCntrDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPropPageCntrDlg)
- DDX_Control(pDX, IDC_RESULTS, m_wndListResults);
- DDX_Control(pDX, IDC_CONTROL, m_wndComboControl);
- DDX_Control(pDX, IDC_STATIC_PROPPAGE, m_wndStaticPropPage);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPropPageCntrDlg, CDialog)
- //{{AFX_MSG_MAP(CPropPageCntrDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_DESTROY()
- ON_BN_CLICKED(IDC_SHOW, OnShow)
- ON_CBN_SELENDOK(IDC_CONTROL, OnSelendokControl)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BEGIN_INTERFACE_MAP(CPropPageCntrDlg, CDialog)
- INTERFACE_PART(CPropPageCntrDlg, IID_IPropertyPageSite, PropertyPageSite)
- END_INTERFACE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPropPageCntrDlg message handlers
- BOOL CPropPageCntrDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- CWnd *pWndControl = NULL;
- int nIndex = 0;
- pWndControl = new CWnd();
- pWndControl->CreateControl( _T("{A56A23D3-79AF-11D2-8DC4-C36D152E46FE}"), NULL, 0, CRect( 0, 0, 0, 0 ), this, -1 );
- nIndex = m_wndComboControl.AddString( _T("MFC Control") );
- m_wndComboControl.SetItemDataPtr( nIndex, pWndControl );
- pWndControl = new CWnd();
- pWndControl->CreateControl( _T("{A56A23F2-79AF-11D2-8DC4-C36D152E46FE}"), NULL, 0, CRect( 0, 0, 0, 0 ), this, -1 );
- nIndex = m_wndComboControl.AddString( _T("ATL Control") );
- m_wndComboControl.SetItemDataPtr( nIndex, pWndControl );
- m_wndComboControl.SetCurSel(0);
- OnSelendokControl();
- return TRUE; // return TRUE unless you set the focus to a control
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CPropPageCntrDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CPropPageCntrDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- BOOL CPropPageCntrDlg::SetCurrentPage( IUnknown * pUnknown, LPRECT rc )
- {
- HRESULT hr = NOERROR;
- try
- {
- // hide previous page and release page pointer
- if( m_pCurrentPage != NULL )
- {
- m_pCurrentPage->Show( SW_HIDE );
- m_pCurrentPage->Deactivate();
- m_pCurrentPage = NULL;
- if( pUnknown == NULL ) return TRUE;
- }
- ISpecifyPropertyPagesPtr pSpecifyPropertyPages = pUnknown;
- CAUUID pages;
- hr = pSpecifyPropertyPages->GetPages( &pages );
- if( FAILED( hr ) ) throw _com_error( hr );
- ASSERT( pages.cElems > 0 && pages.pElems != NULL );
- IPropertyPagePtr pPropPage;
- hr = CoCreateInstance( pages.pElems[0], NULL, CLSCTX_INPROC, IID_IPropertyPage, (void**)&pPropPage );
- if( FAILED( hr ) ) throw _com_error( hr );
- hr = pPropPage->SetPageSite( (IPropertyPageSite*) GetInterface( &IID_IPropertyPageSite ) );
- if( FAILED( hr ) ) throw _com_error( hr );
- hr = pPropPage->SetObjects( 1, &pUnknown );
- if( FAILED( hr ) ) throw _com_error( hr );
- hr = pPropPage->Activate( GetSafeHwnd(), rc, TRUE );
- if( FAILED( hr ) ) throw _com_error( hr );
- hr = pPropPage->Show( SW_SHOW );
- if( FAILED( hr ) ) throw _com_error( hr );
- m_pCurrentPage = pPropPage;
- }
- catch( _com_error &e )
- {
- hr = e.Error();
- ASSERT( SUCCEEDED( hr ) );
- }
- return SUCCEEDED( hr );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CPropPageCntrDlg COM interface implementation
- STDMETHODIMP_( ULONG ) CPropPageCntrDlg::XPropertyPageSite::AddRef()
- {
- METHOD_PROLOGUE( CPropPageCntrDlg, PropertyPageSite )
- return pThis->ExternalAddRef();
- }
- STDMETHODIMP_( ULONG ) CPropPageCntrDlg::XPropertyPageSite::Release()
- {
- METHOD_PROLOGUE( CPropPageCntrDlg, PropertyPageSite )
- return pThis->ExternalRelease();
- }
- STDMETHODIMP CPropPageCntrDlg::XPropertyPageSite::QueryInterface( REFIID iid, void FAR* FAR* ppvObj)
- {
- METHOD_PROLOGUE( CPropPageCntrDlg, PropertyPageSite )
- return (HRESULT)pThis->ExternalQueryInterface( &iid, ppvObj );
- }
- STDMETHODIMP CPropPageCntrDlg::XPropertyPageSite::OnStatusChange( DWORD dwFlags )
- {
- METHOD_PROLOGUE( CPropPageCntrDlg, PropertyPageSite )
- return NOERROR;
- }
- STDMETHODIMP CPropPageCntrDlg::XPropertyPageSite::GetLocaleID( LCID *pLocaleID )
- {
- METHOD_PROLOGUE( CPropPageCntrDlg, PropertyPageSite )
- *pLocaleID = GetThreadLocale();
- return NOERROR;
- }
- STDMETHODIMP CPropPageCntrDlg::XPropertyPageSite::GetPageContainer( IUnknown **ppUnk )
- {
- METHOD_PROLOGUE( CPropPageCntrDlg, PropertyPageSite )
- return E_FAIL;
- }
- STDMETHODIMP CPropPageCntrDlg::XPropertyPageSite::TranslateAccelerator( MSG *pMsg )
- {
- METHOD_PROLOGUE( CPropPageCntrDlg, PropertyPageSite )
- return pThis->PreTranslateMessage( pMsg ) ? S_OK : S_FALSE;
- }
- void CPropPageCntrDlg::OnDestroy()
- {
- // TODO: Add your message handler code here
- SetCurrentPage( NULL, NULL );
- for( int nIndex = 0; nIndex < m_wndComboControl.GetCount(); nIndex++ )
- {
- CWnd *pWndControl = (CWnd*) m_wndComboControl.GetItemDataPtr( nIndex );
- pWndControl->DestroyWindow();
- delete pWndControl;
- }
- CDialog::OnDestroy();
- }
- void CPropPageCntrDlg::OnShow()
- {
- // TODO: Add your control notification handler code here
- int nIndex = m_wndComboControl.GetCurSel();
- if( nIndex == -1 ) return;
- CWnd *pWndControl = (CWnd*) m_wndComboControl.GetItemDataPtr( nIndex );
- if( pWndControl == NULL ) return;
- ASSERT( m_pCurrentPage != NULL );
- HRESULT hr = m_pCurrentPage->Apply();
- if( FAILED( hr ) ) return;
- pWndControl->InvokeHelper( 1, DISPATCH_METHOD, VT_EMPTY, NULL, NULL );
- }
- void CPropPageCntrDlg::OnSelendokControl()
- {
- // TODO: Add your control notification handler code here
- int nIndex = m_wndComboControl.GetCurSel();
- if( nIndex == -1 ) return;
- CWnd *pWndControl = (CWnd*) m_wndComboControl.GetItemDataPtr( nIndex );
- if( pWndControl == NULL ) return;
- CRect rtPropPage;
- m_wndStaticPropPage.GetWindowRect( &rtPropPage );
- ScreenToClient( &rtPropPage );
- SetCurrentPage( pWndControl->GetControlUnknown(), rtPropPage );
- m_wndListResults.ResetContent();
- }
- BEGIN_EVENTSINK_MAP(CPropPageCntrDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CPropPageCntrDlg)
- ON_EVENT(CPropPageCntrDlg, -1, 1 /* ObjectFound */, OnObjectFound, VTS_BSTR)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
- void CPropPageCntrDlg::OnObjectFound(LPCTSTR szObjectID)
- {
- // TODO: Add your control notification handler code here
- m_wndListResults.AddString( szObjectID );
- }