// DisplayCoclassDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TypeLibraryBrowser.h"
#include "DisplayCoclassDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#include <atlbase.h>


/////////////////////////////////////////////////////////////////////////////
// CDisplayCoclassDlg dialog


CDisplayCoclassDlg::CDisplayCoclassDlg(CWnd* pParent /*=NULL*/, ITypeInfoPtr pTypeInfo)
	: CDialog(CDisplayCoclassDlg::IDD, pParent)
{

	m_pTypeInfo = pTypeInfo ;

	//{{AFX_DATA_INIT(CDisplayCoclassDlg)
	//}}AFX_DATA_INIT
}


void CDisplayCoclassDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDisplayCoclassDlg)
	DDX_Control(pDX, IDC_LIST1, m_MemberList);
	DDX_Control(pDX, IDC_EDIT1, m_edGUID);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDisplayCoclassDlg, CDialog)
	//{{AFX_MSG_MAP(CDisplayCoclassDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDisplayCoclassDlg message handlers

BOOL CDisplayCoclassDlg::OnInitDialog() 
{
	USES_CONVERSION ;

	CDialog::OnInitDialog();
	
/*
Get name of enum, make it the title of the dialog box.
*/

	CComBSTR CoclassName ;
	m_pTypeInfo->GetDocumentation (-1, &CoclassName, NULL, NULL, NULL) ;

	CComBSTR DlgTitle ("CoClass: ") ;
	DlgTitle += CoclassName ;
	SetWindowText (W2A(DlgTitle)) ;

/*
Get number of functions and variables in the type info
*/
	TYPEATTR *pTA ;
	m_pTypeInfo->GetTypeAttr (&pTA) ;

/*
Put GUID in text control.
*/
	
	LPOLESTR pstrGuid ;
	StringFromCLSID (pTA->guid, &pstrGuid) ;
	m_edGUID.SetWindowText (W2A(pstrGuid)) ;
	CoTaskMemFree (pstrGuid) ;

/*
For each implemented interface, get its name, and put in list box for user to look at.
*/
	int i ;
	for (i = 0 ; i < pTA->cImplTypes ; i ++) 
	{
		HREFTYPE RefType ;
		m_pTypeInfo->GetRefTypeOfImplType (i, &RefType) ;


		ITypeInfoPtr pRefTypeInfo ;
		m_pTypeInfo->GetRefTypeInfo (RefType, &pRefTypeInfo) ;

		BSTR bstrName ;
		pRefTypeInfo->GetDocumentation (-1, &bstrName, NULL, NULL, NULL) ;

		_bstr_t bstrOut = bstrName ;

		m_MemberList.AddString ((char *) bstrOut) ;
		SysFreeString (bstrName) ;
	}

	m_pTypeInfo->ReleaseTypeAttr (pTA) ;
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
