// maindlg.cpp : implementation file
//

#include "stdafx.h"
#include <fstream.h>
#include <windowsx.h>
#include "wltestc.h"
#include "maindlg.h" 
#include "wlapidlg.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

#define ID_SYSMENU_LOG			0x80

#define WM_APP_APIDLGDESTROY	(WM_USER + 5000)

extern CWLTestApp NEAR theApp;

/////////////////////////////////////////////////////////////////////////////
// CMainDlg dialog

BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
	//{{AFX_MSG_MAP(CMainDlg)
	ON_WM_SYSCOMMAND()
	ON_BN_CLICKED(IDC_BROWSER, OnBrowserAPI)
	ON_BN_CLICKED(IDC_HTML, OnHtmlAPI)
	ON_BN_CLICKED(IDC_TOOLBAR, OnToolbarAPI)
	ON_BN_CLICKED(IDC_UTIL, OnUtilAPI)
	ON_BN_CLICKED(IDC_GO_BTN, OnGoBtn)
	ON_LBN_DBLCLK(IDC_LISTAPI, OnDblclkListapi)
	ON_LBN_SELCHANGE(IDC_LISTAPI, OnSelchangeListapi)
	ON_BN_CLICKED(IDC_NOTIFY_BTN, OnNotifyBtn)
	ON_BN_CLICKED(IDC_STATUS_BTN, OnStatusBtn) 
	ON_UPDATE_COMMAND_UI(IDC_NOTIFY_BTN, OnNotifyUpdateCmdUI)
	ON_UPDATE_COMMAND_UI(IDC_STATUS_BTN, OnStatusUpdateCmdUI)
	ON_MESSAGE(WM_WEBLIB_NOTIFY, OnApiNotification)
	ON_MESSAGE(WM_WEBLIB_ENUMPARSETREE, OnEnumParseTree)
	ON_MESSAGE(WM_WEBLIB_ENUMFINDTEXT, OnEnumFindText)
	ON_MESSAGE(WM_WEBLIB_ENUMFINDSPEC, OnEnumFindSpecial)
	ON_MESSAGE(WM_WEBLIB_ENUMFINDCOMM, OnEnumFindComment)
	ON_MESSAGE(WM_WEBLIB_ENUMFINDTAGTYPE, OnEnumFindTagType)
	ON_MESSAGE(WM_WEBLIB_ENUMFINDTAGNAME, OnEnumFindTagName)
	ON_MESSAGE(WM_WEBLIB_ENUMFINDTAGATTR, OnEnumFindTagAttr) 
	ON_MESSAGE(WM_APP_APIDLGDESTROY, OnApiDlgDestroy) 
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/) : CDialog(CMainDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMainDlg)
	//}}AFX_DATA_INIT
	
	m_bLogging = AfxGetApp()->GetProfileInt("OPTIONS","LOGGING",FALSE);
	m_strLogFile = AfxGetApp()->GetProfileString("OPTIONS","LOGFILE");
	
	m_hBrowser = NULL;
	m_hToolbar = NULL;
	m_hParse = NULL;
	m_hFormData = NULL;
	
	m_hFont = NULL;
	m_hElement = NULL;
	m_hTagAttr = NULL;
	
	m_staRegURLEcho = FALSE;
	m_pnfyArray = NULL;  
	
	// Initialize WEBLIB dynamic link library.
	
	if (!WLStartup())											
		Error(IDS_ERR_WLAPI,"WLStartup"); 
}

CMainDlg::~CMainDlg()
{   
	if (m_bLogging)
		AfxGetApp()->WriteProfileString("OPTIONS","LOGFILE",m_strLogFile);
	AfxGetApp()->WriteProfileInt("OPTIONS","LOGGING",m_bLogging);
	
	m_ListboxInfo.Detach();
	m_ListboxAPI.Detach();
	
	if (m_hFont != NULL && m_hToolbar == NULL)
		::DeleteObject(m_hFont);
	
	// Detach from WEBLIB DLL.
	
	if (!WLCleanup())											
		Error(IDS_ERR_WLAPI,"WLCleanup"); 
}

void CMainDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMainDlg)
	//}}AFX_DATA_MAP
}

BOOL CMainDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	CenterWindow(CWnd::GetDesktopWindow());
	
	// Set WEBLIB default window for WLN_BROWSERSTART and WLN_BROWSEREXIT notifications.
	
	if (!WLSetDefaultNotify(m_hWnd,WM_WEBLIB_NOTIFY))				
		Error(IDS_ERR_WLAPI,"WLSetDefaultNotify");
		
	// Tell DLL containing dialogs to notify us when DLL dialog is destroyed. 
		
	ApiDlgNotifyOnWindowDestroy(m_hWnd,WM_APP_APIDLGDESTROY);
	
	// Add Log... option to system menu.
	
	CMenu *pMenu = GetSystemMenu(FALSE);
	ASSERT(pMenu != NULL);          
	
	CString strLogMenuText;
	strLogMenuText.LoadString(IDS_LOG_MENUTEXT);
	
	pMenu->AppendMenu(MF_SEPARATOR);
	pMenu->AppendMenu(MF_STRING,ID_SYSMENU_LOG,strLogMenuText);
	
	// Attach listbox class instances to controls (not very OO-like, oh well!).
	
	m_ListboxInfo.Attach(GetDlgItem(IDC_LISTINFO)->m_hWnd);
	m_ListboxAPI.Attach(GetDlgItem(IDC_LISTAPI)->m_hWnd);
	
	CRect rcClient;										// allow horz scrolling
	m_ListboxInfo.GetClientRect(rcClient);
	m_ListboxInfo.SetHorizontalExtent(rcClient.Width() * 3);
	
	GetDlgItem(IDC_CANCELTRX_BTN)->ShowWindow(SW_HIDE);	// no trx to cancel, hide button 
	
	// By default, check browser API calls.
	
	((CButton *) GetDlgItem(IDC_BROWSER))->SetCheck(TRUE);
	OnBrowserAPI();
	
	return TRUE;  				// return TRUE  unless you set the focus to a control
}
    
void CMainDlg::OnCancel()
{   
	GetSystemMenu(TRUE);		// restore standard system menu
	CDialog::OnCancel();
}

LRESULT CMainDlg::WindowProc(UINT message,WPARAM wParam,LPARAM lParam)
{
	LRESULT lResult = CDialog::WindowProc(message,wParam,lParam);
	
	if (message == WM_COMMAND)
		UpdateDialogControls(this,FALSE);
	return lResult;
}

void CMainDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == ID_SYSMENU_LOG)                 
	{
		(void) ApiDlgLogging(m_strLogFile.GetBufferSetLength(_MAX_PATH),
			_MAX_PATH,&m_bLogging);
		m_strLogFile.ReleaseBuffer();
	}
	else
		CDialog::OnSysCommand(nID,lParam);
}

void CMainDlg::OnDestroy()
{
	if (m_hBrowser != NULL)
		WLDisconnectBrowser(m_hBrowser,TRUE);	
	if (m_hToolbar != NULL)
		WLDeleteToolbar(m_hToolbar);
	if (m_hParse != NULL)
		WLHtmlEndParse(m_hParse);
	
	CDialog::OnDestroy();
}

///////////////////////////////////////////////////////////////////////////// 
// When an API radio button is clicked, tailor dialog to the particular API.

void CMainDlg::OnBrowserAPI()
{
	CString strGoBtn;
	strGoBtn.LoadString(m_hBrowser == NULL ? IDS_BTN_CONNECT : IDS_BTN_DISCONNECT);
	
	GetDlgItem(IDC_GO_BTN)->SetWindowText(strGoBtn);
	GetDlgItem(IDC_GO_BTN)->EnableWindow(TRUE);	
	GetDlgItem(IDC_STATUS_BTN)->EnableWindow(m_hBrowser != NULL);	
	GetDlgItem(IDC_NOTIFY_BTN)->EnableWindow(m_hBrowser != NULL);	
	
	CString strApiStatic;
	strApiStatic.LoadString(IDS_API_BROWSER);
	GetDlgItem(IDC_API_STATIC)->SetWindowText(strApiStatic);
	
	m_ListboxInfo.ResetContent();
	m_ListboxAPI.ResetContent();
	GetDlgItem(IDC_INFO_STATIC)->SetWindowText("");
	
	if (m_hBrowser != NULL)
	{
		for (int nIdx=0;theApp.m_pszBrowserAPIs[nIdx] != NULL;nIdx++)
			m_ListboxAPI.AddString(theApp.m_pszBrowserAPIs[nIdx]);
		m_ListboxAPI.SetCurSel(0);
	}
}

void CMainDlg::OnToolbarAPI()
{   
	CString strGoBtn;
	strGoBtn.LoadString(m_hToolbar == NULL ? IDS_BTN_CREATE : IDS_BTN_DELETE);
	
	GetDlgItem(IDC_GO_BTN)->SetWindowText(strGoBtn);
	GetDlgItem(IDC_GO_BTN)->EnableWindow(TRUE);	
	GetDlgItem(IDC_STATUS_BTN)->EnableWindow(m_hToolbar != NULL);	
	GetDlgItem(IDC_NOTIFY_BTN)->EnableWindow(m_hToolbar != NULL);	
	
	CString strApiStatic;
	strApiStatic.LoadString(IDS_API_TOOLBAR);
	GetDlgItem(IDC_API_STATIC)->SetWindowText(strApiStatic);
	
	m_ListboxInfo.ResetContent();
	m_ListboxAPI.ResetContent();
	GetDlgItem(IDC_INFO_STATIC)->SetWindowText("");
	
	if (m_hToolbar != NULL)
	{       
		for (int nIdx=0;theApp.m_pszToolbarAPIs[nIdx] != NULL;nIdx++)
			m_ListboxAPI.AddString(theApp.m_pszToolbarAPIs[nIdx]);
		m_ListboxAPI.SetCurSel(0);
	}
}   

void CMainDlg::OnHtmlAPI()
{   
	CString strGoBtn;
	strGoBtn.LoadString(m_hParse == NULL ? IDS_BTN_PARSE : IDS_BTN_ENDPARSE);
	
	GetDlgItem(IDC_GO_BTN)->SetWindowText(strGoBtn);
	GetDlgItem(IDC_GO_BTN)->EnableWindow(TRUE);	
	GetDlgItem(IDC_STATUS_BTN)->EnableWindow(FALSE);	
	GetDlgItem(IDC_NOTIFY_BTN)->EnableWindow(m_hParse != NULL);	
	
	CString strApiStatic;
	strApiStatic.LoadString(IDS_API_HTML);
	GetDlgItem(IDC_API_STATIC)->SetWindowText(strApiStatic);
	
	m_ListboxInfo.ResetContent();
	m_ListboxAPI.ResetContent();
	GetDlgItem(IDC_INFO_STATIC)->SetWindowText("");
	
	if (m_hParse != NULL)
	{       
		for (int nIdx=0;theApp.m_pszHtmlAPIs[nIdx] != NULL;nIdx++)
			m_ListboxAPI.AddString(theApp.m_pszHtmlAPIs[nIdx]);
		m_ListboxAPI.SetCurSel(0);
	}
}

