{ ============================================================================
  Copyright 1995 by Potomac Software, Inc. Use of this material is subject to
  the terms and conditions of the software license agreement.
  ============================================================================ }

unit Maindlg;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Weblib, Htmlpars, Weblibapidlg, ApiDlgConstants;

type
  TMainDlgForm = class(TForm)
    API_GRPBOX: TGroupBox;
    BROWSER_RADIO: TRadioButton;
    TOOLBAR_RADIO: TRadioButton;
    HTML_RADIO: TRadioButton;
    UTIL_RADIO: TRadioButton;
    API_STATIC: TLabel;
    API_LIST: TListBox;
    OPENCLOSE_BTN: TButton;
    STATUS_BTN: TButton;
    INFO_BTN: TButton;
    EXIT_BTN: TButton;
    INFO_STATIC: TLabel;
    INFO_LIST: TListBox;
    PROMPT_STATIC: TLabel;

    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);

    procedure ShowBrowserAPI(Sender: TObject);
    procedure BrowserUI;
    procedure BrowserNotifications;
    procedure BrowserStatus;

    procedure ShowToolbarAPI(Sender: TObject);
    procedure ToolbarUI;
    procedure ToolbarStatus;
    procedure ToolbarNotifications;

    procedure ShowParserAPI(Sender: TObject);
    procedure ParserUI;
    procedure ParserNotifications;
    procedure ParserStatus;

    procedure ShowUtilAPI(Sender: TObject);
    procedure UtilityUI;
    procedure UtilityNotifications;
    procedure UtilityStatus;

    procedure ApiClick(Sender: TObject);
    procedure ApiDblClick(Sender: TObject);

    procedure OpenClose(Sender: TObject);
    procedure ExitDlg(Sender: TObject);
    procedure ShowNotifications(Sender: TObject);
    procedure ShowStatus(Sender: TObject);

    procedure ConnectBrowser;
    procedure DisconnectBrowser;
    procedure CreateToolbar;
    procedure DeleteToolbar;
    procedure ParseHtml;
    procedure EndParse;
    procedure AccessFormData;

    procedure BrowserCallout;
    procedure ToolbarCallout;
    procedure ParserCallout;
    procedure UtilityCallout;

    procedure GetWindowInfo;
	procedure ListWindows;
	procedure ActivateWindow;
	procedure CloseWindow;
	procedure SetWindowPos;
	procedure ShowWindow;
	procedure ShowFile;
	procedure OpenURL;
	procedure SaveURL;
	procedure PostFormData;
	procedure SaveFormData;
	procedure RegisterProtocol;
	procedure UnregisterProtocol;
	procedure RegisterURLEcho;
	procedure UnregisterURLEcho;
	procedure RegisterViewer;
	procedure UnregisterViewer;
    procedure RegisterWindowChange;
	procedure UnregisterWindowChange;
	procedure ParseAnchor;
	procedure GetVersion;
	procedure QueryURLFile;
	procedure SetNotifyMethod;

    procedure IsToolbarActive;
    procedure SetActiveToolbar;
    procedure AddToolbarButton;
    procedure RemoveToolbarButton;
    procedure IsToolbarButtonVisible;
    procedure ShowToolbarButton;
    procedure EnableToolbarButton;
    procedure IsToolbarButtonEnabled;
    procedure GetToolbarText;
    procedure SetToolbarText;
    procedure GetToolbarFont;
    procedure SetToolbarFont;
    procedure GetToolbarBkgnd;
    procedure SetToolbarBkgnd;
    procedure GetToolbarTextColor;
    procedure SetToolbarTextColor;

    procedure HtmlEnumParseTree;
    procedure HtmlGetChild;
    procedure HtmlGetParent;
    procedure HtmlGetSibling;
    procedure HtmlGetElementType;
    procedure HtmlGetElementText;
    procedure HtmlGetTextAttr;
    procedure HtmlGetTagName;
    procedure HtmlGetTagType;
    procedure HtmlGetTagAttr;
    procedure HtmlExtractTagAttr;
    procedure HtmlFindText;
    procedure HtmlFindSpecial;
    procedure HtmlFindComment;
    procedure HtmlFindTagType;
    procedure HtmlFindTagName;
    procedure HtmlFindTagAttr;
    procedure HtmlEnumFindText;
    procedure HtmlEnumFindSpecial;
    procedure HtmlEnumFindComment;
    procedure HtmlEnumFindTagType;
    procedure HtmlEnumFindTagName;
    procedure HtmlEnumFindTagAttr;

    procedure AppendFormData;
    procedure GetFormDataLength;
    procedure ParseAbsoluteURL;

    procedure ShowBoolResult(bResult: Bool; const szName: String);
    procedure ShowStrResult(const szParm: String; const szName: String);
    procedure ShowStrResult2(const szParm1: String; const szParm2: String;
    	const szName: String);

    procedure AddProgressString(const szMsg: String);
    function MakeEnumHtmlString(LParam: LongInt; WParam: Word) : String;

  private
  	{ notification string arrays }
  	nfyShowFile: TStrings;
	nfyOpenURL: TStrings;
	nfySaveURL: TStrings;
	nfyPostFormData: TStrings;
	nfySaveFormData: TStrings;
	nfyRegProtocol: TStrings;
	nfyRegURLEcho: TStrings;
	nfyRegViewer: TStrings;
	nfyRegWindowChange: TStrings;
	nfyToolbar: TStrings;
	nfyEnumParseTree: TStrings;
	nfyEnumFindText: TStrings;
	nfyEnumFindSpecial: TStrings;
	nfyEnumFindComment: TStrings;
	nfyEnumFindTagType: TStrings;
	nfyEnumFindTagName: TStrings;
	nfyEnumFindTagAttr: TStrings;

	staRegProtocol: TStrings;
	staRegViewer: TStrings;
	staRegWindowChange: TStrings; 	{ really holds DWORDs }
	staToolbar: TStrings;  			{ really holds UINTs }
    staRegURLEcho: Bool;

  public
	procedure HandleWeblibNotifyEvent (var msg: TMessage);
    	message WM_WEBLIB_NOTIFY;
    procedure HandleEnumParseTree (var msg: TMessage);
    	message WM_WEBLIB_ENUMPARSETREE;
 	procedure HandleEnumFindText (var msg: TMessage);
    	message WM_WEBLIB_ENUMFINDTEXT;
	 procedure HandleEnumFindSpecial (var msg: TMessage);
    	message WM_WEBLIB_ENUMFINDSPEC;
 	procedure HandleEnumFindComment (var msg: TMessage);
    	message WM_WEBLIB_ENUMFINDCOMM;
 	procedure HandleEnumFindTagType (var msg: TMessage);
    	message WM_WEBLIB_ENUMFINDTAGTYPE;
 	procedure HandleEnumFindTagName (var msg: TMessage);
    	message WM_WEBLIB_ENUMFINDTAGNAME;
 	procedure HandleEnumFindTagAttr (var msg: TMessage);
    	message WM_WEBLIB_ENUMFINDTAGATTR;
  end;

var
  MainDlgForm: TMainDlgForm;

implementation

var
	hBrowser: Weblib.HBROWSER;
    hToolbar: Weblib.HTOOLBAR;
    hParse: Htmlpars.HPARSE;
    hFormData: Weblib.HFORMDATA;

    hfontToolbar: HFont;
    hfontButton: HFont;

    hCurrElement: HELEMENT;
    hCurrTagAttr: HTAGATTR;

{$R *.DFM}

procedure TMainDlgForm.FormCreate(Sender: TObject);
begin
	{ initialize members }
	hBrowser := 0;
    hToolbar := 0;
    hParse := 0;
    hFormData := 0;

    hfontToolbar := 0;
    hfontButton := 0;

    hCurrElement := 0;
    hCurrTagAttr := 0;

    { create notification string lists for holding events }
    nfyShowFile := TStringList.Create;
	nfyOpenURL := TStringList.Create;
	nfySaveURL := TStringList.Create;
	nfyPostFormData := TStringList.Create;
	nfySaveFormData := TStringList.Create;
	nfyRegProtocol := TStringList.Create;
	nfyRegURLEcho := TStringList.Create;
	nfyRegViewer := TStringList.Create;
	nfyRegWindowChange := TStringList.Create;
	nfyToolbar := TStringList.Create;
	nfyEnumParseTree := TStringList.Create;
	nfyEnumFindText := TStringList.Create;
	nfyEnumFindSpecial := TStringList.Create;
	nfyEnumFindComment := TStringList.Create;
	nfyEnumFindTagType := TStringList.Create;
	nfyEnumFindTagName := TStringList.Create;
	nfyEnumFindTagAttr := TStringList.Create;

    { create status string lists }
	staRegProtocol := TStringList.Create;
	staRegViewer := TStringList.Create;
	staRegWindowChange := TStringList.Create;
	staToolbar := TStringList.Create;

    staRegURLEcho := False;

    { use canned sub-classing to handle enable of main window after API dlg }
    if not ApiDlgSubclass4GL(Handle, 5000) then
        Application.MessageBox('ApiDlgSubclass4GL failed','Error',MB_OK);
    if not ApiDlgNotifyOnWindowDestroy(Handle, 5000) then
    	Application.MessageBox('ApiDlgNotifyOnWindowDestroy failed','Error',MB_OK);

	SendMessage(INFO_LIST.Handle,LB_SETHORIZONTALEXTENT,INFO_LIST.Width * 3,0);
    ShowBrowserAPI(BROWSER_RADIO);
end;

procedure TMainDlgForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  	if not ApiDlgUnsubclass4GL(Handle) then
    	Application.MessageBox('ApiDlgUnsubclass4GL failed','Error',MB_OK);

    if hBrowser <> 0 then
    	WLDisconnectBrowser(hBrowser,True);
    if hToolbar <> 0 then
    	WLDeleteToolbar(hToolbar);
    if hParse <> 0 then
    	WLHtmlEndParse(hParse);

	if hfontToolbar <> 0 then
		ApiDlgFreeFont4GL(hfontToolbar);
    if hfontButton <> 0 then
		ApiDlgFreeFont4GL(hfontButton);

    nfyShowFile.Free;
	nfyOpenURL.Free;
	nfySaveURL.Free;
	nfyPostFormData.Free;
	nfySaveFormData.Free;
	nfyRegProtocol.Free;
	nfyRegURLEcho.Free;
	nfyRegViewer.Free;
	nfyRegWindowChange.Free;
	nfyToolbar.Free;
	nfyEnumParseTree.Free;
	nfyEnumFindText.Free;
	nfyEnumFindSpecial.Free;
	nfyEnumFindComment.Free;
	nfyEnumFindTagType.Free;
	nfyEnumFindTagName.Free;
	nfyEnumFindTagAttr.Free;

	staRegProtocol.Free;
	staRegViewer.Free;
	staRegWindowChange.Free;
	staToolbar.Free;
end;

