// DisplayEnumDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TypeLibraryBrowser.h"
#include "DisplayEnumDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDisplayEnumDlg dialog


CDisplayEnumDlg::CDisplayEnumDlg(CWnd* pParent /*=NULL*/, ITypeInfoPtr pTypeInfo)
	: CDialog(CDisplayEnumDlg::IDD, pParent)
{
	m_pTypeInfo = pTypeInfo ;

	//{{AFX_DATA_INIT(CDisplayEnumDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


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


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

/////////////////////////////////////////////////////////////////////////////
// CDisplayEnumDlg message handlers

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

	BSTR EnumName ;
	m_pTypeInfo->GetDocumentation (-1, &EnumName, NULL, NULL, NULL) ;

	_bstr_t DlgTitle ("Enum: ") ;
	DlgTitle += EnumName ;
	SetWindowText ((char *) DlgTitle) ;
	SysFreeString (EnumName) ;

/*
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 variable, get its name and value, and put in list box for user to look at.
*/
	int i ;
	for (i = 0 ; i < pTA->cVars ; i ++) 
	{
		VARDESC *pVarDesc ;
		m_pTypeInfo->GetVarDesc (i, &pVarDesc) ;

		BSTR bstrName ;
		m_pTypeInfo->GetDocumentation (pVarDesc->memid , &bstrName, NULL, NULL, NULL) ;

		_bstr_t bstrOut = bstrName ;
		char out [36] ;
		bstrOut += " = " ;
		bstrOut += itoa (pVarDesc->lpvarValue->lVal, out, 10) ;

		m_MemberList.AddString ((char *) bstrOut) ;

		SysFreeString (bstrName) ;
		m_pTypeInfo->ReleaseVarDesc (pVarDesc) ;
	}

	m_pTypeInfo->ReleaseTypeAttr (pTA) ;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