void CMainDlg::OnUtilAPI()
{
	CString strGoBtn;
	strGoBtn.LoadString(IDS_BTN_ACCESSDATA);
	
	GetDlgItem(IDC_GO_BTN)->SetWindowText(strGoBtn);
	GetDlgItem(IDC_GO_BTN)->EnableWindow(m_hFormData != NULL );	
	GetDlgItem(IDC_STATUS_BTN)->EnableWindow(FALSE);	
	GetDlgItem(IDC_NOTIFY_BTN)->EnableWindow(FALSE);   
	
	CString strApiStatic;
	strApiStatic.LoadString(IDS_API_UTIL);
	GetDlgItem(IDC_API_STATIC)->SetWindowText(strApiStatic);
	
	m_ListboxInfo.ResetContent();
	m_ListboxAPI.ResetContent();        
	GetDlgItem(IDC_INFO_STATIC)->SetWindowText("");
	
	for (int nIdx=0;theApp.m_pszUtilAPIs[nIdx] != NULL;nIdx++)
		m_ListboxAPI.AddString(theApp.m_pszUtilAPIs[nIdx]);
	m_ListboxAPI.SetCurSel(0);
}

///////////////////////////////////////////////////////////////////////////// 
// On click of Go button, create or remove handle to browser, toolbar, parse
// tree or form data. Once we have a valid handle, the API calls become available.

void CMainDlg::OnGoBtn()
{
	CDisableDialog disable(this);
  							// for below to work, ordinal values of IDs better be correct!
	switch (GetCheckedRadioButton(IDC_BROWSER,IDC_UTIL))
	{
		case IDC_BROWSER:
			if (m_hBrowser == NULL)
				ConnectBrowserAPI();
			else
				DisconnectBrowserAPI();
			break;
		
		case IDC_TOOLBAR:
			if (m_hToolbar == NULL)
				CreateToolbarAPI();
			else
				DeleteToolbarAPI();
			break;
		
		case IDC_HTML:
			if (m_hParse == NULL)
				HtmlParseAPI();
			else               
				HtmlEndParseAPI();
			break;
		
		case IDC_UTIL: 
			AccessFormDataAPI();
			break;
	}
}

void CMainDlg::OnDblclkListapi()
{
	CDisableDialog disable(this);   
	int nSelAPI = m_ListboxAPI.GetCurSel();
	
	switch (GetCheckedRadioButton(IDC_BROWSER,IDC_UTIL))
	{
		case IDC_BROWSER:
			switch (nSelAPI)
			{ 
                case WLAPI_GetWindowInfo:
                	GetWindowInfoAPI();
                	break;
                	
                case WLAPI_ListWindows:
                	ListWindowsAPI();
                	break;
                	
                case WLAPI_ActivateWindow:
                	ActivateWindowAPI();
                	break;
                	
                case WLAPI_CloseWindow:
                	CloseWindowAPI();
                	break;
                	
                case WLAPI_SetWindowPos:
                	SetWindowPosAPI();
                	break;
                	
                case WLAPI_ShowWindow:
                	ShowWindowAPI();
                	break;
                	
                case WLAPI_ShowFile:
                	ShowFileAPI();
                	break;
                	
                case WLAPI_OpenURL:
                	OpenURLAPI();
                	break;
                	
                case WLAPI_SaveURL:
                	SaveURLAPI();
                	break;
                	
                case WLAPI_PostFormData:
                	PostFormDataAPI();
                	break;
                	
                case WLAPI_SaveFormData:
                	SaveFormDataAPI();
               		break;
               		
                case WLAPI_RegisterProtocol:
                	RegisterProtocolAPI();
                	break;
                	
                case WLAPI_UnregisterProtocol:
                	UnregisterProtocolAPI();
                	break;
                	
                case WLAPI_RegisterURLEcho:
                	RegisterURLEchoAPI();
                	break;
                	
                case WLAPI_UnregisterURLEcho:
               	 	UnregisterURLEchoAPI();
                	break;
                	
                case WLAPI_RegisterViewer:
                	RegisterViewerAPI();
                	break;
                	
                case WLAPI_UnregisterViewer:
                	UnregisterViewerAPI();
                	break;
                	
                case WLAPI_RegisterWindowChange:
                	RegisterWindowChangeAPI();
                	break;
                	
                case WLAPI_UnregisterWindowChange:
                	UnregisterWindowChangeAPI();
                	break;
                	
                case WLAPI_ParseAnchor:
                	ParseAnchorAPI();
                	break;
                	
                case WLAPI_GetVersion:
                	GetVersionAPI();
                	break;
                	
                case WLAPI_QueryURLFile:
                	QueryURLFileAPI();
                	break;
                	
                case WLAPI_SetNotifyMethod:
                	SetNotifyMethodAPI();
                	break;
                	
               	default:
  					::MessageBeep(-1);
  					break;
			}
			break;
		
		case IDC_TOOLBAR:
			switch (nSelAPI)
			{ 
                case WLAPI_IsToolbarActive:
                	IsToolbarActiveAPI();
                	break;
                	
                case WLAPI_SetActiveToolbar:
                	SetActiveToolbarAPI();
                	break;
                	
                case WLAPI_AddToolbarButton:
                	AddToolbarButtonAPI();
                	break;
                	
                case WLAPI_RemoveToolbarButton:
                	RemoveToolbarButtonAPI();
                	break;
                	
                case WLAPI_IsToolbarButtonVisible:
                	IsToolbarButtonVisibleAPI();
                	break;
                	
                case WLAPI_ShowToolbarButton:
                	ShowToolbarButtonAPI();
                	break;
                	
                case WLAPI_EnableToolbarButton:
                	EnableToolbarButtonAPI();
                	break;
                	
                case WLAPI_IsToolbarButtonEnabled:
                	IsToolbarButtonEnabledAPI();
                	break;
                	
                case WLAPI_GetToolbarText:
                	GetToolbarTextAPI();
                	break;
                	
                case WLAPI_SetToolbarText:
                	SetToolbarTextAPI();
					break;
                	                
                case WLAPI_GetToolbarFont:
                	GetToolbarFontAPI();
                	break;
                	
                case WLAPI_SetToolbarFont:
                	SetToolbarFontAPI();
                	break;
                	
                case WLAPI_GetToolbarBkgnd:
                	GetToolbarBkgndAPI();
                	break;
                	
                case WLAPI_SetToolbarBkgnd:
                	SetToolbarBkgndAPI();
                	break;
                	
                case WLAPI_GetToolbarTextColor: 
                	GetToolbarTextColorAPI();
                	break;
                	
                case WLAPI_SetToolbarTextColor: 
                	SetToolbarTextColorAPI();
                	break;
                			
  				default:
  					::MessageBeep(-1);
  					break;
			}
			break;
		
		case IDC_HTML:
			switch (nSelAPI)
			{
                case WLAPI_HtmlEnumParseTree:
               		HtmlEnumParseTreeAPI();
                	break;
                	
                case WLAPI_HtmlGetChild:
                	HtmlGetChildAPI();
                	break;
                	
                case WLAPI_HtmlGetParent:
                    HtmlGetParentAPI();
                	break;
                	
                case WLAPI_HtmlGetSibling:
                	HtmlGetSiblingAPI();
                	break;
                	
                case WLAPI_HtmlGetElementType:
                	HtmlGetElementTypeAPI();
                	break;
                	
                case WLAPI_HtmlGetElementText: 
                	HtmlGetElementTextAPI();
                	break;
                	
                case WLAPI_HtmlGetTextAttr: 
                	HtmlGetTextAttrAPI();
                	break;
                	
                case WLAPI_HtmlGetTagName: 
                	HtmlGetTagNameAPI();
                	break;
                	
                case WLAPI_HtmlGetTagType:
                	HtmlGetTagTypeAPI();
                	break;
                	
                case WLAPI_HtmlGetTagAttr:
                	HtmlGetTagAttrAPI();
                	break;
                	
                case WLAPI_HtmlExtractTagAttr:
                	HtmlExtractTagAttrAPI();
                	break;
                	
                case WLAPI_HtmlFindText:
                	HtmlFindTextAPI();
                	break;
                	
                case WLAPI_HtmlFindSpecial:
                	HtmlFindSpecialAPI();
                	break;
                	
                case WLAPI_HtmlFindComment:
                	HtmlFindCommentAPI();
                	break;
                	
                case WLAPI_HtmlFindTagType:
                	HtmlFindTagTypeAPI();
                	break;
                	
                case WLAPI_HtmlFindTagName:
                	HtmlFindTagNameAPI();
                	break;
                	
                case WLAPI_HtmlFindTagAttr:
                	HtmlFindTagAttrAPI();
                	break;
                	
                case WLAPI_HtmlEnumFindText:
                	HtmlEnumFindTextAPI();
                	break;
                	
                case WLAPI_HtmlEnumFindSpecial: 
                	HtmlEnumFindSpecialAPI();
                	break;
                	
                case WLAPI_HtmlEnumFindComment:
                	HtmlEnumFindCommentAPI();
                	break;
                	
                case WLAPI_HtmlEnumFindTagType:
                	HtmlEnumFindTagTypeAPI();
                	break;
                	
                case WLAPI_HtmlEnumFindTagName: 
                	HtmlEnumFindTagNameAPI();
                	break;
                	
                case WLAPI_HtmlEnumFindTagAttr:
                	HtmlEnumFindTagAttrAPI();
  					break;
  					
  				default:
  					::MessageBeep(-1);
  					break;
			}
			break;
		
		case IDC_UTIL: 
			switch (nSelAPI)
			{
                case WLAPI_AppendFormData:  
                	AppendFormDataAPI();
                 	break;
                 	
                case WLAPI_GetFormDataLength:
               		GetFormDataLengthAPI();
                 	break;
                 	
                case WLAPI_ParseAbsoluteURL:
                	ParseAbsoluteURLAPI();
                 	break;
					
  				default:
  					::MessageBeep(-1);
  					break;
			}
			break;
			
		default:    
			::MessageBeep(-1);
  			break;
	}
}

void CMainDlg::OnSelchangeListapi()
{   
	m_ListboxInfo.ResetContent(); 
	GetDlgItem(IDC_INFO_STATIC)->SetWindowText("");
}