procedure TMainDlgForm.ShowBrowserAPI(Sender: TObject);
begin
	API_LIST.Items.Clear;
    API_STATIC.Caption := 'Browser APIs';

	if hBrowser = 0 then
    begin
    	OPENCLOSE_BTN.Caption := '&Connect...';
    end
    else
    begin
    	OPENCLOSE_BTN.Caption := '&Disconnect';

    	API_LIST.Items.Add('GetWindowInfo');
        API_LIST.Items.Add('ListWindows');
        API_LIST.Items.Add('ActivateWindow');
        API_LIST.Items.Add('CloseWindow');
        API_LIST.Items.Add('SetWindowPos');
        API_LIST.Items.Add('ShowWindow');
        API_LIST.Items.Add('ShowFile');
        API_LIST.Items.Add('OpenURL');
        API_LIST.Items.Add('SaveURL');
        API_LIST.Items.Add('PostFormData');
        API_LIST.Items.Add('SaveFormData');
        API_LIST.Items.Add('RegisterProtocol');
        API_LIST.Items.Add('UnregisterProtocol');
        API_LIST.Items.Add('RegisterURLEcho');
        API_LIST.Items.Add('UnregisterURLEcho');
        API_LIST.Items.Add('RegisterViewer');
        API_LIST.Items.Add('UnregisterViewer');
        API_LIST.Items.Add('RegisterWindowChange');
        API_LIST.Items.Add('UnregisterWindowChange');
        API_LIST.Items.Add('ParseAnchor');
        API_LIST.Items.Add('GetVersion');
        API_LIST.Items.Add('QueryURLFile');
        API_LIST.Items.Add('SetNotifyMethod');

        API_LIST.ItemIndex := 0;
    end;

	OPENCLOSE_BTN.Enabled := True;
end;

procedure TMainDlgForm.ShowToolbarAPI(Sender: TObject);
begin
	API_LIST.Items.Clear;
    API_STATIC.Caption := 'Toolbar APIs';

	if hToolbar = 0 then
    begin
    	OPENCLOSE_BTN.Caption := '&Create...';
    end
    else
    begin
    	OPENCLOSE_BTN.Caption := '&Delete';

    	API_LIST.Items.Add('IsToolbarActive');
		API_LIST.Items.Add('SetActiveToolbar');
		API_LIST.Items.Add('AddToolbarButton');
		API_LIST.Items.Add('RemoveToolbarButton');
		API_LIST.Items.Add('IsToolbarButtonVisible');
		API_LIST.Items.Add('ShowToolbarButton');
		API_LIST.Items.Add('EnableToolbarButton');
		API_LIST.Items.Add('IsToolbarButtonEnabled');
		API_LIST.Items.Add('GetToolbarText');
		API_LIST.Items.Add('SetToolbarText');
		API_LIST.Items.Add('GetToolbarFont');
		API_LIST.Items.Add('SetToolbarFont');
		API_LIST.Items.Add('GetToolbarBkgnd');
		API_LIST.Items.Add('SetToolbarBkgnd');
		API_LIST.Items.Add('GetToolbarTextColor');
		API_LIST.Items.Add('SetToolbarTextColor');

        API_LIST.ItemIndex := 0;
    end;

	OPENCLOSE_BTN.Enabled := True;
end;

procedure TMainDlgForm.ShowParserAPI(Sender: TObject);
begin
	API_LIST.Items.Clear;
    API_STATIC.Caption := 'Html APIs';

	if hParse = 0 then
    begin
    	OPENCLOSE_BTN.Caption := '&Parse...';
    end
    else
    begin
    	OPENCLOSE_BTN.Caption := '&End Parse';

    	API_LIST.Items.Add('EnumParseTree');
		API_LIST.Items.Add('GetChild');
		API_LIST.Items.Add('GetParent');
		API_LIST.Items.Add('GetSibling');
		API_LIST.Items.Add('GetElementType');
		API_LIST.Items.Add('GetElementText');
		API_LIST.Items.Add('GetTextAttr');
		API_LIST.Items.Add('GetTagName');
		API_LIST.Items.Add('GetTagType');
		API_LIST.Items.Add('GetTagAttr');
		API_LIST.Items.Add('ExtractTagAttr');
		API_LIST.Items.Add('FindText');
		API_LIST.Items.Add('FindSpecial');
		API_LIST.Items.Add('FindComment');
		API_LIST.Items.Add('FindTagType');
		API_LIST.Items.Add('FindTagName');
		API_LIST.Items.Add('FindTagAttr');
		API_LIST.Items.Add('EnumFindText');
		API_LIST.Items.Add('EnumFindSpecial');
		API_LIST.Items.Add('EnumFindComment');
		API_LIST.Items.Add('EnumFindTagType');
		API_LIST.Items.Add('EnumFindTagName');
		API_LIST.Items.Add('EnumFindTagAttr');

        API_LIST.ItemIndex := 0;
    end;

	OPENCLOSE_BTN.Enabled := True;
end;

procedure TMainDlgForm.ShowUtilAPI(Sender: TObject);
begin
	API_LIST.Items.Clear;
    API_STATIC.Caption := 'Utility APIs';
    OPENCLOSE_BTN.Caption := '&Access Data...';

    API_LIST.Items.Add('AppendFormData');
	API_LIST.Items.Add('GetFormDataLength');
	API_LIST.Items.Add('ParseAbsoluteURL');

    API_LIST.ItemIndex := 0;

	if hFormData = 0 then
    	OPENCLOSE_BTN.Enabled := False
    else
    	OPENCLOSE_BTN.Enabled := True;
end;

procedure TMainDlgForm.ApiDblClick(Sender: TObject);
begin
	if BROWSER_RADIO.Checked then
    	BrowserCallout
    else
    	if TOOLBAR_RADIO.Checked then
        	ToolbarCallout
        else
        	if HTML_RADIO.Checked then
             	ParserCallout
             else
             	if UTIL_RADIO.Checked then
                  	UtilityCallout;
end;

procedure TMainDlgForm.ApiClick(Sender: TObject);
begin
	INFO_LIST.Items.Clear;

	if BROWSER_RADIO.Checked then
    	BrowserUI
    else
    	if TOOLBAR_RADIO.Checked then
        	ToolbarUI
        else
        	if HTML_RADIO.Checked then
             	ParserUI
             else
             	if UTIL_RADIO.Checked then
                  	UtilityUI;
end;

procedure TMainDlgForm.OpenClose(Sender: TObject);
begin
	if BROWSER_RADIO.Checked then
    	if hBrowser = 0 then
        	ConnectBrowser
        else
        	DisconnectBrowser
    else
    	if TOOLBAR_RADIO.Checked then
        	if hToolbar = 0 then
             	CreateToolbar
             else
             	DeleteToolbar
        else
        	if HTML_RADIO.Checked then
             	if hParse = 0 then
                  	ParseHtml
                  else
                  	EndParse
             else
             	if UTIL_RADIO.Checked then
                  	AccessFormData;
end;

procedure TMainDlgForm.ExitDlg(Sender: TObject);
begin
	Close;
end;

procedure TMainDlgForm.ShowNotifications(Sender: TObject);
begin
	if BROWSER_RADIO.Checked then
    	BrowserNotifications
    else
    	if TOOLBAR_RADIO.Checked then
        	ToolbarNotifications
        else
        	if HTML_RADIO.Checked then
             	ParserNotifications
             else
             	if UTIL_RADIO.Checked then
                  	UtilityNotifications;
end;

procedure TMainDlgForm.ShowStatus(Sender: TObject);
begin
	if BROWSER_RADIO.Checked then
    	BrowserStatus
    else
    	if TOOLBAR_RADIO.Checked then
        	ToolbarStatus
        else
        	if HTML_RADIO.Checked then
             	ParserStatus
             else
             	if UTIL_RADIO.Checked then
                  	UtilityStatus;
end;

procedure TMainDlgForm.ConnectBrowser;
var
	bStart: Bool;
    bSend: Bool;
    bPost: Bool;
    WOptions: Word;
begin
	bStart := True;
    bSend := False;
    bPost := True;

    if ApiDlgConnectBrowser(bStart,bSend,bPost) then
    begin
    	wOptions := 0;
    	if bStart then
        	wOptions := wOptions or WL_STARTBROWSER;
		if bSend then
        	wOptions := wOptions or WL_SENDMESSAGE;
		if bPost then
        	wOptions := wOptions or WL_POSTMESSAGE;

    	hBrowser := WLConnectBrowser(wOptions);
        if hBrowser = 0 then
        	ShowBoolResult(False,'WLConnectBrowser')
        else
        begin
        	ShowBoolResult(True,'WLConnectBrowser');
	    	ShowBrowserAPI(BROWSER_RADIO);
        end;
    end;
end;

procedure TMainDlgForm.DisconnectBrowser;
var
	bExit: Bool;
begin
	bExit := True;

	if ApiDlgDisconnectBrowser(bExit) then
    begin
    	if WLDisconnectBrowser(hBrowser,bExit) then
        begin
    		hBrowser := 0;
             ShowBoolResult(True,'WLDisconnectBrowser');
             ShowBrowserAPI(BROWSER_RADIO);

             nfyShowFile.Clear;
            	nfyOpenURL.Clear;
            	nfySaveURL.Clear;
            	nfyPostFormData.Clear;
            	nfySaveFormData.Clear;
            	nfyRegProtocol.Clear;
            	nfyRegURLEcho.Clear;
            	nfyRegViewer.Clear;
            	nfyRegWindowChange.Clear;
            	nfyToolbar.Clear;

            	staRegProtocol.Clear;
            	staRegViewer.Clear;
            	staRegWindowChange.Clear;
             staRegURLEcho := False;

        end
        else
        	ShowBoolResult(False,'WLDisconnectBrowser');
    end;
end;

procedure TMainDlgForm.CreateToolbar;
var
	szMenu: array[0..63] of Char;
begin
	szMenu[0] := Chr(0);

	if ApiDlgCreateToolbar(szMenu,SizeOf(szMenu)) then
    begin
    	hToolbar := WLCreateToolbar(szMenu,Handle,WM_WEBLIB_NOTIFY);
        if hToolbar = 0 then
        	ShowBoolResult(False,'WLCreateToolbar')
        else
        begin
        	ShowBoolResult(True,'WLCreateToolbar');
             ShowToolbarAPI(TOOLBAR_RADIO);
        end;
    end;
end;

procedure TMainDlgForm.DeleteToolbar;
begin
	if WLDeleteToolbar(hToolbar) then
     	ShowBoolResult(False,'WLDeleteToolbar')
    else
    	ShowBoolResult(True,'WLDeleteToolbar');

    hToolbar := 0;
    ShowToolbarAPI(TOOLBAR_RADIO);

    nfyToolbar.Clear;
    staToolbar.Clear;
end;

procedure TMainDlgForm.ParseHtml;
var
	szFile: array[0..255] of Char;
	szBuf: array[0..1023] of Char;
	bAttr: Bool;
	bClosing: Bool;
    wOptions: Word;