void CMainDlg::OnNotifyBtn()
{           
	int nSelAPI = m_ListboxAPI.GetCurSel();

	CString strInfo;
	strInfo.LoadString(IDS_NOTIFY_TITLE);
	
	CString strText; 
	
	if (GetCheckedRadioButton(IDC_BROWSER,IDC_UTIL) == IDC_TOOLBAR)
		strText.LoadString(IDS_NOTIFY_TOOLBAR);
	else
		m_ListboxAPI.GetText(nSelAPI,strText);
	   
	strInfo += strText;
	GetDlgItem(IDC_INFO_STATIC)->SetWindowText(strInfo);
	
	switch (GetCheckedRadioButton(IDC_BROWSER,IDC_UTIL))
	{                     
		case IDC_BROWSER:                 
		{
			CStringArray *pnfyArray = NULL;	
			
			if (nSelAPI == WLAPI_ShowFile)
				pnfyArray = &m_nfyShowFile;
			else if (nSelAPI == WLAPI_OpenURL)
				pnfyArray = &m_nfyOpenURL;
			else if (nSelAPI == WLAPI_SaveURL)
				pnfyArray = &m_nfySaveURL;
			else if (nSelAPI == WLAPI_PostFormData)
				pnfyArray = &m_nfyPostFormData;
			else if (nSelAPI == WLAPI_SaveFormData)
				pnfyArray = &m_nfySaveFormData;
			else if (nSelAPI == WLAPI_RegisterProtocol)
				pnfyArray = &m_nfyRegProtocol;
			else if (nSelAPI == WLAPI_RegisterURLEcho)
				pnfyArray = &m_nfyRegURLEcho;
			else if (nSelAPI == WLAPI_RegisterViewer)
				pnfyArray = &m_nfyRegViewer;
			else if (nSelAPI == WLAPI_RegisterWindowChange)
				pnfyArray = &m_nfyRegWindowChange;
				
			if (pnfyArray != NULL)
				FillInfoListbox(*pnfyArray);
			break;
		}
		
		case IDC_TOOLBAR:
			FillInfoListbox(m_nfyToolbar);
			break;
		
		case IDC_HTML:    
		{
			CStringArray *pnfyArray = NULL;	
				
			if (nSelAPI == WLAPI_HtmlEnumParseTree)
				pnfyArray = &m_nfyEnumParseTree;
			else if (nSelAPI == WLAPI_HtmlEnumFindText)
				pnfyArray = &m_nfyEnumFindText;
			else if (nSelAPI == WLAPI_HtmlEnumFindSpecial)
				pnfyArray = &m_nfyEnumFindSpecial;
			else if (nSelAPI == WLAPI_HtmlEnumFindComment)
				pnfyArray = &m_nfyEnumFindComment;			
			else if (nSelAPI == WLAPI_HtmlEnumFindTagType)
				pnfyArray = &m_nfyEnumFindTagType;	
			else if (nSelAPI == WLAPI_HtmlEnumFindTagName)
				pnfyArray = &m_nfyEnumFindTagName;	
			else if (nSelAPI == WLAPI_HtmlEnumFindTagAttr)
				pnfyArray = &m_nfyEnumFindTagAttr;
			
			if (pnfyArray != NULL)
				FillInfoListbox(*pnfyArray);
			break;
		}
		
		case IDC_UTIL: 
			break;
	}	
}

void CMainDlg::OnStatusBtn()
{
	int nSelAPI = m_ListboxAPI.GetCurSel();   
	
	CString strInfo;
	strInfo.LoadString(IDS_STATUS_TITLE);
	
	CString strText; 
	
	if (GetCheckedRadioButton(IDC_BROWSER,IDC_UTIL) == IDC_TOOLBAR)
		strText.LoadString(IDS_STATUS_TOOLBAR);
	else
		m_ListboxAPI.GetText(nSelAPI,strText);
	   
	strInfo += strText;
	GetDlgItem(IDC_INFO_STATIC)->SetWindowText(strInfo);
	                                                       
	switch (GetCheckedRadioButton(IDC_BROWSER,IDC_UTIL))
	{                     
		case IDC_BROWSER:                 
		{
			CStringArray staArray,*pstaArray = NULL;	
			char szBuf[16];
			
			if (nSelAPI == WLAPI_RegisterProtocol)
				pstaArray = &m_staRegProtocol;
			else if (nSelAPI == WLAPI_RegisterViewer)
				pstaArray = &m_staRegViewer;
			else if (nSelAPI == WLAPI_RegisterURLEcho && m_staRegURLEcho)
			{   
				CString strStatus;                     
				strStatus.LoadString(IDS_STAT_URLECHO);
				
				staArray.Add(strStatus);
				pstaArray = &staArray;				
			}
			else if (nSelAPI == WLAPI_RegisterWindowChange)
			{
				for (int nIdx=0;nIdx < m_staRegWindowChange.GetSize();nIdx++)
					staArray.Add(CString(ltoa((long) m_staRegWindowChange[nIdx],szBuf,10)));
				pstaArray = &staArray;	
			}
				
			if (pstaArray != NULL)
				FillInfoListbox(*pstaArray);
			break;
		}
		
		case IDC_TOOLBAR:
		{                           
			CStringArray staArray;
			char szID[16];			
			
			for (int nIdx=0;nIdx < m_staToolbar.GetSize();nIdx++)
				staArray.Add(CString(itoa((int) m_staToolbar[nIdx],szID,10)));
			FillInfoListbox(staArray);
			break;
		}
		
		case IDC_HTML:    
			break;
		
		case IDC_UTIL: 
			break;
	}	
}

void CMainDlg::OnNotifyUpdateCmdUI(CCmdUI* pCmdUI)
{                       
	int nSelAPI = m_ListboxAPI.GetCurSel();
	BOOL bEnable = TRUE;
	
	switch (GetCheckedRadioButton(IDC_BROWSER,IDC_UTIL))
	{
		case IDC_BROWSER:
			if (bEnable = m_hBrowser != NULL)
				bEnable = nSelAPI == WLAPI_ShowFile ||
						  nSelAPI == WLAPI_OpenURL ||
						  nSelAPI == WLAPI_SaveURL ||
						  nSelAPI == WLAPI_PostFormData ||
						  nSelAPI == WLAPI_SaveFormData ||
						  nSelAPI == WLAPI_RegisterProtocol ||
						  nSelAPI == WLAPI_RegisterURLEcho ||
						  nSelAPI == WLAPI_RegisterViewer ||
						  nSelAPI == WLAPI_RegisterWindowChange;
			break;
		
		case IDC_TOOLBAR:
			bEnable = m_hToolbar != NULL;
			break;
		
		case IDC_HTML:
			if (bEnable = m_hParse != NULL)
				bEnable = nSelAPI == WLAPI_HtmlEnumParseTree ||
						  nSelAPI == WLAPI_HtmlEnumFindText ||
						  nSelAPI == WLAPI_HtmlEnumFindSpecial ||
						  nSelAPI == WLAPI_HtmlEnumFindComment ||
						  nSelAPI == WLAPI_HtmlEnumFindTagType ||
						  nSelAPI == WLAPI_HtmlEnumFindTagName ||
						  nSelAPI == WLAPI_HtmlEnumFindTagAttr;
			break;
		
		case IDC_UTIL: 
			bEnable = FALSE;
			break;
	}
	pCmdUI->Enable(bEnable);
}

void CMainDlg::OnStatusUpdateCmdUI(CCmdUI* pCmdUI)
{   
	int nSelAPI = m_ListboxAPI.GetCurSel();
	BOOL bEnable = TRUE;
	
	switch (GetCheckedRadioButton(IDC_BROWSER,IDC_UTIL))
	{
		case IDC_BROWSER:
			if (bEnable = m_hBrowser != NULL)
				bEnable = nSelAPI == WLAPI_RegisterProtocol ||
						  nSelAPI == WLAPI_RegisterURLEcho ||
						  nSelAPI == WLAPI_RegisterViewer ||
						  nSelAPI == WLAPI_RegisterWindowChange;
			break;
		
		case IDC_TOOLBAR:
			bEnable = m_hToolbar != NULL;
			break;
		
		case IDC_HTML:
			bEnable = FALSE;
			break;
		
		case IDC_UTIL: 
			bEnable = FALSE;
			break;
	}
	pCmdUI->Enable(bEnable);
}

///////////////////////////////////////////////////////////////////////////// 
// Methods for each WEBLIB API.

void CMainDlg::ConnectBrowserAPI()
{                            
	BOOL bStart = TRUE,bSend = FALSE,bPost = TRUE;
					
	if (ApiDlgConnectBrowser(&bStart,&bSend,&bPost))
	{
		WORD wOptions = (bStart ? WL_STARTBROWSER : 0) |
						(bSend  ? WL_SENDMESSAGE  : 0) |
						(bPost  ? WL_POSTMESSAGE  : 0);
										
		if ((m_hBrowser = WLConnectBrowser(wOptions)) == NULL) 		
			Error(IDS_ERR_WLAPI,"WLConnectBrowser"); 
		else
			ApiReturnValue("WLConnectBrowser");
		OnBrowserAPI();
	}
}

void CMainDlg::DisconnectBrowserAPI()
{  
	BOOL bExit = TRUE;
				 
	if (ApiDlgDisconnectBrowser(&bExit))
	{
		m_nfyShowFile.RemoveAll();
		m_nfyOpenURL.RemoveAll();
		m_nfySaveURL.RemoveAll();
		m_nfyPostFormData.RemoveAll();	
		m_nfySaveFormData.RemoveAll();
		m_nfyRegProtocol.RemoveAll();
		m_nfyRegURLEcho.RemoveAll();
		m_nfyRegViewer.RemoveAll();
		m_nfyRegWindowChange.RemoveAll();
	
		if (WLDisconnectBrowser(m_hBrowser,bExit))					
		{   
			ApiReturnValue("WLDisconnectBrowser");
			m_hBrowser = NULL;
			OnBrowserAPI();
		}
		else   
			Error(IDS_ERR_WLAPI,"WLDisconnectBrowser"); 
	}
}
		
void CMainDlg::CreateToolbarAPI()
{                            
	char szMenu[64] = "";
				
	if (ApiDlgCreateToolbar(szMenu,sizeof(szMenu)))
	{
		m_hToolbar = WLCreateToolbar(szMenu,m_hWnd,WM_WEBLIB_NOTIFY);
		if (m_hToolbar == NULL) 									
			Error(IDS_ERR_WLAPI,"WLCreateToolbar"); 
		else
			ApiReturnValue("WLCreateToolbar");
		OnToolbarAPI();
	}
}

void CMainDlg::DeleteToolbarAPI()
{   
	m_nfyToolbar.RemoveAll();
	
	if (WLDeleteToolbar(m_hToolbar))								
	{   
		ApiReturnValue("WLDeleteToolbar");
		m_hToolbar = NULL;
		OnToolbarAPI();
	}
	else   
		Error(IDS_ERR_WLAPI,"WLDeleteToolbar"); 
}
		
void CMainDlg::HtmlParseAPI()
{   
	BOOL bAttr = FALSE,bClosing = FALSE;                         
	char szFile[_MAX_PATH] = "",szBuf[MAX_HTMLBUF] = "";
	char *pszBuf = szBuf; 
	UINT cbBuf = sizeof(szBuf);
					
	if (ApiDlgHtmlParse(szFile,sizeof(szFile),pszBuf,cbBuf,&bAttr,&bClosing))
	{ 
		WORD wOptions = (bAttr ? WL_KEEPATTRIBUTETAG : 0) |
						(bClosing ? WL_KEEPCLOSINGTAG : 0);
										
		if (szFile[0])
			m_hParse = WLHtmlParseFile(szFile,wOptions);			
		else           
			m_hParse = WLHtmlParseBuf(pszBuf,lstrlen(pszBuf),wOptions);
							
		if (m_hParse == NULL) 
			Error(IDS_ERR_WLAPI,szFile[0] ? "WLHtmlParseFile" : "WLHtmlParseBuf"); 
		else 
		{
			ApiReturnValue(szFile[0] ? "WLHtmlParseFile" : "WLHtmlParseBuf");
			m_hElement = WL_ROOTELEMENT;
			m_hTagAttr = NULL;
		}
		OnHtmlAPI();
	}
}             

void CMainDlg::HtmlEndParseAPI()
{ 
	m_nfyEnumParseTree.RemoveAll();
	m_nfyEnumFindText.RemoveAll();
	m_nfyEnumFindSpecial.RemoveAll();
	m_nfyEnumFindComment.RemoveAll();
	m_nfyEnumFindTagType.RemoveAll();
	m_nfyEnumFindTagName.RemoveAll();
	m_nfyEnumFindTagAttr.RemoveAll(); 
	
	if (WLHtmlEndParse(m_hParse))									
	{   
		ApiReturnValue("WLHtmlEndParse");
		m_hParse = NULL;
		m_hElement = NULL;
		OnHtmlAPI();
	}
	else   
		Error(IDS_ERR_WLAPI,"WLHtmlEndParse"); 
}
		
void CMainDlg::AccessFormDataAPI()
{   
	ASSERT(m_hFormData != NULL);
	UINT nDataLength = WLGetFormDataLength(m_hFormData);            
			
	if (nDataLength == 0)
		Error(IDS_ERR_WLAPI,"WLGetFormDataLength"); 
	else 
	{   
		nDataLength += sizeof('\0');
		LPSTR lpszFormData = (LPSTR) GlobalAllocPtr(GHND,nDataLength);
				
		if (WLAccessFormData(m_hFormData,lpszFormData,nDataLength))
		{                                                           
			ApiDlgAccessFormData(lpszFormData);
			ApiReturnValue("WLAccessFormData");
		}
		else
			Error(IDS_ERR_WLAPI,"WLAccessFormData"); 
				
		GlobalFreePtr(lpszFormData);
		m_hFormData = NULL;
		OnUtilAPI();
	}
}

void CMainDlg::GetWindowInfoAPI()
{   
	DWORD dwWindow = 0;
	char szURL[128] = "",szTitle[128] = "";
	
	if (ApiDlgGetWindowInfo(&dwWindow))                             
		if (WLGetWindowInfo(m_hBrowser,dwWindow,szURL,sizeof(szURL),szTitle,sizeof(szTitle)))
			ApiReturnValue("WLGetWindowInfo",szURL,szTitle);
		else
			Error(IDS_ERR_WLAPI,"WLGetWindowInfo"); 
}

void CMainDlg::ListWindowsAPI()
{
	BOOL bFirst = FALSE;  
					
	if (ApiDlgListWindows(&bFirst))
	{
		DWORD dwWindow = WLListWindows(m_hBrowser,bFirst ? WL_FIRSTWINDOW : WL_NEXTWINDOW);
		char szWindow[16];                             				
		
		if (dwWindow == 0)
			Error(IDS_ERR_WLAPI,"WLListWindows"); 
		else                                       
			ApiReturnValue("WLListWindows",_ltoa((long) dwWindow,szWindow,10));
	}
}

void CMainDlg::ActivateWindowAPI()
{   
	DWORD dwWindow = 0;
	char szWindow[16];    
	
	if (ApiDlgActivateWindow(&dwWindow))
		if ((dwWindow = WLActivateWindow(m_hBrowser,dwWindow)))		
			ApiReturnValue("WLActivateWindow",_ltoa((long) dwWindow,szWindow,10));
		else
			Error(IDS_ERR_WLAPI,"WLActivateWindow"); 
}

void CMainDlg::CloseWindowAPI()
{   
	DWORD dwWindow = 0;
	
	if (ApiDlgCloseWindow(&dwWindow))
		if (WLCloseWindow(m_hBrowser,dwWindow))						
			ApiReturnValue("WLCloseWindow");
		else
			Error(IDS_ERR_WLAPI,"WLCloseWindow"); 
}

void CMainDlg::SetWindowPosAPI()
{   
	DWORD dwWindow = 0,dwX = 0,dwY = 0,dwWidth = 0,dwHeight = 0;
	
	if (ApiDlgSetWindowPos(&dwWindow,&dwX,&dwY,&dwWidth,&dwHeight))
		if (WLSetWindowPos(m_hBrowser,dwWindow,dwX,dwY,dwWidth,dwHeight))	
			ApiReturnValue("WLSetWindowPos");						
		else
			Error(IDS_ERR_WLAPI,"WLSetWindowPos"); 
}

void CMainDlg::ShowWindowAPI()
{   
	DWORD dwWindow = 0;
	UINT nShow = WL_NORMAL;
	
	if (ApiDlgShowWindow(&dwWindow,&nShow))
		if (WLShowWindow(m_hBrowser,dwWindow,nShow))				
			ApiReturnValue("WLShowWindow");
		else
			Error(IDS_ERR_WLAPI,"WLShowWindow"); 
}

void CMainDlg::ShowFileAPI()
{         
	BOOL bNotify = 0;
	DWORD dwWindow = 0;
	char szFile[128] = "",szMIME[64] = "",szURL[128] = "";
	
	if (ApiDlgShowFile(szFile,sizeof(szFile),szMIME,sizeof(szMIME),&bNotify,szURL,
		sizeof(szURL),&dwWindow))
	{
		(m_pnfyArray = &m_nfyShowFile)->RemoveAll();
	 
		DWORD dwTrx = WLShowFile(m_hBrowser,szFile,szMIME,dwWindow,szURL,
			bNotify ? m_hWnd : WL_NONOTIFY,bNotify ? WM_WEBLIB_NOTIFY : 0);
		char szTrx[16];											
			
		if (dwTrx == 0)
			Error(IDS_ERR_WLAPI,"WLShowFile"); 
		else
			ApiReturnValue("WLShowFile",_ltoa((long) dwTrx,szTrx,10));
	}
}

void CMainDlg::OpenURLAPI()
{   
	BOOL bBackground = FALSE,bNoDocCache = FALSE,bNoImageCache = FALSE,bNotify = TRUE;
	DWORD dwWindow = 0;
	char szURL[128] = "";

	if (ApiDlgOpenURL(&bBackground,&bNoDocCache,&bNoImageCache,&bNotify,szURL,
		sizeof(szURL),&dwWindow))
	{    
		(m_pnfyArray = &m_nfyOpenURL)->RemoveAll();
	
		WORD wOptions = (bBackground ? WL_BACKGROUNDMODE : 0) |       
						(bNoDocCache ? WL_NODOCUMENTCACHE : 0) |  
						(bNoImageCache ? WL_NOIMAGECACHE : 0);
		char szTrx[16];
						
		DWORD dwTrx = WLOpenURL(m_hBrowser,szURL,dwWindow,wOptions,		
			bNotify ? m_hWnd : WL_NONOTIFY,bNotify ? WM_WEBLIB_NOTIFY : 0);
			
		if (dwTrx == 0)
			Error(IDS_ERR_WLAPI,"WLOpenURL"); 
		else
			ApiReturnValue("WLOpenURL",_ltoa((long) dwTrx,szTrx,10));
	}
}

void CMainDlg::SaveURLAPI()
{       
	BOOL bBackground = FALSE,bNoDocCache = FALSE,bNoImageCache = FALSE,bNotify = TRUE;
	DWORD dwWindow = 0;
	char szURL[128] = "",szFile[128] = "";

	if (ApiDlgSaveURL(&bBackground,&bNoDocCache,&bNoImageCache,&bNotify,szURL,
		sizeof(szURL),szFile,sizeof(szFile),&dwWindow))
	{
		(m_pnfyArray = &m_nfySaveURL)->RemoveAll();
		
		WORD wOptions = (bBackground ? WL_BACKGROUNDMODE : 0) |       
						(bNoDocCache ? WL_NODOCUMENTCACHE : 0) |  
						(bNoImageCache ? WL_NOIMAGECACHE : 0);
		char szTrx[16];
						
		DWORD dwTrx = WLSaveURL(m_hBrowser,szURL,szFile,dwWindow,wOptions,	
			bNotify ? m_hWnd : WL_NONOTIFY,bNotify ? WM_WEBLIB_NOTIFY : 0);
			
		if (dwTrx == 0)
			Error(IDS_ERR_WLAPI,"WLSaveURL"); 
		else
			ApiReturnValue("WLSaveURL",_ltoa((long) dwTrx,szTrx,10));
	}
}

void CMainDlg::PostFormDataAPI()
{   
	BOOL bNotify = TRUE;
	DWORD dwWindow = 0;
	char szFormData[MAX_FORMDATA] = "",szMIME[64] = "",szURL[128] = "";

	if (ApiDlgPostFormData(szFormData,sizeof(szFormData),szMIME,sizeof(szMIME),
		&bNotify,szURL,sizeof(szURL),&dwWindow))
	{
		(m_pnfyArray = &m_nfyPostFormData)->RemoveAll();       
		
		DWORD dwTrx = WLPostFormData(m_hBrowser,szURL,dwWindow,szFormData,	
			szMIME,bNotify ? m_hWnd : WL_NONOTIFY,bNotify ? WM_WEBLIB_NOTIFY : 0);
		char szTrx[16];
			
		if (dwTrx == 0)
			Error(IDS_ERR_WLAPI,"WLPostFormData"); 
		else
			ApiReturnValue("WLPostFormData",_ltoa((long) dwTrx,szTrx,10));
	}
}

void CMainDlg::SaveFormDataAPI()
{
	BOOL bNotify = TRUE;
	DWORD dwWindow = 0;
	char szFile[128] = "",szFormData[MAX_FORMDATA] = "",szMIME[64] = "",szURL[128] = "";

	if (ApiDlgSaveFormData(szFile,sizeof(szFile),szFormData,sizeof(szFormData),
		szMIME,sizeof(szMIME),&bNotify,szURL,sizeof(szURL),&dwWindow))
	{
		(m_pnfyArray = &m_nfySaveFormData)->RemoveAll();
	
		DWORD dwTrx = WLSaveFormData(m_hBrowser,szURL,szFile,dwWindow,	
			szFormData,szMIME,bNotify ? m_hWnd : WL_NONOTIFY,
				bNotify ? WM_WEBLIB_NOTIFY : 0);
		char szTrx[16];
			
		if (dwTrx == 0)
			Error(IDS_ERR_WLAPI,"WLSaveFormData"); 
		else
			ApiReturnValue("WLSaveFormData",_ltoa((long) dwTrx,szTrx,10));
	}
}