begin
	szFile[0] := Chr(0);
    szBuf[0] := Chr(0);
    bAttr := False;
    bClosing := False;

	if ApiDlgHtmlParse(szFile,SizeOf(szFile),szBuf,SizeOf(szBuf),bAttr,bClosing) then
    begin
		hCurrElement := WL_ROOTELEMENT;
        hCurrTagAttr := 0;

    	wOptions := 0;
        if bAttr then
        	wOptions := wOptions or WL_KEEPATTRIBUTETAG;
        if bClosing then
        	wOptions := wOptions or WL_KEEPCLOSINGTAG;

    	if StrLen(szFile) > 0 then
        	hParse := WLHtmlParseFile(szFile,wOptions)
        else
        	hParse := WLHtmlParseBuf(szBuf,StrLen(szBuf),wOptions);

        if hParse = 0 then
        	ShowBoolResult(False,'WLHtmlParseFile/Buf')
        else
        begin
        	ShowBoolResult(True,'WLHtmlParseFile/Buf');
             ShowParserAPI(HTML_RADIO);
        end;
    end
end;

procedure TMainDlgForm.EndParse;
begin
	if WLHtmlEndParse(hParse) then
    	ShowBoolResult(True,'WLHtmlEndParse')
    else
    	ShowBoolResult(False,'WLHtmlEndParse');

	hParse := 0;
    ShowParserAPI(HTML_RADIO);

    nfyEnumParseTree.Clear;
	nfyEnumFindText.Clear;
	nfyEnumFindSpecial.Clear;
	nfyEnumFindComment.Clear;
	nfyEnumFindTagType.Clear;
	nfyEnumFindTagName.Clear;
	nfyEnumFindTagAttr.Clear;
end;

procedure TMainDlgForm.AccessFormData;
var
	szRetBuf: array[0..1023] Of Char;
begin
	szRetBuf[0] := Chr(0);

    if WLGetFormDataLength(hFormData) <= SizeOf(szRetBuf) then
    	if WLAccessFormData(hFormData,szRetBuf,SizeOf(szRetBuf)) then
        begin
        	hFormData := 0;
             ApiDlgAccessFormData(szRetBuf);
             ShowBoolResult(True,'WLAccessFormData');
             OPENCLOSE_BTN.Enabled := False;
        end
        else
        	ShowBoolResult(False,'WLAccessFormData');
end;

procedure TMainDlgForm.BrowserCallout;
begin
	case API_LIST.ItemIndex of
    WLAPI_GetWindowInfo:
        GetWindowInfo;
    WLAPI_ListWindows:
        ListWindows;
    WLAPI_ActivateWindow:
        ActivateWindow;
    WLAPI_CloseWindow:
        CloseWindow;
    WLAPI_SetWindowPos:
        SetWindowPos;
    WLAPI_ShowWindow:
        ShowWindow;
    WLAPI_ShowFile:
        ShowFile;
    WLAPI_OpenURL:
        OpenURL;
    WLAPI_SaveURL:
        SaveURL;
    WLAPI_PostFormData:
        PostFormData;
    WLAPI_SaveFormData:
        SaveFormData;
    WLAPI_RegisterProtocol:
        RegisterProtocol;
    WLAPI_UnregisterProtocol:
        UnregisterProtocol;
    WLAPI_RegisterURLEcho:
        RegisterURLEcho;
    WLAPI_UnregisterURLEcho:
        UnregisterURLEcho;
    WLAPI_RegisterViewer:
        RegisterViewer;
    WLAPI_UnregisterViewer:
        UnregisterViewer;
    WLAPI_RegisterWindowChange:
        RegisterWindowChange;
    WLAPI_UnregisterWindowChange:
        UnregisterWindowChange;
    WLAPI_ParseAnchor:
        ParseAnchor;
    WLAPI_GetVersion:
        GetVersion;
    WLAPI_QueryURLFile:
        QueryURLFile;
    WLAPI_SetNotifyMethod:
        SetNotifyMethod;
    else
    	;
    end;
end;

procedure TMainDlgForm.ToolbarCallout;
begin
	case API_LIST.ItemIndex of
    WLAPI_IsToolbarActive:
        IsToolbarActive;
    WLAPI_SetActiveToolbar:
        SetActiveToolbar;
    WLAPI_AddToolbarButton:
        AddToolbarButton;
    WLAPI_RemoveToolbarButton:
        RemoveToolbarButton;
    WLAPI_IsToolbarButtonVisible:
        IsToolbarButtonVisible;
    WLAPI_ShowToolbarButton:
        ShowToolbarButton;
    WLAPI_EnableToolbarButton:
        EnableToolbarButton;
    WLAPI_IsToolbarButtonEnabled:
        IsToolbarButtonEnabled;
    WLAPI_GetToolbarText:
        GetToolbarText;
    WLAPI_SetToolbarText:
        SetToolbarText;
    WLAPI_GetToolbarFont:
        GetToolbarFont;
    WLAPI_SetToolbarFont:
        SetToolbarFont;
    WLAPI_GetToolbarBkgnd:
        GetToolbarBkgnd;
    WLAPI_SetToolbarBkgnd:
        SetToolbarBkgnd;
    WLAPI_GetToolbarTextColor:
        GetToolbarTextColor;
    WLAPI_SetToolbarTextColor:
        SetToolbarTextColor;
    else
    	;
    end;
end;

procedure TMainDlgForm.ParserCallout;
begin
	case API_LIST.ItemIndex of
    WLAPI_HtmlEnumParseTree:
        HtmlEnumParseTree;
    WLAPI_HtmlGetChild:
        HtmlGetChild;
    WLAPI_HtmlGetParent:
        HtmlGetParent;
    WLAPI_HtmlGetSibling:
        HtmlGetSibling;
    WLAPI_HtmlGetElementType:
        HtmlGetElementType;
    WLAPI_HtmlGetElementText:
        HtmlGetElementText;
    WLAPI_HtmlGetTextAttr:
        HtmlGetTextAttr;
    WLAPI_HtmlGetTagName:
        HtmlGetTagName;
    WLAPI_HtmlGetTagType:
        HtmlGetTagType;
    WLAPI_HtmlGetTagAttr:
        HtmlGetTagAttr;
    WLAPI_HtmlExtractTagAttr:
        HtmlExtractTagAttr;
    WLAPI_HtmlFindText:
        HtmlFindText;
    WLAPI_HtmlFindSpecial:
        HtmlFindSpecial;
    WLAPI_HtmlFindComment:
        HtmlFindComment;
    WLAPI_HtmlFindTagType:
        HtmlFindTagType;
    WLAPI_HtmlFindTagName:
        HtmlFindTagName;
    WLAPI_HtmlFindTagAttr:
        HtmlFindTagAttr;
    WLAPI_HtmlEnumFindText:
        HtmlEnumFindText;
    WLAPI_HtmlEnumFindSpecial:
        HtmlEnumFindSpecial;
    WLAPI_HtmlEnumFindComment:
        HtmlEnumFindComment;
    WLAPI_HtmlEnumFindTagType:
        HtmlEnumFindTagType;
    WLAPI_HtmlEnumFindTagName:
        HtmlEnumFindTagName;
    WLAPI_HtmlEnumFindTagAttr:
        HtmlEnumFindTagAttr;
    else
    	;
    end;
end;

procedure TMainDlgForm.UtilityCallout;
begin
	case API_LIST.ItemIndex of
    WLAPI_AppendFormData:
        AppendFormData;
    WLAPI_GetFormDataLength:
        GetFormDataLength;
    WLAPI_ParseAbsoluteURL:
        ParseAbsoluteURL;
    else
    	;
    end;
end;

procedure TMainDlgForm.GetWindowInfo;
var
	dwWindow: LongInt;
    szURL: array[0..255] of Char;
    szTitle: array[0..255] of Char;
begin
	dwWindow := 0;
    szURL[0] := Chr(0);
    szTitle[0] := Chr(0);

	if ApiDlgGetWindowInfo(dwWindow) then
    	if WLGetWindowInfo(hBrowser,dwWindow,szURL,SizeOf(szURL),szTitle,
        	SizeOf(szTitle)) then
        	ShowStrResult2(StrPas(szURL),StrPas(szTitle),'WLGetWindowInfo')
        else
        	ShowBoolResult(False,'WLGetWindowInfo');
end;

procedure TMainDlgForm.ListWindows;
var
	bFirst: Bool;
    dwWindow: LongInt;
begin
	bFirst := False;
    dwWindow := 0;

	if ApiDlgListWindows(bFirst) then
    begin
    	dwWindow := WLListWindows(hBrowser,bFirst);
        if dwWindow = 0 then
        	ShowBoolResult(False,'WLListWindows')
        else
        	ShowStrResult(IntToStr(dwWindow),'WLListWindows')
	end;
end;

procedure TMainDlgForm.ActivateWindow;
var
	dwWindow: LongInt;
begin
	dwWindow := 0;

	if ApiDlgActivateWindow(dwWindow) then
    begin
		dwWindow := WLActivateWindow(hBrowser,dwWindow);
        if dwWindow = 0 then
        	ShowBoolResult(False,'WLActivateWindow')
        else
        	ShowStrResult(IntToStr(dwWindow),'WLActivateWindow');
    end
end;

procedure TMainDlgForm.CloseWindow;
var
	dwWindow: LongInt;
begin
	dwWindow := 0;

	if ApiDlgCloseWindow(dwWindow) then
		if WLCloseWindow(hBrowser,dwWindow) then
			ShowBoolResult(True,'WLCloseWindow')
        else
        	ShowBoolResult(False,'WLCloseWindow');
end;

procedure TMainDlgForm.SetWindowPos;
var
	dwWindow: LongInt;
	dwX: LongInt;
	dwY: LongInt;
	dwWidth: LongInt;
	dwHeight: LongInt;
begin
	dwWindow := 0;
	dwX := 0;
	dwY := 0;
	dwWidth := 0;
	dwHeight := 0;

	if ApiDlgSetWindowPos(dwWindow,dwX,dwY,dwWidth,dwHeight) then
		if WLSetWindowPos(hBrowser,dwWindow,dwX,dwY,dwWidth,dwHeight) then
        	ShowBoolResult(True,'WLSetWindowPos')
        else
        	ShowBoolResult(False,'WLSetWindowPos');
end;

procedure TMainDlgForm.ShowWindow;
var
	dwWindow: LongInt;
	nShow : Word;
begin
	dwWindow := 0;
    nShow := WL_NORMAL;

	if ApiDlgShowWindow(dwWindow,nShow) then
		if WLShowWindow(hBrowser,dwWindow,nShow) then
			ShowBoolResult(True,'WLShowWindow')
        else
        	ShowBoolResult(False,'WLShowWindow');
end;

procedure TMainDlgForm.ShowFile;
var
	szFile: array[0..255] of Char;
	szMIME: array[0..63] of Char;
	bNotify: Bool;
	szURL: array[0..255] of Char;
	dwWindow: LongInt;
    dwTrx: LongInt;
    hwndNotify: HWnd;