void CMainDlg::RegisterProtocolAPI()
{
	char szProtocol[64] = "";
	
	if (ApiDlgRegisterProtocol(szProtocol,sizeof(szProtocol)))
	{
		if (WLRegisterProtocol(m_hBrowser,szProtocol,m_hWnd,WM_WEBLIB_NOTIFY))
		{
			m_staRegProtocol.Add(CString(szProtocol));
			ApiReturnValue("WLRegisterProtocol");
		}
		else
			Error(IDS_ERR_WLAPI,"WLRegisterProtocol"); 
	}
}

void CMainDlg::UnregisterProtocolAPI()
{
	char szProtocol[64] = "";
	
	if (ApiDlgUnregisterProtocol(szProtocol,sizeof(szProtocol)))
	{       
		RemoveFromStatusArray(m_staRegProtocol,CString(szProtocol));
		if (m_staRegProtocol.GetSize() == 0)
			m_nfyRegProtocol.RemoveAll();
		
		if (WLUnregisterProtocol(m_hBrowser,szProtocol,m_hWnd))
			ApiReturnValue("WLUnregisterProtocol");
		else
			Error(IDS_ERR_WLAPI,"WLUnregisterProtocol"); 
	}
}

void CMainDlg::RegisterURLEchoAPI()
{
	if (WLRegisterURLEcho(m_hBrowser,m_hWnd,WM_WEBLIB_NOTIFY))
	{
		m_staRegURLEcho = TRUE;
		ApiReturnValue("WLRegisterURLEcho");
	}
	else
		Error(IDS_ERR_WLAPI,"WLRegisterURLEcho"); 
}

void CMainDlg::UnregisterURLEchoAPI()
{       
	m_staRegURLEcho = FALSE;
	m_nfyRegURLEcho.RemoveAll();
	
	if (WLUnregisterURLEcho(m_hBrowser,m_hWnd))
		ApiReturnValue("WLUnregisterURLEcho");
	else
		Error(IDS_ERR_WLAPI,"WLUnregisterURLEcho"); 
}

void CMainDlg::RegisterViewerAPI()
{   
	BOOL bQueryViewer = FALSE,bShellExec = FALSE,bViewDocFile = TRUE;
	char szMIME[64] = "";
	
	if (ApiDlgRegisterViewer(szMIME,sizeof(szMIME),&bQueryViewer,&bShellExec,&bViewDocFile))
	{       
		WORD wOptions = (bQueryViewer ? WL_QUERYVIEWER : 0) |
						(bShellExec ? WL_SHELLEXECUTE : 0) |
						(bViewDocFile ? WL_VIEWDOCFILE : 0);
		
		if (WLRegisterViewer(m_hBrowser,szMIME,wOptions,m_hWnd,WM_WEBLIB_NOTIFY))
		{
			m_staRegViewer.Add(CString(szMIME));
			ApiReturnValue("WLRegisterViewer");
		}
		else
			Error(IDS_ERR_WLAPI,"WLRegisterViewer"); 
	}
}

void CMainDlg::UnregisterViewerAPI()
{   
	char szMIME[64] = "";
	
	if (ApiDlgUnregisterViewer(szMIME,sizeof(szMIME)))
	{               
		RemoveFromStatusArray(m_staRegViewer,CString(szMIME));
		if (m_staRegViewer.GetSize() == 0)
			m_nfyRegViewer.RemoveAll();
			
		if (WLUnregisterViewer(m_hBrowser,szMIME,m_hWnd))
			ApiReturnValue("WLUnregisterViewer");
		else
			Error(IDS_ERR_WLAPI,"WLUnregisterViewer"); 
	}
}

void CMainDlg::RegisterWindowChangeAPI()
{                                               
	DWORD dwWindow = 0;
	
	if (ApiDlgRegisterWindowChange(&dwWindow))
		if (WLRegisterWindowChange(m_hBrowser,dwWindow,m_hWnd,WM_WEBLIB_NOTIFY))
		{
			m_staRegWindowChange.Add(dwWindow);
			ApiReturnValue("WLRegisterWindowChange");
		}
		else
			Error(IDS_ERR_WLAPI,"WLRegisterWindowChange"); 
}

void CMainDlg::UnregisterWindowChangeAPI()
{   
	DWORD dwWindow = 0;
	
	if (ApiDlgUnregisterWindowChange(&dwWindow))
	{ 
		for (int nIdx=0;nIdx < m_staRegWindowChange.GetSize();nIdx++)
			if (dwWindow == m_staRegWindowChange[nIdx])
			{
				m_staRegWindowChange.RemoveAt(nIdx);
				break;
			}
		if (m_staRegWindowChange.GetSize() == 0)
			m_nfyRegWindowChange.RemoveAll();
			
		if (WLUnregisterWindowChange(m_hBrowser,dwWindow,m_hWnd))
			ApiReturnValue("WLUnregisterWindowChange");
		else
			Error(IDS_ERR_WLAPI,"WLUnregisterWindowChange"); 
	}
}

void CMainDlg::ParseAnchorAPI()
{
	char szAbsURL[128] = "",szRelURL[128] = "";
 
	if (ApiDlgParseAnchor(szAbsURL,sizeof(szAbsURL),szRelURL,sizeof(szRelURL)))
	{
		const char *pszURL = WLParseAnchor(m_hBrowser,szAbsURL,szRelURL);
		
		if (pszURL == NULL)
			Error(IDS_ERR_WLAPI,"WLParseAnchor"); 
		else
			ApiReturnValue("WLParseAnchor",pszURL);
	}
}

void CMainDlg::GetVersionAPI()
{   
	UINT nMajor = 0,nMinor = 0;
	
	if (ApiDlgGetVersion(&nMajor,&nMinor))
	{
		DWORD dwVersion = WLGetVersion(m_hBrowser,(WORD) nMajor,(WORD) nMinor);
		char szVersion[16];
		
		wsprintf(szVersion,"%d.%d",(int) HIWORD(dwVersion),(int) LOWORD(dwVersion));
		ApiReturnValue("WLGetVersion",szVersion);
	}
}

void CMainDlg::QueryURLFileAPI()
{   
	char szFile[128] = "";
	
	if (ApiDlgQueryFile(szFile,sizeof(szFile)))
	{
		const char *pszURL = WLQueryURLFile(m_hBrowser,szFile);
		
		if (pszURL == NULL)
			Error(IDS_ERR_WLAPI,"WLQueryURLFile"); 
		else
			ApiReturnValue("WLQueryURLFile",pszURL);
	}
}

void CMainDlg::SetNotifyMethodAPI()
{                                      
	BOOL bPost = TRUE;
	
	if (ApiDlgSetNotifyMethod(&bPost))
		if (WLSetNotifyMethod(m_hBrowser,bPost ? WL_POSTMESSAGE : WL_SENDMESSAGE))
			ApiReturnValue("WLSetNotifyMethod");
		else
			Error(IDS_ERR_WLAPI,"WLSetNotifyMethod"); 
}

void CMainDlg::IsToolbarActiveAPI()
{                       
	const char *pszBool = WLIsToolbarActive(m_hToolbar) ? "TRUE" : "FALSE";
	
	ApiReturnValue("WLIsToolbarActive",pszBool);	// no-op if only one toolbar
}

void CMainDlg::SetActiveToolbarAPI()
{
	if (WLSetActiveToolbar(m_hToolbar))
		ApiReturnValue("WLSetActiveToolbar");
	else
		Error(IDS_ERR_WLAPI,"WLSetActiveToolbar"); 
}

void CMainDlg::AddToolbarButtonAPI()
{       
	UINT nID = 100;
	int nIdx = 0,nBitmapStyle = 1,nBitmapMask = 0xF;
	char szText[128] = "";
		
	if (ApiDlgAddToolbarButton(&nID,&nIdx,szText,sizeof(szText),&nBitmapStyle,&nBitmapMask))
	{
		LPCSTR lpszBitmap = NULL,lpszBitmapSel = NULL;
		LPCSTR lpszBitmapFocus = NULL,lpszBitmapDisabled = NULL;
	    
	    if (_ISUP(nBitmapMask))
	    	lpszBitmap = MAKEINTRESOURCE(nBitmapStyle + APIDLG_BITMAP_UP);
	    if (_ISSEL(nBitmapMask))
	    	lpszBitmapSel = MAKEINTRESOURCE(nBitmapStyle + APIDLG_BITMAP_SEL);
	    if (_ISFOCUS(nBitmapMask))
	    	lpszBitmapFocus = MAKEINTRESOURCE(nBitmapStyle + APIDLG_BITMAP_FOCUS);
	    if (_ISDISABLED(nBitmapMask))
	    	lpszBitmapDisabled = MAKEINTRESOURCE(nBitmapStyle + APIDLG_BITMAP_DISABLED);
	
		if (WLAddToolbarButton(m_hToolbar,nID,nIdx,szText,GetApiDlgDLLInstance(),
			lpszBitmap,lpszBitmapSel,lpszBitmapFocus,lpszBitmapDisabled))
		{
			m_staToolbar.Add(nID);
			ApiReturnValue("WLAddToolbarButton");
		}
		else
			Error(IDS_ERR_WLAPI,"WLAddToolbarButton"); 
	}
}

void CMainDlg::RemoveToolbarButtonAPI()
{   
	UINT nID = 100;
	
	if (ApiDlgRemoveToolbarButton(&nID))
	{
		for (int nIdx=0;nIdx < m_staToolbar.GetSize();nIdx++)
			if (nID == m_staToolbar[nIdx])
			{
				m_staToolbar.RemoveAt(nIdx);
				break;
			}
		if (m_staToolbar.GetSize() == 0)
			m_nfyToolbar.RemoveAll();
			
		if (WLRemoveToolbarButton(m_hToolbar,nID))
			ApiReturnValue("WLRemoveToolbarButton");
		else
			Error(IDS_ERR_WLAPI,"WLRemoveToolbarButton"); 
	}
}

void CMainDlg::IsToolbarButtonVisibleAPI()
{   
	UINT nID = 100;
	
	if (ApiDlgIsToolbarButtonVisible(&nID))                          
	{
		const char *pszBool = WLIsToolbarButtonVisible(m_hToolbar,nID) ? "TRUE" : "FALSE";
		ApiReturnValue("WLIsToolbarButtonVisible",pszBool);
	}
}

void CMainDlg::ShowToolbarButtonAPI()
{   
	UINT nID = 100;
	BOOL bShow = TRUE;
	
	if (ApiDlgShowToolbarButton(&nID,&bShow))
		if (WLShowToolbarButton(m_hToolbar,nID,bShow))
			ApiReturnValue("WLShowToolbarButton");
		else
			Error(IDS_ERR_WLAPI,"WLShowToolbarButton"); 
}

void CMainDlg::EnableToolbarButtonAPI()
{   
	UINT nID = 100;
	BOOL bEnable = TRUE;
	
	if (ApiDlgEnableToolbarButton(&nID,&bEnable))
		if (WLEnableToolbarButton(m_hToolbar,nID,bEnable))
			ApiReturnValue("WLEnableToolbarButton");
		else
			Error(IDS_ERR_WLAPI,"WLEnableToolbarButton"); 
}

void CMainDlg::IsToolbarButtonEnabledAPI()
{   
	UINT nID = 100;
	
	if (ApiDlgIsToolbarButtonEnabled(&nID))
	{
		const char *pszBool = WLIsToolbarButtonEnabled(m_hToolbar,nID) ? "TRUE" : "FALSE";
		ApiReturnValue("WLIsToolbarButtonEnabled",pszBool);
	}
}

void CMainDlg::GetToolbarTextAPI()
{   
	UINT nID = 100;
	
	if (ApiDlgGetToolbarText(&nID))
	{
		const char *pszText = WLGetToolbarText(m_hToolbar,nID == 0 ? WL_TOOLBARTEXT : nID);
		
		if (pszText == NULL)
			Error(IDS_ERR_WLAPI,"WLGetToolbarText"); 
		else
			ApiReturnValue("WLGetToolbarText",pszText);
	}
}

void CMainDlg::SetToolbarTextAPI()
{   
	UINT nID = 100;                      
	char szText[128] = "";
	
	if (ApiDlgSetToolbarText(&nID,szText,sizeof(szText)))
		if (WLSetToolbarText(m_hToolbar,nID == 0 ? WL_TOOLBARTEXT : nID,szText))
			ApiReturnValue("WLSetToolbarText",szText);
		else
			Error(IDS_ERR_WLAPI,"WLSetToolbarText"); 
}

void CMainDlg::GetToolbarFontAPI()
{                         
	BOOL bToolbar = TRUE;
	
	if (ApiDlgGetToolbarFont(&bToolbar))
	{
		HFONT hFont = WLGetToolbarFont(m_hToolbar,bToolbar ? WL_TOOLBARFONT : WL_BUTTONFONT);
		
		if (hFont == NULL)
			Error(IDS_ERR_WLAPI,"WLGetToolbarFont"); 
		else
		{   
			LOGFONT LogFont;
			::GetObject(hFont,sizeof(LogFont),&LogFont);
			
			char szHeight[16];
			(void) _itoa((int) LogFont.lfHeight,szHeight,10);
			
			ApiReturnValue("WLGetToolbarFont",LogFont.lfFaceName,szHeight);
		}
	}
}

void CMainDlg::SetToolbarFontAPI()
{   
	BOOL bToolbar = TRUE;
	int nPointSize = 12; 
	char szFont[64] = "";
	
	if (ApiDlgSetToolbarFont(szFont,sizeof(szFont),&nPointSize,&bToolbar))
	{
		if (m_hFont != NULL)
		{
			::DeleteObject(m_hFont);
			m_hFont = NULL;
		}
			
		// Get logical horizontal pixels per inch from display device.
			
		CDC *pDC = GetDC();
		ASSERT(pDC != NULL);
			
		int nLogPixelsX = pDC->GetDeviceCaps(LOGPIXELSX);		
		ReleaseDC(pDC);  
		
		// Create logical font based on user's preferences.
	
		LOGFONT Logfont;
			
		memset(&Logfont,'\0',sizeof(Logfont));
		Logfont.lfCharSet = ANSI_CHARSET;
		Logfont.lfQuality = PROOF_QUALITY;
		Logfont.lfOutPrecision = OUT_TT_ONLY_PRECIS;		
		Logfont.lfWeight = FW_NORMAL;
		Logfont.lfHeight = -((nLogPixelsX * nPointSize) / 72);
		lstrcpyn(Logfont.lfFaceName,szFont,LF_FACESIZE);
			
		if ((m_hFont = ::CreateFontIndirect(&Logfont)) == NULL)
			Error(IDS_ERR_WINAPI,"CreateFontIndirect"); 
		else
			if (WLSetToolbarFont(m_hToolbar,bToolbar ? WL_TOOLBARFONT : WL_BUTTONFONT,m_hFont))
				ApiReturnValue("WLSetToolbarFont");
			else
				Error(IDS_ERR_WLAPI,"WLSetToolbarFont"); 
	}
}

void CMainDlg::GetToolbarBkgndAPI()
{
	COLORREF crBkgnd = WLGetToolbarBkgnd(m_hToolbar); 
	RGBQUAD rgbQuad;
	char szBuf[64];
	
	memcpy(&rgbQuad,&crBkgnd,sizeof(crBkgnd));
	wsprintf(szBuf,"RGB(%d,%d,%d)",rgbQuad.rgbBlue,rgbQuad.rgbGreen,rgbQuad.rgbRed);
	ApiReturnValue("WLGetToolbarBkgnd",szBuf);
}

void CMainDlg::SetToolbarBkgndAPI()
{
	int nRed = 0,nGreen = 0,nBlue = 0;

	if (ApiDlgSetToolbarBkgnd(&nRed,&nGreen,&nBlue))
		if (WLSetToolbarBkgnd(m_hToolbar,RGB(nRed,nGreen,nBlue)))
			ApiReturnValue("WLSetToolbarBkgnd");
		else
			Error(IDS_ERR_WLAPI,"WLSetToolbarBkgnd"); 
}

void CMainDlg::GetToolbarTextColorAPI()
{   
	BOOL bToolbar = TRUE;
	
	if (ApiDlgGetToolbarTextColor(&bToolbar))
	{
		COLORREF crBkgnd = WLGetToolbarTextColor(m_hToolbar,
			bToolbar ? WL_TOOLBARTEXTCOLOR : WL_BUTTONTEXTCOLOR);
		RGBQUAD rgbQuad;
		char szBuf[64];
		
		memcpy(&rgbQuad,&crBkgnd,sizeof(crBkgnd));
		wsprintf(szBuf,"RGB(%d,%d,%d)",rgbQuad.rgbBlue,rgbQuad.rgbGreen,rgbQuad.rgbRed);
		ApiReturnValue("WLGetToolbarTextColor",szBuf);
	}
}

void CMainDlg::SetToolbarTextColorAPI()
{   
	BOOL bToolbar = TRUE;
	int nRed = 0,nGreen = 0,nBlue = 0;
	
	if (ApiDlgSetToolbarTextColor(&nRed,&nGreen,&nBlue,&bToolbar)) 
		if (WLSetToolbarTextColor(m_hToolbar,
			bToolbar ? WL_TOOLBARTEXTCOLOR : WL_BUTTONTEXTCOLOR,
			RGB(nRed,nGreen,nBlue)))
			ApiReturnValue("WLSetToolbarTextColor");
		else
			Error(IDS_ERR_WLAPI,"WLSetToolbarTextColor"); 
}

void CMainDlg::HtmlEnumParseTreeAPI()
{
	m_nfyEnumParseTree.RemoveAll();
	
	if (WLHtmlEnumParseTree(m_hParse,m_hWnd,WM_WEBLIB_ENUMPARSETREE))
		ApiReturnValue("WLHtmlEnumParseTree");
	else
		Error(IDS_ERR_WLAPI,"WLHtmlEnumParseTree"); 
}

void CMainDlg::HtmlGetChildAPI()
{   
	HELEMENT hElement = WLHtmlGetChild(m_hParse,m_hElement);
	
	if (hElement == NULL)                               
		Error(IDS_ERR_WLAPI,"WLHtmlGetChild"); 
	else
	{
		ApiReturnValue("WLHtmlGetChild");
		m_hElement = hElement;
		m_hTagAttr = NULL;
	}
}

void CMainDlg::HtmlGetParentAPI()
{   
	HELEMENT hElement = WLHtmlGetParent(m_hParse,m_hElement);
	
	if (hElement == NULL)                               
		Error(IDS_ERR_WLAPI,"WLHtmlGetParent"); 
	else
	{
		ApiReturnValue("WLHtmlGetParent");
		m_hElement = hElement;
		m_hTagAttr = NULL;
	}
}

void CMainDlg::HtmlGetSiblingAPI()
{
	UINT nRel = WL_FIRSTELEM;
	
	if (ApiDlgHtmlGetSibling(&nRel))
	{
		HELEMENT hElement = WLHtmlGetSibling(m_hParse,m_hElement,nRel);
		
		if (hElement == NULL)                               
			Error(IDS_ERR_WLAPI,"WLHtmlGetSibling"); 
		else
		{
			ApiReturnValue("WLHtmlGetSibling");
			m_hElement = hElement;
			m_hTagAttr = NULL;
		}
	}
}

void CMainDlg::HtmlGetElementTypeAPI()
{       
	const char *pszType = "?";
	
	switch (WLHtmlGetElementType(m_hParse,m_hElement))
	{
		case WL_ROOT:
			pszType = "ROOT";
			break;
			
		case WL_TAG:
			pszType = "TAG";
			break;
			
		case WL_SPECIALCHAR:
			pszType = "SPECIAL-CHAR";
			break;
			
		case WL_COMMENT:
			pszType = "COMMENT";
			break;
			
		case WL_TEXT:
			pszType = "TEXT";
			break;
	}       
	ApiReturnValue("WLHtmlGetElementType",pszType);
}

void CMainDlg::HtmlGetElementTextAPI()
{
	const char *pszText = WLHtmlGetElementText(m_hParse,m_hElement);
	
	ApiReturnValue("WLHtmlGetElementText",pszText == NULL ? "" : pszText);
}

void CMainDlg::HtmlGetTextAttrAPI()
{   
	if (WLHtmlGetElementType(m_hParse,m_hElement) == WL_TEXT)
	{
		DWORD dwAttr = WLHtmlGetTextAttr(m_hParse,m_hElement);
		char szAttr[16] = "0x";
		
		_ltoa((long) dwAttr,&szAttr[2],16);
		ApiReturnValue("WLHtmlGetTextAttr",szAttr);
	}
	else 
		Error(IDS_ERR_NOTTEXT); 
}

void CMainDlg::HtmlGetTagNameAPI()
{   
	if (WLHtmlGetElementType(m_hParse,m_hElement) == WL_TAG)
	{
		const char *pszTag = WLHtmlGetTagName(m_hParse,m_hElement);
		ApiReturnValue("WLHtmlGetTagName",pszTag);
	}
	else
		Error(IDS_ERR_NOTTAG); 
}

void CMainDlg::HtmlGetTagTypeAPI()
{   
	if (WLHtmlGetElementType(m_hParse,m_hElement) == WL_TAG)
	{
		UINT nType = WLHtmlGetTagType(m_hParse,m_hElement);
		char szType[16];
		
		_itoa((int) nType,szType,10);
		ApiReturnValue("WLHtmlGetTagType",szType);
	}
	else
		Error(IDS_ERR_NOTTAG); 
}

void CMainDlg::HtmlGetTagAttrAPI()
{   
	WORD wType = 0;
	char szAttr[128] = "",szValue[128] = "";
	
	if (m_hTagAttr = WLHtmlGetTagAttr(m_hParse,m_hElement,m_hTagAttr,
		&wType,szAttr,sizeof(szAttr),szValue,sizeof(szValue)))
		ApiReturnValue("WLHtmlGetTagAttr",szValue,szAttr);
	else
		Error(IDS_ERR_WLAPI,"WLHtmlGetTagAttr"); 
}