begin
	szFile[0] := Chr(0);
    szMIME[0] := Chr(0);
    szURL[0] := Chr(0);
    bNotify := True;
    dwWindow := 0;
    dwTrx := 0;
    hwndNotify := WL_NONOTIFY;

	if ApiDlgShowFile(szFile,SizeOf(szFile),szMIME,SizeOf(szMIME),bNotify,szURL,
    	SizeOf(szURL),dwWindow) then
    begin
    	if (bNotify) then
        	hwndNotify := Handle;
    	dwTrx := WLShowFile(hBrowser,szFile,szMIME,dwWindow,szURL,hwndNotify,
        	WM_WEBLIB_NOTIFY);
        if dwTrx = 0 then
        	ShowBoolResult(False,'WLShowFile')
        else
        	ShowStrResult(IntToStr(dwTrx),'WLShowFile');
    end;
end;

procedure TMainDlgForm.OpenURL;
var
	szURL: array[0..255] of Char;
	bNotify: Bool;
    bBackground: Bool;
	bNoDocCache: Bool;
	bNoImageCache: Bool;
	dwWindow: LongInt;
    wOptions: Word;
    dwTrx: LongInt;
    hwndNotify: HWnd;
begin
    szURL[0] := Chr(0);
    bNotify := True;
    dwWindow := 0;
    bBackground := False;
	bNoDocCache := False;
	bNoImageCache := False;
    dwTrx := 0;
    hwndNotify := WL_NONOTIFY;

    wOptions := 0;
    if bBackground then
    	wOptions := wOptions or WL_BACKGROUNDMODE;
	if bNoDocCache then
    	wOptions := wOptions or WL_NODOCUMENTCACHE;
    if bNoImageCache then
    	wOptions := wOptions or WL_NOIMAGECACHE;

    if ApiDlgOpenURL(bBackground,bNoDocCache,bNoImageCache,bNotify,szURL,SizeOf(szURL),
    	dwWindow) then
    begin
    	if (bNotify) then
        	hwndNotify := Handle;
        dwTrx := WLOpenURL(hBrowser,szURL,dwWindow,wOptions,hwndNotify,
        	WM_WEBLIB_NOTIFY);
    	if dwTrx = 0 then
        	ShowBoolResult(False,'WLOpenURL')
        else
        	ShowStrResult(IntToStr(dwTrx),'WLOpenURL');
    end;
end;

procedure TMainDlgForm.SaveURL;
var
	szFile: array[0..255] of Char;
	szURL: array[0..255] of Char;
	bNotify: Bool;
    bBackground: Bool;
	bNoDocCache: Bool;
	bNoImageCache: Bool;
	dwWindow: LongInt;
    wOptions: Word;
    dwTrx: LongInt;
    hwndNotify: HWnd;
begin
	szURL[0] := Chr(0);
    szFile[0] := Chr(0);
    bNotify := True;
    dwWindow := 0;
    bBackground := False;
	bNoDocCache := False;
	bNoImageCache := False;
    dwTrx := 0;
    hwndNotify := WL_NONOTIFY;

    wOptions := 0;
    if bBackground then
    	wOptions := wOptions or WL_BACKGROUNDMODE;
	if bNoDocCache then
    	wOptions := wOptions or WL_NODOCUMENTCACHE;
    if bNoImageCache then
    	wOptions := wOptions or WL_NOIMAGECACHE;

    if ApiDlgSaveURL(bBackground,bNoDocCache,bNoImageCache,bNotify,szURL,SizeOf(szURL),
    	szFile,SizeOf(szFile),dwWindow) then
    begin
    	if (bNotify) then
        	hwndNotify := Handle;
        dwTrx := WLSaveURL(hBrowser,szURL,szFile,dwWindow,wOptions,hwndNotify,
        	WM_WEBLIB_NOTIFY);
    	if dwTrx = 0 then
        	ShowBoolResult(False,'WLSaveURL')
        else
        	ShowStrResult(IntToStr(dwTrx),'WLSaveURL');
    end;
end;

procedure TMainDlgForm.PostFormData;
var
	szFormData: array[0..1023] of Char;
	szMIME: array[0..63] of Char;
	szURL: array[0..255] of Char;
    bNotify: Bool;
	dwWindow: LongInt;
    dwTrx: LongInt;
    hwndNotify: HWnd;
begin
	szFormData[0] := Chr(0);
	szMIME[0] := Chr(0);
    szURL[0] := Chr(0);
	bNotify := True;
	dwWindow := 0;
    dwTrx := 0;
    hwndNotify := WL_NONOTIFY;

	if ApiDlgPostFormData(szFormData,SizeOf(szFormData),szMIME,SizeOf(szMIME),
		bNotify,szURL,SizeOf(szURL),dwWindow) then
    begin
    	if (bNotify) then
        	hwndNotify := Handle;
    	dwTrx := WLPostFormData(hBrowser,szURL,dwWindow,szFormData,szMIME,
        	hwndNotify,WM_WEBLIB_NOTIFY);
		if dwTrx = 0 then
        	ShowBoolResult(False,'WLPostFormData')
        else
        	ShowStrResult(IntToStr(dwTrx),'WLPostFormData');
    end;
end;

procedure TMainDlgForm.SaveFormData;
var
	szFormData: array[0..1023] of Char;
	szMIME: array[0..63] of Char;
	szURL: array[0..255] of Char;
    szFile: array[0..255] of Char;
    bNotify: Bool;
	dwWindow: LongInt;
    dwTrx: LongInt;
    hwndNotify: HWnd;
begin
	szFormData[0] := Chr(0);
	szMIME[0] := Chr(0);
    szURL[0] := Chr(0);
    szFile[0] := Chr(0);
	bNotify := True;
	dwWindow := 0;
    dwTrx := 0;
    hwndNotify := WL_NONOTIFY;

	if ApiDlgSaveFormData(szFile,SizeOf(szFile),szFormData,SizeOf(szFormData),
    	szMIME,SizeOf(szMIME),bNotify,szURL,SizeOf(szURL),dwWindow) then
    begin
    	if (bNotify) then
        	hwndNotify := Handle;
    	dwTrx := WLSaveFormData(hBrowser,szURL,szFile,dwWindow,szFormData,szMIME,
        	hwndNotify,WM_WEBLIB_NOTIFY);
		if dwTrx = 0 then
        	ShowBoolResult(False,'WLSaveFormData')
        else
        	ShowStrResult(IntToStr(dwTrx),'WLSaveFormData');
    end;
end;

procedure TMainDlgForm.RegisterProtocol;
var
	szProtocol: array[0..64] of Char;
begin
	szProtocol[0] := Chr(0);

	if ApiDlgRegisterProtocol(szProtocol,SizeOf(szProtocol)) then
    	if WLRegisterProtocol(hBrowser,szProtocol,Handle,WM_WEBLIB_NOTIFY) then
        begin
        	staRegProtocol.Add(StrPas(szProtocol));
        	ShowBoolResult(True,'WLRegisterProtocol')
        end
        else
        	ShowBoolResult(False,'WLRegisterProtocol');
end;

procedure TMainDlgForm.UnregisterProtocol;
var
	szProtocol: array[0..64] of Char;
    nIdx: Integer;
begin
	szProtocol[0] := Chr(0);

	if ApiDlgUnregisterProtocol(szProtocol,SizeOf(szProtocol)) then
    	if WLUnregisterProtocol(hBrowser,szProtocol,Handle) then
        begin
        	nIdx := staRegProtocol.IndexOf(StrPas(szProtocol));
             if nIdx >= 0 then
	        		staRegProtocol.Delete(nIdx);
        	ShowBoolResult(True,'WLUnregisterProtocol');
        end
        else
        	ShowBoolResult(False,'WLUnregisterProtocol');
end;

procedure TMainDlgForm.RegisterURLEcho;
begin
	if WLRegisterURLEcho(hBrowser,Handle,WM_WEBLIB_NOTIFY) then
    begin
    	staRegURLEcho := True;
    	ShowBoolResult(True,'WLRegisterURLEcho');
    end
    else
    	ShowBoolResult(False,'WLRegisterURLEcho');
end;

procedure TMainDlgForm.UnregisterURLEcho;
begin
	if WLUnregisterURLEcho(hBrowser,Handle) then
    begin
    	staRegURLEcho := False;
    	ShowBoolResult(True,'WLUnregisterURLEcho');
    end
    else
    	ShowBoolResult(False,'WLUnregisterURLEcho');
end;

procedure TMainDlgForm.RegisterViewer;
var
	szMIME: array[0..63] of Char;
	bQueryViewer: Bool;
	bShellExec: Bool;
	bViewDocFile: Bool;
    wOptions: Word;
begin
	szMIME[0] := Chr(0);
	bQueryViewer := False;
	bShellExec := False;
	bViewDocFile := True;

	if ApiDlgRegisterViewer(szMIME,SizeOf(szMIME),bQueryViewer,bShellExec,
		bViewDocFile) then
    begin
        wOptions := 0;
        if bQueryViewer then
            wOptions := wOptions or WL_QUERYVIEWER;
        if bShellExec then
            wOptions := wOptions or WL_SHELLEXECUTE;
        if bViewDocFile then
            wOptions := wOptions or WL_VIEWDOCFILE;

    	if WLRegisterViewer(hBrowser,szMIME,wOptions,Handle,WM_WEBLIB_NOTIFY) then
        begin
        	staRegViewer.Add(StrPas(szMIME));
			ShowBoolResult(True,'WLRegisterViewer')
        end
    	else
    		ShowBoolResult(False,'WLRegisterViewer');
    end;
end;

procedure TMainDlgForm.UnregisterViewer;
var
	szMIME: array[0..63] of Char;
    nIdx: Integer;
begin
	szMIME[0] := Chr(0);

	if ApiDlgUnregisterViewer(szMIME,SizeOf(szMIME)) then
    	if WLUnregisterViewer(hBrowser,szMIME,Handle) then
        begin
        	nIdx := staRegViewer.IndexOf(StrPas(szMIME));
             if nIdx >= 0 then
	        		staRegViewer.Delete(nIdx);
    		ShowBoolResult(True,'WLUnregisterViewer');
        end
    	else
    		ShowBoolResult(False,'WLUnregisterViewer');
end;

procedure TMainDlgForm.RegisterWindowChange;
var
	dwWindow: LongInt;
begin
	dwWindow := 0;

	if ApiDlgRegisterWindowChange(dwWindow) then
    	if WLRegisterWindowChange(hBrowser,dwWindow,Handle,WM_WEBLIB_NOTIFY) then
        begin
        	staRegWindowChange.Add(IntToStr(dwWindow));
        	ShowBoolResult(True,'WLRegisterWindowChange');
        end
        else
    		ShowBoolResult(False,'WLRegisterWindowChange');
end;

procedure TMainDlgForm.UnregisterWindowChange;
var
	dwWindow: LongInt;
    nIdx: Integer;
begin
	dwWindow := 0;

	if ApiDlgUnregisterWindowChange(dwWindow) then
    	if WLUnregisterWindowChange(hBrowser,dwWindow,Handle) then
        begin
        	nIdx := staRegWindowChange.IndexOf(IntToStr(dwWindow));
             if nIdx >= 0 then
	        		staRegWindowChange.Delete(nIdx);
        	ShowBoolResult(True,'WLUnregisterWindowChange');
        end
    	else
    		ShowBoolResult(False,'WLUnregisterWindowChange');
end;

procedure TMainDlgForm.ParseAnchor;
var
	szAbsURL: array[0..255] of Char;
	szRelURL: array[0..255] of Char;
    pszURL: PChar;
begin
	szAbsURL[0] := Chr(0);
    szRelURL[0] := Chr(0);
    pszURL := Nil;

	if ApiDlgParseAnchor(szAbsURL,SizeOf(szAbsURL),szRelURL,SizeOf(szRelURL)) then
    begin
    	pszURL := WLParseAnchor(hBrowser,szAbsURL,szRelURL);
        if (pszURL = Nil) then
        	ShowBoolResult(False,'WLParseAnchor')
        else
        	ShowStrResult(StrPas(pszURL),'WLParseAnchor');
    end;
end;

procedure TMainDlgForm.GetVersion;
var
	nMajor: Word;
    nMinor: Word;
    dwVersion: LongInt;
begin
	nMajor := 0;
    nMinor := 0;
    dwVersion := 0;

	if ApiDlgGetVersion(nMajor,nMinor) then
    begin
    	dwVersion := WLGetVersion(hBrowser,nMajor,nMinor);
        nMinor := dwVersion and $FFFF;
        nMajor := dwVersion shr 16;
        ShowStrResult2(IntToStr(nMajor),IntToStr(nMinor),'WLGetVersion');
    end;
end;

procedure TMainDlgForm.QueryURLFile;
var
	szFile: array[0..255] of Char;
    pszURL: PChar;
begin
	szFile[0] := Chr(0);
    pszURL := Nil;

	if ApiDlgQueryFile(szFile,SizeOf(szFile)) then
    begin
    	pszURL := WLQueryURLFile(hBrowser,szFile);
        if pszURL = Nil then
        	ShowBoolResult(False,'WLQueryURLFile')
        else
        	ShowStrResult(StrPas(pszURL),'WLQueryURLFile');
    end;
end;

procedure TMainDlgForm.SetNotifyMethod;
var
	bPost: Bool;
    wMethod: Word;
begin
	bPost := True;

	if ApiDlgSetNotifyMethod(bPost) then
    	if bPost then
        	wMethod := WL_POSTMESSAGE
        else
        	wMethod := WL_SENDMESSAGE;

    	if WLSetNotifyMethod(hBrowser,wMethod) then
        	ShowBoolResult(True,'WLSetNotifyMethod')
        else
             ShowBoolResult(False,'WLSetNotifyMethod');
end;

procedure TMainDlgForm.IsToolbarActive;
begin
	if WLIsToolbarActive(hToolbar) then
    	ShowBoolResult(True,'WLIsToolbarActive')
    else
    	ShowBoolResult(False,'WLIsToolbarActive');
end;

procedure TMainDlgForm.SetActiveToolbar;
begin
	if WLSetActiveToolbar(hToolbar) then
    	ShowBoolResult(True,'WLSetActiveToolbar')
    else
        ShowBoolResult(False,'WLSetActiveToolbar');
end;

procedure TMainDlgForm.AddToolbarButton;
var
	nID: Word;
	nIdx: Integer;
	szText: array[0..64] of Char;
	nBitmapStyle: Integer;
	nBitmapMask: Integer;
    hDLLInst: THandle;
    nBitmap: Word;
	nBitmapSel: Word;
	nBitmapFocus: Word;
	nBitmapDisabled: Word;
begin
	nID := 100;
	nIdx := 0;
	szText[0] := Chr(0);
	nBitmapStyle := 1;
	nBitmapMask := $F;

	if ApiDlgAddToolbarButton(nID,nIdx,szText,SizeOf(szText),nBitmapStyle,
    	nBitmapMask) then
    begin
    	hDLLInst := GetApiDlgDLLInstance;
        nBitmap := 0;
		nBitmapSel := 0;
		nBitmapFocus := 0;
		nBitmapDisabled := 0;

        if (nBitmapMask and BM_UP) = BM_UP then
        	nBitmap := nBitmapStyle + APIDLG_BITMAP_UP;
        if (nBitmapMask and BM_SEL) = BM_SEL then
        	nBitmapSel := nBitmapStyle + APIDLG_BITMAP_SEL;
        if (nBitmapMask and BM_FOCUS) = BM_FOCUS then
        	nBitmapFocus := nBitmapStyle + APIDLG_BITMAP_FOCUS;
        if (nBitmapMask and BM_DISABLED) = BM_DISABLED then
        	nBitmapDisabled := nBitmapStyle + APIDLG_BITMAP_DISABLED;

        if WLAddToolbarButtonByID(hToolbar,nID,nIdx,szText,hDLLInst,nBitmap,
			nBitmapSel,nBitmapFocus,nBitmapDisabled) then
        begin
             staToolbar.Add(IntToStr(nID));
        	ShowBoolResult(True,'WLAddToolbarButtonByID');
        end
	    else
        	ShowBoolResult(False,'WLAddToolbarButtonByID');
    end;
end;

procedure TMainDlgForm.RemoveToolbarButton;
var
	nID: Word;
    nIdx: Integer;
begin
	nID := 100;
	if ApiDlgRemoveToolbarButton(nID) then
    	if WLRemoveToolbarButton(hToolbar,nID) then
        begin
        	nIdx := staToolbar.IndexOf(IntToStr(nID));
             if nIdx >= 0 then
	        		staToolbar.Delete(nIdx);
        	ShowBoolResult(True,'WLRemoveToolbarButton');
        end
	    else
        	ShowBoolResult(False,'WLRemoveToolbarButton');
end;

procedure TMainDlgForm.IsToolbarButtonVisible;
var
	nID: Word;
begin
	nID := 100;

	if ApiDlgIsToolbarButtonVisible(nID) then
    	if WLIsToolbarButtonVisible(hToolbar,nID) then
    		ShowBoolResult(True,'WLIsToolbarButtonVisible')
    	else
    		ShowBoolResult(False,'WLIsToolbarButtonVisible');
end;

procedure TMainDlgForm.ShowToolbarButton;
var
	nID: Word;
    bShow: Bool;
begin
	nID := 100;
    bShow := True;

    if ApiDlgShowToolbarButton(nID,bShow) then
    	if WLShowToolbarButton(hToolbar,nID,bShow) then
        	ShowBoolResult(True,'WLShowToolbarButton')
    	else
    		ShowBoolResult(False,'WLShowToolbarButton');
end;

procedure TMainDlgForm.EnableToolbarButton;
var
	nID: Word;
    bEnable: Bool;
begin
	nID := 100;
    bEnable := True;

	if ApiDlgEnableToolbarButton(nID,bEnable) then
    	if WLEnableToolbarButton(hToolbar,nID,bEnable) then
        	ShowBoolResult(True,'WLEnableToolbarButton')
    	else
    		ShowBoolResult(False,'WLEnableToolbarButton');
end;

procedure TMainDlgForm.IsToolbarButtonEnabled;
var
	nID: Word;
begin
	nID := 100;

	if ApiDlgIsToolbarButtonEnabled(nID) then
		if WLIsToolbarButtonEnabled(hToolbar,nID) then
        	ShowBoolResult(True,'WLIsToolbarButtonEnabled')
    	else
    		ShowBoolResult(False,'WLIsToolbarButtonEnabled');
end;

procedure TMainDlgForm.GetToolbarText;
var
	nID: Word;
    pszText: PChar;
    nTemp: Integer;
begin
	nID := 0;
    pszText := Nil;

	if ApiDlgGetToolbarText(nID) then
    begin
    	if nID = 0 then
        begin
        	nTemp := WL_TOOLBARTEXT;	{ quick and dirty to shutup compiler }
        	nID := nTemp;
        end;

    	pszText := WLGetToolbarText(hToolbar,nID);
        if pszText = Nil then
        	ShowBoolResult(False,'WLGetToolbarText')
    	else
    		ShowStrResult(StrPas(pszText),'WLGetToolbarText');
    end;
end;

procedure TMainDlgForm.SetToolbarText;
var
	nID: Word;
    nTemp: Integer;
    szText: array[0..127] of Char;
begin
	nID := 0;
    szText[0] := Chr(0);

	if ApiDlgSetToolbarText(nID,szText,SizeOf(szText)) then
    begin
    	if nID = 0 then
        begin
        	nTemp := WL_TOOLBARTEXT;	{ quick and dirty to shutup compiler }
        	nID := nTemp;
        end;

		if WLSetToolbarText(hToolbar,nID,szText) then
         	ShowBoolResult(True,'WLSetToolbarText')
    	else
    		ShowBoolResult(False,'WLSetToolbarText');
    end;
end;

procedure TMainDlgForm.GetToolbarFont;
var
   	bToolbar: Bool;
    wType: Word;
    szFont: array[0..63] of Char;
    nPointSize: Integer;
    hfontRet: HFont;
begin
	bToolbar := False;

	if ApiDlgGetToolbarFont(bToolbar) then
    begin
    	if bToolbar then
        	wType := WL_TOOLBARFONT
        else
        	wType := WL_BUTTONFONT;

    	hfontRet := WLGetToolbarFont(hToolbar,wType);
        if hfontRet = 0 then
        	ShowBoolResult(False,'WLGetToolbarFont')
        else
        begin
        	szFont[0] := Chr(0);
             nPointSize := 0;

        	ApiDlgGetFontInfo4GL(hfontRet,szFont,SizeOf(szFont),nPointSize);
        	ShowStrResult2(IntToStr(nPointSize),StrPas(szFont),'WLGetToolbarFont');
        end;
	end;
end;

procedure TMainDlgForm.SetToolbarFont;
var
    szFont: array[0..63] of Char;
   	nPointSize: Integer;
   	bToolbar: Bool;
    wType: Word;
    hfontNew: HFont;
begin
	szFont[0] := Chr(0);
    nPointSize := 0;
	bToolbar := False;

	if ApiDlgSetToolbarFont(szFont,SizeOf(szFont),nPointSize,bToolbar) then
    begin
    	hfontNew := ApiDlgCreateFont4GL(szFont,nPointSize);

    	if bToolbar then
        begin
        	wType := WL_TOOLBARFONT;
             if hfontToolbar <> 0 then
             	ApiDlgFreeFont4GL(hfontToolbar);
	        	hfontToolbar := hfontNew;
        end
        else
        begin
        	wType := WL_BUTTONFONT;
             if hfontButton <> 0 then
             	ApiDlgFreeFont4GL(hfontButton);
             hfontButton := hfontNew;
        end;

		if WLSetToolbarFont(hToolbar,wType,hfontNew) then
         	ShowBoolResult(True,'WLSetToolbarFont')
    	else
    		ShowBoolResult(False,'WLSetToolbarFont');
    end;
end;