void CMainDlg::HtmlExtractTagAttrAPI()
{
	char szAttr[64] = "";
	
	if (ApiDlgHtmlExtractTagAttr(szAttr,sizeof(szAttr)))                               
	{
		const char *pszValue = WLHtmlExtractTagAttr(m_hParse,m_hElement,szAttr);
		
		if (pszValue == NULL)
			Error(IDS_ERR_WLAPI,"WLHtmlExtractTagAttr"); 
		else
			ApiReturnValue("WLHtmlExtractTagAttr",pszValue);
	}
}

void CMainDlg::HtmlFindTextAPI()
{   
	char szText[128] = "";
	
	if (ApiDlgHtmlFindText(szText,sizeof(szText))) 
	{
		HELEMENT hElement = WLHtmlFindText(m_hParse,m_hElement,szText);
		
		if (hElement == NULL)                               
			Error(IDS_ERR_WLAPI,"WLHtmlFindText"); 
		else
		{
			ApiReturnValue("WLHtmlFindText");
			m_hElement = hElement;
			m_hTagAttr = NULL;
		}
	}
}

void CMainDlg::HtmlFindSpecialAPI()
{   
	char szSpecial[128] = "";
	
	if (ApiDlgHtmlFindSpecial(szSpecial,sizeof(szSpecial)))
	{
		HELEMENT hElement = WLHtmlFindSpecial(m_hParse,m_hElement,szSpecial);
		
		if (hElement == NULL)                               
			Error(IDS_ERR_WLAPI,"WLHtmlFindSpecial"); 
		else
		{
			ApiReturnValue("WLHtmlFindSpecial");
			m_hElement = hElement;
			m_hTagAttr = NULL;
		}
	}
}

void CMainDlg::HtmlFindCommentAPI()
{   
	char szComment[128] = "";
	
	if (ApiDlgHtmlFindComment(szComment,sizeof(szComment)))
	{   
		HELEMENT hElement = WLHtmlFindComment(m_hParse,m_hElement,szComment);
		
		if (hElement == NULL)                               
			Error(IDS_ERR_WLAPI,"WLHtmlFindComment"); 
		else
		{
			ApiReturnValue("WLHtmlFindComment");
			m_hElement = hElement;
			m_hTagAttr = NULL;
		}
	}
}

void CMainDlg::HtmlFindTagTypeAPI()
{   
	UINT nTag = HTML_BASE;
	
	if (ApiDlgHtmlFindTagType(&nTag))
	{   
		HELEMENT hElement = WLHtmlFindTagType(m_hParse,m_hElement,nTag);
		
		if (hElement == NULL)                               
			Error(IDS_ERR_WLAPI,"WLHtmlFindTagType"); 
		else
		{
			ApiReturnValue("WLHtmlFindTagType");
			m_hElement = hElement;
			m_hTagAttr = NULL;
		}
	}
}

void CMainDlg::HtmlFindTagNameAPI()
{   
	char szTag[64] = "";
	
	if (ApiDlgHtmlFindTagName(szTag,sizeof(szTag)))
	{   
	    HELEMENT hElement = WLHtmlFindTagName(m_hParse,m_hElement,szTag);
		
		if (hElement == NULL)                               
			Error(IDS_ERR_WLAPI,"WLHtmlFindTagName"); 
		else
		{
			ApiReturnValue("WLHtmlFindTagName");
			m_hElement = hElement;
			m_hTagAttr = NULL;
		}
	}
}

void CMainDlg::HtmlFindTagAttrAPI()
{   
	UINT nTag = HTML_BASE;    
	char szAttr[64] = "",szValue[64] = "";
		
	if (ApiDlgHtmlFindTagAttr(szAttr,sizeof(szAttr),szValue,sizeof(szValue),&nTag))
	{
		HELEMENT hElement = WLHtmlFindTagAttr(m_hParse,m_hElement,nTag,szAttr,szValue);
		
		if (hElement == NULL)                               
			Error(IDS_ERR_WLAPI,"WLHtmlFindTagAttr"); 
		else
		{
			ApiReturnValue("WLHtmlFindTagAttr");
			m_hElement = hElement;
			m_hTagAttr = NULL;
		}
	}
}

void CMainDlg::HtmlEnumFindTextAPI()
{
	char szText[128] = ""; 
	
	if (ApiDlgHtmlEnumFindText(szText,sizeof(szText)))
	{
		m_nfyEnumFindText.RemoveAll();
		
		if (WLHtmlEnumFindText(m_hParse,m_hElement,szText,m_hWnd,WM_WEBLIB_ENUMFINDTEXT))
			ApiReturnValue("WLHtmlEnumFindText");
		else
			Error(IDS_ERR_WLAPI,"WLHtmlEnumFindText"); 
	}
}

void CMainDlg::HtmlEnumFindSpecialAPI()
{
	char szSpecial[128] = "";
	
	if (ApiDlgHtmlEnumFindSpecial(szSpecial,sizeof(szSpecial)))
	{
		m_nfyEnumFindSpecial.RemoveAll();
		
		if (WLHtmlEnumFindSpecial(m_hParse,m_hElement,szSpecial,m_hWnd,WM_WEBLIB_ENUMFINDSPEC))
			ApiReturnValue("WLHtmlEnumFindSpecial");
		else
			Error(IDS_ERR_WLAPI,"WLHtmlEnumFindSpecial"); 
	}
}

void CMainDlg::HtmlEnumFindCommentAPI()
{
	char szComment[128] = "";
	
	if (ApiDlgHtmlEnumFindComment(szComment,sizeof(szComment)))
	{
		m_nfyEnumFindComment.RemoveAll();
		
		if (WLHtmlEnumFindComment(m_hParse,m_hElement,szComment,m_hWnd,WM_WEBLIB_ENUMFINDCOMM))
			ApiReturnValue("WLHtmlEnumFindComment");
		else
			Error(IDS_ERR_WLAPI,"WLHtmlEnumFindComment"); 
	}
}

void CMainDlg::HtmlEnumFindTagTypeAPI()
{
	UINT nTag = HTML_BASE;
	
	if (ApiDlgHtmlEnumFindTagType(&nTag))
	{
		m_nfyEnumFindTagType.RemoveAll();
		
		if (WLHtmlEnumFindTagType(m_hParse,m_hElement,nTag,m_hWnd,WM_WEBLIB_ENUMFINDTAGTYPE))
			ApiReturnValue("WLHtmlEnumFindTagType");
		else
			Error(IDS_ERR_WLAPI,"WLHtmlEnumFindTagType"); 
	}
}

void CMainDlg::HtmlEnumFindTagNameAPI()
{
	char szTag[64] = "";
	
	if (ApiDlgHtmlEnumFindTagName(szTag,sizeof(szTag)))
	{
		m_nfyEnumFindTagName.RemoveAll();
		
	 	if (WLHtmlEnumFindTagName(m_hParse,m_hElement,szTag,m_hWnd,WM_WEBLIB_ENUMFINDTAGNAME))
	 		ApiReturnValue("WLHtmlEnumFindTagName");
		else
			Error(IDS_ERR_WLAPI,"WLHtmlEnumFindTagName"); 
	}
}

void CMainDlg::HtmlEnumFindTagAttrAPI()
{   
	UINT nTag = HTML_BASE;    
	char szAttr[64] = "",szValue[64] = "";
		
	if (ApiDlgHtmlEnumFindTagAttr(szAttr,sizeof(szAttr),szValue,sizeof(szValue),&nTag))
	{
		m_nfyEnumFindTagAttr.RemoveAll();
		
		if (WLHtmlEnumFindTagAttr(m_hParse,m_hElement,nTag,szAttr,szValue,m_hWnd,WM_WEBLIB_ENUMFINDTAGATTR))
			ApiReturnValue("WLHtmlEnumFindTagAttr");
		else
			Error(IDS_ERR_WLAPI,"WLHtmlEnumFindTagAttr"); 
	}
}

void CMainDlg::AppendFormDataAPI()
{   
	char szData[MAX_FORMDATA] = "",szName[64] = "";
	
	if (ApiDlgAppendFormData(szData,sizeof(szData),szName,sizeof(szName)))
	{
		m_hFormData = WLAppendFormData(m_hFormData,szName,szData,lstrlen(szData) + 1);
		
		if (m_hFormData == NULL)
		    Error(IDS_ERR_WLAPI,"WLAppendFormData"); 
		else
		{
			OnUtilAPI();
			ApiReturnValue("WLAppendFormData");
		}
	}
}

void CMainDlg::GetFormDataLengthAPI()
{
	UINT nLength = WLGetFormDataLength(m_hFormData);
	char szLength[16];
	
	ApiReturnValue("WLGetFormDataLength",_itoa((int) nLength,szLength,10));
}

void CMainDlg::ParseAbsoluteURLAPI()
{                          
	char szURL[128] = "";
	
	if (ApiDlgParseAbsoluteURL(szURL,sizeof(szURL)))
	{
		char szProtocol[32] = "",szHost[64] = "",szPath[128] = "";
		UINT nPort = 0;
	
		if (WLParseAbsoluteURL(szURL,szProtocol,sizeof(szProtocol),szHost,sizeof(szHost),
			&nPort,szPath,sizeof(szPath)))
		{
			char szBuf[256];
			
			wsprintf(szBuf,"%s %s %d %s",szProtocol,szHost,nPort,szPath);
			ApiReturnValue("WLParseAbsoluteURL",szBuf);
		}
		else
		  	Error(IDS_ERR_WLAPI,"WLParseAbsoluteURL");
	}
}

///////////////////////////////////////////////////////////////////////////// 
// Message handler for API notifications.