procedure TMainDlgForm.GetToolbarBkgnd;
var
	crBkgnd: TColorRef;
begin
	crBkgnd := WLGetToolbarBkgnd(hToolbar);
    ShowStrResult(IntToHex(crBkgnd,8),'WLGetToolbarBkgnd');
end;

procedure TMainDlgForm.SetToolbarBkgnd;
var
	nRed: Integer;
	nGreen: Integer;
	nBlue: Integer;
	crBkgnd: TColorRef;
begin
	nRed := 0;
	nGreen := 0;
	nBlue := 0;

	if ApiDlgSetToolbarBkgnd(nRed,nGreen,nBlue) then
    begin
		crBkgnd := RGB(nRed,nGreen,nBlue);
		if WLSetToolbarBkgnd(hToolbar,crBkgnd) then
        	ShowBoolResult(True,'WLSetToolbarBkgnd')
    	else
    		ShowBoolResult(False,'WLSetToolbarBkgnd');
    end;
end;

procedure TMainDlgForm.GetToolbarTextColor;
var
	bToolbar: Bool;
    wType: Word;
    crText: TColorRef;
begin
	bToolbar := False;

	if ApiDlgGetToolbarTextColor(bToolbar) then
    begin
        if bToolbar then
        	wType := WL_TOOLBARTEXTCOLOR
        else
        	wType := WL_BUTTONTEXTCOLOR;

		crText := WLGetToolbarTextColor(hToolbar,wType);
        ShowStrResult(IntToHex(crText,8),'WLGetToolbarTextColor');
	end;
end;

procedure TMainDlgForm.SetToolbarTextColor;
var
	bToolbar: Bool;
    nRed: Integer;
	nGreen: Integer;
	nBlue: Integer;
    wType: Word;
    crText: TColorRef;
begin
	bToolbar := False;
    nRed := 0;
	nGreen := 0;
	nBlue := 0;

	if ApiDlgSetToolbarTextColor(nRed,nGreen,nBlue,bToolbar) then
    begin
    	if bToolbar then
        	wType := WL_TOOLBARTEXTCOLOR
        else
        	wType := WL_BUTTONTEXTCOLOR;
    	crText := RGB(nRed,nGreen,nBlue);

    	if WLSetToolbarTextColor(hToolbar,wType,crText) then
        	ShowBoolResult(True,'WLSetToolbarTextColor')
    	else
    		ShowBoolResult(False,'WLSetToolbarTextColor');
	end;

end;

procedure TMainDlgForm.HtmlEnumParseTree;
begin
	if WLHtmlEnumParseTree(hParse,Handle,WM_WEBLIB_ENUMPARSETREE) then
    	ShowBoolResult(True,'WLHtmlEnumParseTree')
    else
    	ShowBoolResult(False,'WLHtmlEnumParseTree');
end;

procedure TMainDlgForm.HtmlGetChild;
var
	hElement: Htmlpars.HELEMENT;
begin
	hElement := WLHtmlGetChild(hParse,hCurrElement);

    if hElement = 0 then
		ShowBoolResult(False,'WLHtmlGetChild')
    else
    begin
    	hCurrElement := hElement;
        hCurrTagAttr := 0;
    	ShowBoolResult(True,'WLHtmlGetChild');
    end;
end;

procedure TMainDlgForm.HtmlGetParent;
var
	hElement: Htmlpars.HELEMENT;
begin
	hElement := WLHtmlGetParent(hParse,hCurrElement);

    if hElement = 0 then
		ShowBoolResult(False,'WLHtmlGetParent')
    else
    begin
    	hCurrElement := hElement;
        hCurrTagAttr := 0;
    	ShowBoolResult(True,'WLHtmlGetParent');
    end;
end;

procedure TMainDlgForm.HtmlGetSibling;
var
	hElement: Htmlpars.HELEMENT;
    nRel: Word;
begin
	nRel := WL_FIRSTELEM;

	if ApiDlgHtmlGetSibling(nRel) then
    begin
        hElement := WLHtmlGetSibling(hParse,hCurrElement,nRel);

        if hElement = 0 then
            ShowBoolResult(False,'WLHtmlGetSibling')
        else
        begin
            hCurrElement := hElement;
            hCurrTagAttr := 0;
            ShowBoolResult(True,'WLHtmlGetSibling');
        end;
    end;
end;

procedure TMainDlgForm.HtmlGetElementType;
var
	wType: Word;
    szType: string;
begin
	wType := WLHtmlGetElementType(hParse,hCurrElement);

    case wType of
    WL_ROOT:
    	szType := 'ROOT';
    WL_TAG:
    	szType := 'TAG';
    WL_TEXT:
    	szType := 'TEXT';
    WL_SPECIALCHAR:
    	szType := 'SPECIALCHAR';
    WL_COMMENT:
    	szType := 'COMMENT';
    else
    	szType := '???';
    end;

    ShowStrResult(szType,'WLHtmlGetElementType');
end;

procedure TMainDlgForm.HtmlGetElementText;
var
	pszText: PChar;
begin
	pszText := WLHtmlGetElementText(hParse,hCurrElement);
    if pszText = Nil then
    	ShowBoolResult(False,'WLHtmlGetElementText')
    else
     	ShowStrResult(StrPas(pszText),'WLHtmlGetElementText');
end;

procedure TMainDlgForm.HtmlGetTextAttr;
var
	lTextAttr: LongInt;
begin
	lTextAttr := WLHtmlGetTextAttr(hParse,hCurrElement);
    ShowStrResult(IntToHex(lTextAttr,8),'WLHtmlGetTextAttr');
end;

procedure TMainDlgForm.HtmlGetTagName;
var
	pszTag: PChar;
begin
	pszTag := WLHtmlGetTagName(hParse,hCurrElement);
    ShowStrResult(StrPas(pszTag),'WLHtmlGetTagName');
end;

procedure TMainDlgForm.HtmlGetTagType;
var
	wType : Word;
begin
	wType := WLHtmlGetTagType(hParse,hCurrElement);
    ShowStrResult(IntToStr(wType),'WLHtmlGetTagName');
end;

procedure TMainDlgForm.HtmlGetTagAttr;
var
	wType: Word;
    szAttr: array[0..63] of Char;
    szValue: array[0..255] of Char;
    szMsg: String;
begin
	wType := 0;
    szAttr[0] := Chr(0);
    szValue[0] := Chr(0);

	hCurrTagAttr := WLHtmlGetTagAttr(hParse,hCurrElement,hCurrTagAttr,wType,
		szAttr,SizeOf(szAttr),szValue,SizeOf(szValue));
    szMsg := 'TYPE: ' +
    	IntToStr(wType) + ' ATTR: ' +
        StrPas(szAttr) + ' VALUE: ' +
        StrPas(szValue);
    ShowStrResult(szMsg,'WLHtmlGetTagAttr');
end;

procedure TMainDlgForm.HtmlExtractTagAttr;
var
	szAttr: array[0..63] of Char;
    pszValue: PChar;
begin
	if ApiDlgHtmlExtractTagAttr(szAttr,SizeOf(szAttr)) then
    begin
    	pszValue := WLHtmlExtractTagAttr(hParse,hCurrElement,szAttr);
        if pszValue = Nil then
        	ShowBoolResult(False,'WLHtmlExtractTagAttr')
        else
        	ShowStrResult(StrPas(pszValue),'WLHtmlExtractTagAttr');
    end;
end;

procedure TMainDlgForm.HtmlFindText;
var
	szText: array[0..255] of Char;
    hElement: Htmlpars.HELEMENT;
begin
	szText[0] := Chr(0);

	if ApiDlgHtmlFindText(szText,SizeOf(szText)) then
    begin
    	hElement := WLHtmlFindText(hParse,hCurrElement,szText);
        if hElement = 0 then
        	ShowBoolResult(False,'WLHtmlFindText')
        else
        begin
        	ShowBoolResult(True,'WLHtmlFindText');
             hCurrElement := hElement;
             hCurrTagAttr := 0;
        end;
	end;
end;

procedure TMainDlgForm.HtmlFindSpecial;
var
	szText: array[0..255] of Char;
    hElement: Htmlpars.HELEMENT;
begin
	szText[0] := Chr(0);

	if ApiDlgHtmlFindSpecial(szText,SizeOf(szText)) then
    begin
    	hElement := WLHtmlFindSpecial(hParse,hCurrElement,szText);
        if hElement = 0 then
        	ShowBoolResult(False,'WLHtmlFindSpecial')
        else
        begin
        	ShowBoolResult(True,'WLHtmlFindSpecial');
             hCurrElement := hElement;
             hCurrTagAttr := 0;
        end;
	end;
end;

procedure TMainDlgForm.HtmlFindComment;
var
	szText: array[0..255] of Char;
    hElement: Htmlpars.HELEMENT;
begin
	szText[0] := Chr(0);

	if ApiDlgHtmlFindComment(szText,SizeOf(szText)) then
    begin
    	hElement := WLHtmlFindComment(hParse,hCurrElement,szText);
        if hElement = 0 then
        	ShowBoolResult(False,'WLHtmlFindComment')
        else
        begin
        	ShowBoolResult(True,'WLHtmlFindComment');
             hCurrElement := hElement;
             hCurrTagAttr := 0;
        end;
	end;
end;

procedure TMainDlgForm.HtmlFindTagType;
var
	nTag: Word;
    hElement: Htmlpars.HELEMENT;
begin
	nTag := HTML_BASE;

	if ApiDlgHtmlFindTagType(nTag) then
    begin
	    hElement := WLHtmlFindTagType(hParse,hCurrElement,nTag);
        if hElement = 0 then
        	ShowBoolResult(False,'WLHtmlFindTagType')
        else
        begin
        	ShowBoolResult(True,'WLHtmlFindTagType');
             hCurrElement := hElement;
             hCurrTagAttr := 0;
        end;
    end;
end;

procedure TMainDlgForm.HtmlFindTagName;
var
	szTag: array[0..63] of Char;
	hElement: Htmlpars.HELEMENT;
begin
	szTag[0] := Chr(0);

	if ApiDlgHtmlFindTagName(szTag,SizeOf(szTag)) then
    begin
    	hElement := WLHtmlFindTagName(hParse,hCurrElement,szTag);
        if hElement = 0 then
        	ShowBoolResult(False,'WLHtmlFindTagName')
        else
        begin
        	ShowBoolResult(True,'WLHtmlFindTagName');
             hCurrElement := hElement;
             hCurrTagAttr := 0;
        end;
    end;
end;

procedure TMainDlgForm.HtmlFindTagAttr;
var
	szAttr: array[0..63] of Char;
	szValue: array[0..255] of Char;
	nTag: Word;
    hElement: Htmlpars.HELEMENT;
begin
	szAttr[0] := Chr(0);
    szValue[0] := Chr(0);
	nTag := HTML_BASE;

	if ApiDlgHtmlFindTagAttr(szAttr,SizeOf(szAttr),szValue,SizeOf(szValue),nTag) then
    begin
    	hElement := WLHtmlFindTagAttr(hParse,hCurrElement,nTag,szAttr,szValue);
        if hElement = 0 then
        	ShowBoolResult(False,'WLHtmlFindTagAttr')
        else
        begin
        	ShowBoolResult(True,'WLHtmlFindTagAttr');
             hCurrElement := hElement;
             hCurrTagAttr := 0;
        end;
	end;
end;

procedure TMainDlgForm.HtmlEnumFindText;
var
	szText: array[0..255] of Char;
begin
	szText[0] := Chr(0);

	if ApiDlgHtmlEnumFindText(szText,SizeOf(szText)) then
    	if WLHtmlEnumFindText(hParse,hCurrElement,szText,Handle,
        	WM_WEBLIB_ENUMFINDTEXT) then
        	ShowBoolResult(True,'WLHtmlEnumFindText')
        else
        	ShowBoolResult(False,'WLHtmlEnumFindText');
end;

procedure TMainDlgForm.HtmlEnumFindSpecial;
var
	szText: array[0..255] of Char;
begin
	szText[0] := Chr(0);

	if ApiDlgHtmlEnumFindSpecial(szText,SizeOf(szText)) then
    	if WLHtmlEnumFindSpecial(hParse,hCurrElement,szText,Handle,
        	WM_WEBLIB_ENUMFINDSPEC) then
        	ShowBoolResult(True,'WLHtmlEnumFindSpecial')
        else
        	ShowBoolResult(False,'WLHtmlEnumFindSpecial');
end;

procedure TMainDlgForm.HtmlEnumFindComment;
var
	szText: array[0..255] of Char;
begin
	szText[0] := Chr(0);

	if ApiDlgHtmlEnumFindComment(szText,SizeOf(szText)) then
    	if WLHtmlEnumFindComment(hParse,hCurrElement,szText,Handle,
        	WM_WEBLIB_ENUMFINDCOMM) then
        	ShowBoolResult(True,'WLHtmlEnumFindComment')
        else
        	ShowBoolResult(False,'WLHtmlEnumFindComment');
end;

procedure TMainDlgForm.HtmlEnumFindTagType;
var
	nTag: Word;
begin
	nTag := HTML_BASE;

    if ApiDlgHtmlEnumFindTagType(nTag) then
		if WLHtmlEnumFindTagType(hParse,hCurrElement,nTag,Handle,
        	WM_WEBLIB_ENUMFINDTAGTYPE) then
        	ShowBoolResult(True,'WLHtmlEnumFindTagType')
        else
        	ShowBoolResult(False,'WLHtmlEnumFindTagType');
end;

procedure TMainDlgForm.HtmlEnumFindTagName;
var
	szTag: array[0..63] of Char;
begin
	szTag[0] := Chr(0);

	if ApiDlgHtmlEnumFindTagName(szTag,SizeOf(szTag)) then
    	if WLHtmlEnumFindTagName(hParse,hCurrElement,szTag,Handle,
        	WM_WEBLIB_ENUMFINDTAGNAME) then
        	ShowBoolResult(True,'WLHtmlEnumFindTagName')
        else
        	ShowBoolResult(False,'WLHtmlEnumFindTagName');
end;

procedure TMainDlgForm.HtmlEnumFindTagAttr;
var
	szAttr: array[0..63] of Char;
	szValue: array[0..255] of Char;
	nTag: Word;
begin
	szAttr[0] := Chr(0);
    szValue[0] := Chr(0);
	nTag := HTML_BASE;

    if ApiDlgHtmlEnumFindTagAttr(szAttr,SizeOf(szAttr),szValue,SizeOf(szValue),
    	nTag) then
		if WLHtmlEnumFindTagAttr(hParse,hCurrElement,nTag,szAttr,szValue,Handle,
        	WM_WEBLIB_ENUMFINDTAGATTR) then
 			ShowBoolResult(True,'WLHtmlEnumFindTagAttr')
        else
        	ShowBoolResult(False,'WLHtmlEnumFindTagAttr');
end;

procedure TMainDlgForm.AppendFormData;
var
	szData: array[0..255] of Char;
	szName: array[0..63] of Char;
begin
	szName[0] := Chr(0);
    szData[0] := Chr(0);

	if ApiDlgAppendFormData(szData,SizeOf(szData),szName,SizeOf(szName)) then
    begin
    	hFormData := WLAppendFormData(hFormData,szName,szData,SizeOf(szData));
        if hFormData = 0 then
        	ShowBoolResult(False,'WLAppendFormData')
        else
        begin
        	ShowBoolResult(True,'WLAppendFormData');
             OPENCLOSE_BTN.Enabled := True;
        end;
    end;
end;

procedure TMainDlgForm.GetFormDataLength;
var
	wLength: Word;
begin
	if hFormData = 0 then
    	ShowBoolResult(False,'WLGetFormDataLength')
    else
    begin
		wLength := WLGetFormDataLength(hFormData);
        ShowStrResult(IntToStr(wLength),'WLGetFormDataLength')
    end;
end;

procedure TMainDlgForm.ParseAbsoluteURL;
var
	szURL: array[0..255] of Char;
    szProtocol: array[0..15] of Char;
	szHost: array[0..63] of Char;
	szPath: array[0..127] of Char;
    nPort: Word;
    szMsg: string;
begin
	szURL[0] := Chr(0);
    szProtocol[0] := Chr(0);
	szHost[0] := Chr(0);
	szPath[0] := Chr(0);
    nPort := 0;

	if ApiDlgParseAbsoluteURL(szURL,SizeOf(szURL)) then
		if WLParseAbsoluteURL(szURL,szProtocol,SizeOf(szProtocol),szHost,
        	SizeOf(szHost),nPort,szPath,SizeOf(szPath)) then
        begin
        	szMsg := StrPas(szProtocol) + ' ' +
             	    StrPas(szHost) + ' ' +
                      IntToStr(nPort) + ' ' +
                      StrPas(szPath);
        	ShowStrResult(szMsg,'WLParseAbsoluteURL');
        end
        else
             ShowBoolResult(False,'WLParseAbsoluteURL');
end;

procedure TMainDlgForm.ShowBoolResult(bResult: Bool; const szName: String);
begin
	if bResult then
		PROMPT_STATIC.Caption := szName + ': SUCCESS'
    else
    	PROMPT_STATIC.Caption := 'WebLib API failed: ' + szName;
end;

procedure TMainDlgForm.ShowStrResult(const szParm: String; const szName: String);
begin
	PROMPT_STATIC.Caption := szName + ': [' + szParm + ']';
end;

procedure TMainDlgForm.ShowStrResult2(const szParm1: String; const szParm2: String;
	const szName: String);
begin
	PROMPT_STATIC.Caption := szName + ': [' + szParm1 + '] [' + szParm2 + ']';
end;

procedure TMainDlgForm.HandleWeblibNotifyEvent (var msg: TMessage);
var
	dwTrx: LongInt;
    dwWindow: LongInt;
    dwMax: LongInt;
    dwFlags: LongInt;
	dwProgress: LongInt;
    dwX: LongInt;
    dwY: LongInt;
    dwWidth: LongInt;
	dwHeight: LongInt;
    pszProgress: PChar;
    pszURL: pChar;
    pszMIME: pChar;
    pszRef: pChar;
    pszFile: pChar;
    pszFormData: pChar;
    nButtonID: Word;
    szMsg: String;
    szTempFile: String;
    szPTempFile: array[0..255] of Char;
begin
	case msg.wParam of
    WLN_BEGINPROGRESS:
    begin
		dwTrx := WLNGetTransaction(msg.LParam);
        pszProgress := WLNGetProgressString(msg.LParam);
        szMsg := 'BEGINPROGRESS:' +
        	    IntToStr(dwTrx) + ' ' +
                 StrPas(pszProgress);
        AddProgressString(szMsg);
    end;

    WLN_SETPROGRESSRANGE:
    begin
		dwTrx := WLNGetTransaction(msg.LParam);
		dwMax := WLNGetProgressMaximum(msg.LParam);
        szMsg := 'SETPROGRESSRANGE:' +
        	    IntToStr(dwTrx) + ' ' +
                 IntToStr(dwMax);
        AddProgressString(szMsg);
    end;

    WLN_MAKINGPROGRESS:
    begin;
		dwTrx := WLNGetTransaction(msg.LParam);
		dwProgress := WLNGetProgressValue(msg.LParam);
        pszProgress := WLNGetProgressString(msg.LParam);
        szMsg := 'MAKINGPROGRESS:' +
        	    IntToStr(dwTrx) + ' ' +
                 IntToStr(dwProgress) + ' ' +
                 StrPas(pszProgress);
        AddProgressString(szMsg);
    end;

    WLN_ENDPROGRESS:
    begin
    	dwTrx := WLNGetTransaction(msg.LParam);
        szMsg := 'ENDPROGRESS:' + IntToStr(dwTrx);
        AddProgressString(szMsg);
    end;

    WLN_FINISHED:
    begin
		dwTrx := WLNGetTransaction(msg.LParam);
        dwWindow := WLNGetWindow(msg.LParam);
        szMsg := 'FINISHED:' + IntToStr(dwTrx) + ' ' + IntToStr(dwWindow);
        AddProgressString(szMsg);
    end;

	WLN_CANCELED:
    begin
		dwTrx := WLNGetTransaction(msg.LParam);
        szMsg := 'CANCELED:' + IntToStr(dwTrx);
        AddProgressString(szMsg);
    end;

    WLN_URLECHO:
    begin
 		dwWindow := WLNGetWindow(msg.LParam);
        pszURL := WLNGetURL(msg.LParam);
        pszMIME := WLNGetMIMEType(msg.LParam);
    	pszRef := WLNGetReferrer(msg.LParam);
        szMsg := 'URLECHO:' +
        	    IntToStr(dwWindow) + ' ' +
                 StrPas(pszURL) + ' ' +
                 StrPas(pszMIME) + ' ' +
                 StrPas(pszRef);
    	nfyRegURLEcho.Add(szMsg);
    end;

    WLN_OPENURL:
    begin
 		dwWindow := WLNGetWindow(msg.LParam);
        dwTrx := WLNGetTransaction(msg.LParam);
    	dwFlags := WLNGetFlags(msg.LParam);
        pszURL := WLNGetURL(msg.LParam);
        pszMIME := WLNGetMIMEType(msg.LParam);
    	pszFile := WLNGetSaveFile(msg.LParam);
        pszFormData := WLNGetFormData(msg.LParam);
        szMsg := 'OPENURL: WIN=' +
        	    IntToStr(dwWindow) + ' TX=' +
                 IntToStr(dwTrx) + ' FL=' +
                 IntToStr(dwFlags) + ' URL=' +
                 StrPas(pszURL) + ' MIME=' +
                 StrPas(pszMIME) + ' FILE=' +
                 StrPas(pszFile) + ' FMDATA=' +
                 StrPas(pszFormData);
    	nfyRegProtocol.Add(szMsg);
    end;

    WLN_WINDOWCHANGE:
    begin
 		dwWindow := WLNGetWindow(msg.LParam);
    	dwFlags := WLNGetFlags(msg.LParam);
        dwX := WLNGetX(msg.LParam);
    	dwY := WLNGetY(msg.LParam);
    	dwWidth := WLNGetWidth(msg.LParam);
    	dwHeight := WLNGetHeight(msg.LParam);
        szMsg := 'WINDOWCHANGE: WIN=' +
                 IntToStr(dwWindow) + ' FL=' +
                 IntToStr(dwFlags) + ' X=' +
                 IntToStr(dwX) + ' Y=' +
                 IntToStr(dwY) + ' CX=' +
                 IntToStr(dwWidth) + ' CY=' +
                 IntToStr(dwHeight);
    	nfyRegWindowChange.Add(szMsg);
    end;

    WLN_QUERYVIEWER:
    begin
 		pszURL := WLNGetURL(msg.LParam);
    	pszMIME := WLNGetMIMEType(msg.LParam);
        szMsg := 'QUERYVIEWER: ' + StrPas(pszURL) + ' ' + StrPas(pszMIME);
        nfyRegViewer.Add(szMsg);

        szTempFile := 'C:\TEMP\' + IntToHex(GetTickCount,8) + '.HTM';
        StrPCopy(szPTempFile,szTempFile);
        WLNSetFileName(msg.LParam,szPTempFile);
    end;

    WLN_VIEWDOCFILE:
    begin
 		pszURL := WLNGetURL(msg.LParam);
    	pszMIME := WLNGetMIMEType(msg.LParam);
        pszFile := WLNGetFileName(msg.LParam);
    	dwWindow := WLNGetWindow(msg.LParam);
        szMsg := 'VIEWDOCFILE: ' +
                 StrPas(pszURL) + ' ' +
                 StrPas(pszMIME) + ' ' +
                 StrPas(pszFile) + ' ' +
                 IntToStr(dwWindow);
        nfyRegViewer.Add(szMsg);
    end;

    WLN_BUTTONCLICKED:
    begin
 		nButtonID := WLNGetButtonID(msg.LParam);
        szMsg := 'BUTTONCLICKED: ' + IntToStr(nButtonID);
        nfyToolbar.Add(szMsg);
    end;

    WLN_BROWSERSTART:
    begin
        szMsg := 'BROWSERSTART';		{ not recorded, example only }
    end;

    WLN_BROWSEREXIT:
    begin
        szMsg := 'BROWSEREXIT'; 		{ not recorded, example only }
    end;

    else
    	;
	end;