LONG CMainDlg::OnApiNotification(UINT wParam,LONG lParam)
{
	CStringArray *pnfyArray = m_pnfyArray;	
	char szMessage[512];
	
	switch (wParam)
	{
		case WLN_BEGINPROGRESS: 
		{ 
			DWORD dwTrx = WLNGetTransaction(lParam);
			const char *pszProgress = WLNGetProgressString(lParam);
			
			wsprintf(szMessage,"BEGINPROGRESS: %ld %s",dwTrx,pszProgress);
			break;
		}
		
		case WLN_SETPROGRESSRANGE:      
		{   
			DWORD dwTrx = WLNGetTransaction(lParam);
			DWORD dwMaximum = WLNGetProgressMaximum(lParam);
			
			wsprintf(szMessage,"SETPROGRESSRANGE: %ld %ld",dwTrx,dwMaximum);
			break;
		}		
			
		case WLN_MAKINGPROGRESS:      
		{   
			DWORD dwTrx = WLNGetTransaction(lParam);
			DWORD dwProgress = WLNGetProgressValue(lParam);
			const char *pszProgress = WLNGetProgressString(lParam);
			
			wsprintf(szMessage,"MAKINGPROGRESS: %ld %ld %s",dwTrx,dwProgress,pszProgress);
			break;
		}
		
		case WLN_ENDPROGRESS:      
		{   
			DWORD dwTrx = WLNGetTransaction(lParam);
			
			wsprintf(szMessage,"ENDPROGRESS: %ld",dwTrx);
			break;
		}
		
		case WLN_FINISHED:      
		{   
			DWORD dwTrx = WLNGetTransaction(lParam);
			DWORD dwWindow = WLNGetWindow(lParam);
			
			wsprintf(szMessage,"FINISHED: %ld %ld",dwTrx,dwWindow);
			break;
		}
		
		case WLN_CANCELED:      
		{   
			DWORD dwTrx = WLNGetTransaction(lParam);
			
			wsprintf(szMessage,"CANCELED: %ld",dwTrx);
			break;
		}			
		
		case WLN_URLECHO:
		{   
			DWORD dwWindow = WLNGetWindow(lParam);
			const char *pszURL = WLNGetURL(lParam);
			const char *pszMIME = WLNGetMIMEType(lParam);
			const char *pszRef = WLNGetReferrer(lParam);
			
			wsprintf(szMessage,"URLECHO: %ld %s %s %s",dwWindow,pszURL,pszMIME,pszRef);
			pnfyArray = &m_nfyRegURLEcho;
			break;
		}
		
		case WLN_OPENURL:
		{   
			DWORD dwWindow = WLNGetWindow(lParam);
			DWORD dwTrx = WLNGetTransaction(lParam);
			DWORD dwFlags = WLNGetFlags(lParam);
			const char *pszURL = WLNGetURL(lParam);
			const char *pszMIME = WLNGetMIMEType(lParam);
			const char *pszSaveFile = WLNGetSaveFile(lParam);
			const char *pszFormData = WLNGetFormData(lParam);
			
			wsprintf(szMessage,
				"OPENURL: WIN=%ld TX=%ld FL=%ld URL=%s MIME=%s FILE=%s FMDATA=%s",
				dwWindow,dwTrx,dwFlags,pszURL,pszMIME,pszSaveFile,pszFormData);
			pnfyArray = &m_nfyRegProtocol;
			break;
		}
		
		case WLN_WINDOWCHANGE:
		{   
			DWORD dwWindow = WLNGetWindow(lParam);
			DWORD dwFlags = WLNGetFlags(lParam);
			DWORD dwX = WLNGetX(lParam);
			DWORD dwY = WLNGetY(lParam);
			DWORD dwWidth = WLNGetWidth(lParam);
			DWORD dwHeight = WLNGetHeight(lParam);
			
			wsprintf(szMessage,"WINDOWCHANGE: WIN=%ld FL=%ld X=%ld Y=%ld CX=%ld CY=%ld",
				dwWindow,dwFlags,dwX,dwY,dwWidth,dwHeight);
			pnfyArray = &m_nfyRegWindowChange;
			break;
		}
		
		case WLN_QUERYVIEWER:
		{   
		    const char *pszURL = WLNGetURL(lParam);
			const char *pszMIME = WLNGetMIMEType(lParam); 
			char szFile[128];
			
			wsprintf(szMessage,"QUERYVIEWER: %s %s",pszURL,pszMIME);
			pnfyArray = &m_nfyRegViewer;
			
			wsprintf(szFile,"C:\\TEMP\\%lx.HTM",::GetTickCount());
			WLNSetFileName(lParam,szFile);			// return filename to browser
			break;
		}
		
		case WLN_VIEWDOCFILE:
		{
		    const char *pszURL = WLNGetURL(lParam);
			const char *pszMIME = WLNGetMIMEType(lParam);
			const char *pszFile = WLNGetFileName(lParam);
			DWORD dwWindow = WLNGetWindow(lParam);
			
			wsprintf(szMessage,"VIEWDOCFILE: %s %s %s %ld",pszURL,pszMIME,pszFile,dwWindow);
			pnfyArray = &m_nfyRegViewer;
			break;
		}
		
		case WLN_BUTTONCLICKED:
		{                                                                                    
			UINT nButtonID = WLNGetButtonID(lParam);
			
			wsprintf(szMessage,"BUTTONCLICKED: %u",nButtonID);
			pnfyArray = &m_nfyToolbar;
			break;
		}
		
		case WLN_BROWSERSTART:
		{   
			lstrcpy(szMessage,"BROWSERSTART");
			pnfyArray = NULL;						// recorded only to log
			break;
		}
		
		case WLN_BROWSEREXIT:
		{   
			lstrcpy(szMessage,"BROWSEREXIT");
			pnfyArray = NULL;						// recorded only to log
			break;
		}		
	}
	
	if (pnfyArray != NULL)
		pnfyArray->Add(CString(szMessage));
	
	if (m_bLogging)
	{
		ofstream outfile(m_strLogFile,ios::out | ios::app);
		
		if (outfile.is_open() && outfile.good())
		{                   
			outfile << "NFY --> " << szMessage << endl;
			outfile.close();
		}
	}
	return 0;
}

///////////////////////////////////////////////////////////////////////////// 
//  Message handler for HTML parsing notifications.

LONG CMainDlg::OnEnumParseTree(UINT wParam,LONG lParam)
{
	EnumHtmlElement(m_nfyEnumParseTree,"ENUMTREE",wParam,lParam);               
	return TRUE;						// return TRUE to continue enumeration
}

LONG CMainDlg::OnEnumFindText(UINT wParam,LONG lParam)
{   
	EnumHtmlElement(m_nfyEnumFindText,"ENUMTEXT",wParam,lParam);    
	return TRUE;
}

LONG CMainDlg::OnEnumFindSpecial(UINT wParam,LONG lParam)
{   
	EnumHtmlElement(m_nfyEnumFindSpecial,"ENUMSPEC",wParam,lParam);    
	return TRUE;
}

LONG CMainDlg::OnEnumFindComment(UINT wParam,LONG lParam)
{   
	EnumHtmlElement(m_nfyEnumFindComment,"ENUMCOMM",wParam,lParam);    
	return TRUE;
}

LONG CMainDlg::OnEnumFindTagType(UINT wParam,LONG lParam)
{   
	EnumHtmlElement(m_nfyEnumFindTagType,"ENUMTYPE",wParam,lParam);    
	return TRUE;
}

LONG CMainDlg::OnEnumFindTagName(UINT wParam,LONG lParam)
{   
	EnumHtmlElement(m_nfyEnumFindTagName,"ENUMTAG",wParam,lParam);    
	return TRUE;
}

LONG CMainDlg::OnEnumFindTagAttr(UINT wParam,LONG lParam)
{   
	EnumHtmlElement(m_nfyEnumFindTagAttr,"ENUMATTR",wParam,lParam);    
	return TRUE;
}

///////////////////////////////////////////////////////////////////////////// 
// Handler for message sent by DLL when dialog is destroyed, We enable our
// window so we become active window after DLL dialog dies.

LONG CMainDlg::OnApiDlgDestroy(UINT wParam,LONG lParam)
{
	EnableWindow(TRUE); 
	return 0;
}

///////////////////////////////////////////////////////////////////////////// 
// Methods to display API results in prompt line (also performs logging).

void CMainDlg::ApiReturnValue(const char *pszAPI,const char *pszParm1,const char *pszParm2)
{                                     
	CString strMsg = pszAPI;
	
	if (pszParm1 == NULL)
	{   
		CString strSuccess;
		strSuccess.LoadString(IDS_PROMPT_SUCCESS);
		
		strMsg += ": ";
		strMsg += strSuccess;
	}
	else
	{
		strMsg += ": [";
		strMsg += pszParm1;
		strMsg += "]";
		
		if (pszParm2 != NULL)     
		{
			strMsg += " [";
			strMsg += pszParm2;
			strMsg += "]";
		}
	}
	GetDlgItem(IDC_PROMPT)->SetWindowText(strMsg);
	
	if (m_bLogging)
	{
		ofstream outfile(m_strLogFile,ios::out | ios::app);
		
		if (outfile.is_open() && outfile.good())
		{                   
			outfile << "API --> " << strMsg << endl;
			outfile.close();
		}
	}
}

void CMainDlg::Error(UINT nMsgID,const char *pszParm)
{
	CString strMsg;
	strMsg.LoadString(nMsgID);
	
	if (pszParm != NULL)
		strMsg += pszParm;
	GetDlgItem(IDC_PROMPT)->SetWindowText(strMsg);
	
	if (m_bLogging)
	{
		ofstream outfile(m_strLogFile,ios::out | ios::app);
		
		if (outfile.is_open() && outfile.good())
		{                   
			outfile << "ERROR --> " << strMsg << endl;
			outfile.close();
		}
	}
}

///////////////////////////////////////////////////////////////////////////// 
// Method to format info about HTML element in string (and also to log file).

void CMainDlg::EnumHtmlElement(CStringArray &nfyArray,const char *pszEnum,
	UINT wParam,LONG lParam)
{               
	HELEMENT hElement = (HELEMENT) lParam;
	char szMessage[256];
	
	switch (wParam)
	{
		case WL_ROOT:   
			wsprintf(szMessage,"ROOT");
			break;
			
		case WL_TEXT:
			wsprintf(szMessage,"TEXT: %.240s %ld",
				WLHtmlGetElementText(m_hParse,hElement),
				WLHtmlGetTextAttr(m_hParse,hElement));
			break;
			
		case WL_TAG:
			wsprintf(szMessage,"TAG: %s %d",
				WLHtmlGetTagName(m_hParse,hElement),
				WLHtmlGetTagType(m_hParse,hElement));
			break;
			
		case WL_SPECIALCHAR:
			wsprintf(szMessage,"SPECIALCHAR: %s",
				WLHtmlGetElementText(m_hParse,hElement));
			break;
			
		case WL_COMMENT:
			wsprintf(szMessage,"COMMENT: %.240s",
				WLHtmlGetElementText(m_hParse,hElement));
			break;
			
		default:
			lstrcpy(szMessage,"???");
	}
	
	nfyArray.Add(CString(szMessage));
	
	if (m_bLogging)
	{
		ofstream outfile(m_strLogFile,ios::out | ios::app);
		
		if (outfile.is_open() && outfile.good())
		{                   
			outfile << pszEnum << " --> " << szMessage << endl;
			outfile.close();
		}
	}   	
}

///////////////////////////////////////////////////////////////////////////// 
// Fill info listbox with strings from string array.

void CMainDlg::FillInfoListbox(CStringArray &nfyArray)
{
	m_ListboxInfo.ResetContent();
	for (int nIdx=0;nIdx < nfyArray.GetSize();nIdx++)
		m_ListboxInfo.AddString(nfyArray.GetAt(nIdx));
}

///////////////////////////////////////////////////////////////////////////// 
// Find string in status string array and remove it.

void CMainDlg::RemoveFromStatusArray(CStringArray &staArray,CString &strItem)
{
	for (int nIdx=0;nIdx < staArray.GetSize();nIdx++)
		if (strItem == staArray[nIdx])
		{
			staArray.RemoveAt(nIdx);
			break;
		}
}