end;

procedure TMainDlgForm.HandleEnumParseTree (var msg: TMessage);
begin
	nfyEnumParseTree.Add(MakeEnumHtmlString(msg.LParam,msg.WParam));
    msg.Result := 1;	{ must be TRUE (1) to continue enumeration }
end;

procedure TMainDlgForm.HandleEnumFindText (var msg: TMessage);
begin
	nfyEnumFindText.Add(MakeEnumHtmlString(msg.LParam,msg.WParam));
    msg.Result := 1;
end;

procedure TMainDlgForm.HandleEnumFindSpecial (var msg: TMessage);
begin
	nfyEnumFindSpecial.Add(MakeEnumHtmlString(msg.LParam,msg.WParam));
    msg.Result := 1;
	;
end;

procedure TMainDlgForm.HandleEnumFindComment (var msg: TMessage);
begin
	nfyEnumFindComment.Add(MakeEnumHtmlString(msg.LParam,msg.WParam));
    msg.Result := 1;
	;
end;

procedure TMainDlgForm.HandleEnumFindTagType (var msg: TMessage);
begin
	nfyEnumFindTagType.Add(MakeEnumHtmlString(msg.LParam,msg.WParam));
    msg.Result := 1;
end;

procedure TMainDlgForm.HandleEnumFindTagName (var msg: TMessage);
begin
	nfyEnumFindTagName.Add(MakeEnumHtmlString(msg.LParam,msg.WParam));
    msg.Result := 1;
end;

procedure TMainDlgForm.HandleEnumFindTagAttr (var msg: TMessage);
begin
	nfyEnumFindTagAttr.Add(MakeEnumHtmlString(msg.LParam,msg.WParam));
    msg.Result := 1;
end;

procedure TMainDlgForm.AddProgressString(const szMsg: String);
begin
	case API_LIST.ItemIndex of
    WLAPI_ShowFile:
        nfyShowFile.Add(szMsg);
    WLAPI_OpenURL:
        nfyOpenURL.Add(szMsg);
    WLAPI_SaveURL:
        nfySaveURL.Add(szMsg);
    WLAPI_PostFormData:
        nfyPostFormData.Add(szMsg);
    WLAPI_SaveFormData:
        nfySaveFormData.Add(szMsg);
    else
    	;
    end;
end;

procedure TMainDlgForm.BrowserUI;
var
	bInfoBtn: Bool;
    bStatusBtn: Bool;
begin
    bInfoBtn := False;
    bStatusBtn := False;

    case API_LIST.ItemIndex of
    WLAPI_ShowFile,
    WLAPI_OpenURL,
    WLAPI_SaveURL,
    WLAPI_PostFormData,
    WLAPI_SaveFormData,
    WLAPI_RegisterProtocol,
    WLAPI_RegisterURLEcho,
    WLAPI_RegisterViewer,
    WLAPI_RegisterWindowChange:
        bInfoBtn := True
    end;

    case API_LIST.ItemIndex of
    WLAPI_RegisterProtocol,
    WLAPI_RegisterViewer,
    WLAPI_RegisterWindowChange,
    WLAPI_RegisterURLEcho:
        bStatusBtn := True;
    end;

    INFO_BTN.Enabled := bInfoBtn;
    STATUS_BTN.Enabled := bStatusBtn;
end;

procedure TMainDlgForm.ToolbarUI;
begin
    INFO_BTN.Enabled := True;
    STATUS_BTN.Enabled := True;
end;

procedure TMainDlgForm.ParserUI;
var
	bInfoBtn: Bool;
begin
    bInfoBtn := False;

    case API_LIST.ItemIndex of
    WLAPI_HtmlEnumParseTree,
    WLAPI_HtmlEnumFindText,
    WLAPI_HtmlEnumFindSpecial,
    WLAPI_HtmlEnumFindComment,
    WLAPI_HtmlEnumFindTagType,
    WLAPI_HtmlEnumFindTagName,
    WLAPI_HtmlEnumFindTagAttr:
        bInfoBtn := True
    end;

    INFO_BTN.Enabled := bInfoBtn;
    STATUS_BTN.Enabled := False;
end;

procedure TMainDlgForm.UtilityUI;
begin
    INFO_BTN.Enabled := False;
    STATUS_BTN.Enabled := False;
end;

procedure TMainDlgForm.BrowserNotifications;
begin
    case API_LIST.ItemIndex of
    WLAPI_ShowFile:
    	INFO_LIST.Items := nfyShowFile;
    WLAPI_OpenURL:
    	INFO_LIST.Items := nfyOpenURL;
    WLAPI_SaveURL:
    	INFO_LIST.Items := nfySaveURL;
    WLAPI_PostFormData:
    	INFO_LIST.Items := nfyPostFormData;
    WLAPI_SaveFormData:
    	INFO_LIST.Items := nfySaveFormData;
    WLAPI_RegisterProtocol:
    	INFO_LIST.Items := nfyRegProtocol;
    WLAPI_RegisterURLEcho:
    	INFO_LIST.Items := nfyRegURLEcho;
    WLAPI_RegisterViewer:
    	INFO_LIST.Items := nfyRegViewer;
    WLAPI_RegisterWindowChange:
    	INFO_LIST.Items := nfyRegWindowChange;
    end;
end;

procedure TMainDlgForm.ToolbarNotifications;
begin
	INFO_LIST.Items := nfyToolbar;
end;

procedure TMainDlgForm.ParserNotifications;
begin
    case API_LIST.ItemIndex of
    WLAPI_HtmlEnumParseTree:
    	INFO_LIST.Items := nfyEnumParseTree;
    WLAPI_HtmlEnumFindText:
    	INFO_LIST.Items := nfyEnumFindText;
    WLAPI_HtmlEnumFindSpecial:
    	INFO_LIST.Items := nfyEnumFindSpecial;
    WLAPI_HtmlEnumFindComment:
    	INFO_LIST.Items := nfyEnumFindComment;
    WLAPI_HtmlEnumFindTagType:
    	INFO_LIST.Items := nfyEnumFindTagType;
    WLAPI_HtmlEnumFindTagName:
    	INFO_LIST.Items := nfyEnumFindTagName;
    WLAPI_HtmlEnumFindTagAttr:
    	INFO_LIST.Items := nfyEnumFindTagAttr;
    end;
end;

procedure TMainDlgForm.UtilityNotifications;
begin
	;  { no-op }
end;

procedure TMainDlgForm.BrowserStatus;
begin
    case API_LIST.ItemIndex of
    WLAPI_RegisterProtocol:
    	INFO_LIST.Items := staRegProtocol;
    WLAPI_RegisterViewer:
    	INFO_LIST.Items := staRegViewer;
    WLAPI_RegisterWindowChange:
    	INFO_LIST.Items := staRegWindowChange;
    WLAPI_RegisterURLEcho:
    begin
         if staRegURLEcho then
              INFO_LIST.Items.Add('Registered');
    end;
    end;
end;

procedure TMainDlgForm.ToolbarStatus;
begin
	INFO_LIST.Items := staToolbar;
end;

procedure TMainDlgForm.ParserStatus;
begin
	; { no-op }
end;

procedure TMainDlgForm.UtilityStatus;
begin
	; { no-op }
end;

function TMainDlgForm.MakeEnumHtmlString(LParam: LongInt; WParam: Word) : String;
var
    szMsg: String;
    pszText: PChar;
    nType: Integer;
    lAttr: LongInt;
begin
    pszText := Nil;
    nType := 0;
    lAttr := 0;

    case WParam of
    WL_ROOT:
		szMsg := 'ROOT';

    WL_TEXT:
    begin
    	pszText := WLHtmlGetElementText(hParse,LParam);
        lAttr := WLHtmlGetTextAttr(hParse,LParam);
        szMsg := 'TEXT: ' + StrPas(pszText) + ' ' + IntToHex(lAttr,8);
    end;

    WL_TAG:
    begin
		pszText := WLHtmlGetTagName(hParse,LParam);
        nType := WLHtmlGetTagType(hParse,LParam);
        szMsg := 'TAG: ' + StrPas(pszText) + ' ' + IntToStr(nType);
	end;

    WL_SPECIALCHAR:
    begin
    	pszText := WLHtmlGetElementText(hParse,LParam);
    	szMsg := 'SPECIALCHAR: ' + StrPas(pszText);
    end;

    WL_COMMENT:
    begin
    	pszText := WLHtmlGetElementText(hParse,LParam);
    	szMsg := 'COMMENT: ' + StrPas(pszText);
    end;

    else
    	szMsg := '???';
    end;

	MakeEnumHtmlString := szMsg;
end;

end.

