delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (6)


HTML Dialog BoxesFormat this article printer-friendly!Bookmark function is only available for registered users!
using the ShowHTMLDialog function
Product:
Delphi 4.x (or higher)
Category:
Dialogs
Skill Level:
Scoring:
Last Update:
04/20/2003
Search Keys:
delphi delphi3000 article borland vcl code-snippet ShowHTMLDialog HTML-Dialog-boxes HTMLDialog Web-Page-Dialog HTML-Dialog IE-Dialog IE-Dialogs Dialogs-with-HTML
Times Scored:
3
Visits:
5939
Uploader: wes Mess
Company:
Reference: N/A
 
Question/Problem/Abstract:
How can you show System HTML Dialog boxes using the ShowHTMLDialog function in the MSHTML.dll library? Is Internet Explorer ver 4 and higher needed for a ShowHTMLDialog( ) function?
Answer:



Where is the ShowHTMLDialog function, in a  .pas unit?
=====================================================
No. The ShowHTMLDialog( ) function in the MSHTML.dll library. and you will need to use
hLib := LoadLibrary('MSHTML.DLL');
to access this DLL, , , and use the
ShowHTMLDialog := GetProcAddress(hLib, 'ShowHTMLDialog');
to get the function address for this function.
Only if Internet Explorer version 4 and above is installed, can you use this function.

WHAT DOES A HTML DIALOG BOX LOOK LIKE?
=================================
When ShowHTMLDialog is used, Internet Explorer shows an IE Browser window with only a dialog type Title bar (no menu or tool bars, or status). This browser window will read the HTML in a file, and display it like a browser window. If you need user Input (buttons, Edit, radio buttons), you will use JScript (JavaScript or VBScript) as the code language for functions to read or change these Inputs.

WHAT CODE IS NEEDED TO USE THE HTML DIALOG?
=====================================
Since the HTML Dialog is an Internet Explorer browser window, COM is used to comunicate between your program and IE, with Variants, IMoniker and IHTMLDialog interfaces. And the ShowHTMLDialog function will implement these interfaces for you.
the ShowHTMLDialog fuction is defined below -

function ShowHTMLDialog(
  hwndParent: Cardinal;  // parent's Handle
  UrlMnk: IMoniker;  // IMoniker which has the HTML source file
  PvarArgIn: PVariantArg; // Variant address that contains PWChar sent to dialog
  PWCHOptions: PWChar; // pointer to Wide Char with Dialog Options
  PvarArgOut: PVariantArg // Variant address receives the data placed in IHTMLDialog::returnValue
  ): HRESULT; // function Result is an OLE HRESULT (Integer)

Parameters

hwndParent - Handle to the parent of the dialog box, can be Zero.

UrlMnk - An IMoniker interface containing the URL from which the HTML file for the dialog box is loaded,
         file can be in app's resources.

PvarArgIn - Pointer to a VariantArg record that contains the data sent to the dialog box.
            The data passed in this VariantArg is placed in the dialog window object's IHTMLDialog::dialogArguments
            property. This is mostly set as a VT_BSTR, with a PWChar for text the dialog will use for display.
            This parameter can be set as an empty VariantArg (VT_EMPTY).

PWCHOptions - Window options for the dialog box. This parameter can be NIL or the address of a PWChar
              that contains a combination of values, each separated by a semicolon (;).
              POptions := 'dialogHeight:13;dialogWidth:21;resizable:no;help:no;center:yes'

PvarArgOut - Pointer to a VariantArg record that contains the data sent from the dialog box when
             it closes. This VariantArg gets the data that was placed in the dialog window object's
             IHTMLDialog::returnValue property. This parameter can be an empty VariantArg.

Result Value - Returns S_OK if successful, or an error value.


-----------------------------------------
The Second parameter in ShowHTMLDialog is an IMoniker type, in order to place data into an IMoniker, you would use the CreateURLMoniker Function in the UrlMon.pas, defined below

   function CreateURLMoniker(
     MkCtx: IMoniker; // moniker to use as the base context, can be NIL
     szURL: PWChar;  // contains the text of URL to be parsed
     out mk: IMoniker // moniker with the new URL created from MkCtx and szURL.
     ): HResult; // function Result is an OLE HRESULT (Integer)

This Url string (szURL) needs to be prefixed with the  "file://"  to signify a disk file location,
or with the  "res://"  to signify a programs resource location, followed by the path and file name,
and a "/#" then the resource number, like this for file -
UrlStr := 'file://C:\Program Files\HtmlDlg1.htm';
or
UrlStr := 'file://'+ExtractFilePath(ParamStr(0))+'HtmlDlg1.htm';

from resource
UrlStr := 'res://MyProgram.exe/#101';
or
UrlStr := 'res://'+ExtractFileName(ParamStr(0))+'/#101';
    ====>  the  #101 is defined in your resource creation  .rc  file
-----------------------------------------

The Third and Fifth parameters in ShowHTMLDialog is a PVariantArg type, this is a Variant that delphi does not automatically "Decode" for you, so you will need to read or set the variant data type  .vt (VarArgs.vt) yourself and then use that data "Type" when using the data in the Variant.


SAMPLE BUTTON CLICK CODE FOR HTML DIALOG
===================================================================

Here is a Button Click that will show an Html Dialog Box. I do not check for Internet Explorer version, since this does not use DHTML or COM objects that are only in higher versions (5, 6, 7 , 8) of IE. This uses a htm file on disk (HtmlDlg1.htm) in the applications folder. A text string (VarArgs.bstrVal) is sent to the dialog with the dialog Title, an Information text string, and text items to put in the Combo Box.
The code for the HtmlDlg1.htm web page is below this button click code.


procedure TForm1.button_FileHtmlDlgClick(Sender: TObject);
type
  TShowHTMLDialog = function(hwndParent: Cardinal;
    UrlMnk: IMoniker; PvarArgIn: PVariantArg;
    PWCHOptions: PWChar; PvarArgOut: PVariantArg): HRESULT; stdcall;

var
hLib2: Integer;
ShowHTMLDialog: TShowHTMLDialog;
URLMoniker: IMoniker;
VarArgs, VarReturn: TVariantArg;
ArugStr, UrlStr, Return: String;
POptions: PWChar;

begin
Return := 'ERROR, IE version is Below 4 or does not support HTML dialogs';
hLib2 := LoadLibrary('MSHTML.DLL');
  if hLib2 <> 0 then
    try
    ShowHTMLDialog := GetProcAddress(hLib2, 'ShowHTMLDialog');
    if Assigned(ShowHTMLDialog) then
      begin
      {the PvarArgIn is used to Pass Data To the HTML Dialog.
       The VarArgs Variant will be used here as a PWChar, with the  ^  being
       used as a Delimiter for the seven sub Strings, that are sent to the Dialog}
      ArugStr := 'HTML Dialog Top Title^This is Information text passed to the '+
                 'Dialog
Type your Name Below^Small^Medium^Large^'+
                 'My Size^One size fits all';
{the first sub string is the dialog Title, the next substring is the text (and HTML)
that will be written to the html with JScript  document.write(ArgArray[1]) ,
notice that I have HTML tags in this Text, this allows you to customize the dialog
from your programs data, all of the sub strings that follow are placed in the Combo Box}
      VarArgs.vt := VT_BSTR;
      VarArgs.bstrVal := StringToOleStr(ArugStr);

      {the UrlStr is prefixed with the  file://  to signify a disk file,
       use  res://  to sigify a resource}
      UrlStr := 'file://'+ExtractFilePath(ParamStr(0))+'HtmlDlg1.htm';
      {the URLMoniker is set to the URL of the source of the htm file used for
      the dialog box, it can be a disk file, a program resource, or an Internet
      file address, if the html file is not found, a blank dialog box is displayed}

      OLECheck(CreateURLMoniker(nil, StringToOleStr(UrlStr), URLMoniker));

      POptions := 'dialogHeight:17;dialogWidth:23;resizable:no;help:no;center:yes';
      {POptions can be omitted (set to nil), but it allows you to set some options
       of the dialog, like width and height}
      VariantInit(OleVariant(VarReturn));
      {VariantInit sets the VarReturn.vt to VT_EMPTY}
      if ShowHTMLDialog(Handle, URLMoniker, @VarArgs, POptions, @VarReturn) = S_OK then
        begin
        {the JScript  window.returnValue  will automatically set the VarReturn.vt to the
        data Type that is assigned to it, I only use 2 data types for the
        window.returnValue  , a JScript text string (VT_BSTR  - OLE wide string) and an
        integer (VT_I4)  , so any other variant data type will indicate an Error}
        if VarReturn.vt = VT_BSTR then
          begin
          Return := VarReturn.bstrVal;
          {I use a  ^  to delimit the VarReturn.bstrVal, but the first
          Char is the Radio Box number, which is below 9, so I do not
          delimit it, since it will always be a single Char Return[1]}
          Return := 'OK was Clicked'#10'Radio was '+Return[1]+#10+
          'Combo1 was '+Copy(Return,2,Pos('^',Return)-2)+
          #10'Edit Text was  '+Copy(Return,Pos('^',Return)+1, 512);
          end else
        if VarReturn.vt = VT_I4 then
          Return := 'OK was NOT clicked'#10'the VarReturn is '+IntToStr(VarReturn.lVal)
          else
          Return := 'Variant Data type is not integer or OLE string, ERROR';
        end else
          Return := 'The ShowHTMLDialog FAILED';
      end;
    finally
    FreeLibrary(hLib2);
    end;
ShowMessage(Return);
end;


HTML CODE FOR DIALOG ABOVE
===========================================================================
Below is the HTML code for the web page HtmlDlg1.htm , to be displayed in the HTML Dialog box created by the Delphi code above. To get funtionality from your dialog box (button press, enter text, combo boxes) you will need to use a HTML Script language. If you do not know HTML or any HTML Scripting language (JScript, JavaScript, VBscript), then HTML dialog boxes are not for you.
The  window.dialogArguments  is your access to Data passed to the Dialog Box. You will usually pass a Wide String or Integer in your   VarArgs  parameter to the dialog box. If you want more than One Data Item in your  VarArgs  variant, you can use a Delimited String and the split method in
ArgArray = window.dialogArguments.split("^");
split will use it's single parameter as the delimiter charater, to divide up the string into an Array.
The only data this usage gets from the dialog box comes in the    VarReturn   variant. If you need more than one data Item returned, you can again use a delimited string, as I have done here.





HTML Dialog Test



A HTML Dialog Box







Howdy

Late

Goomba

Pick your Size -


       




----------------------------------------------------------------------------------
There are seven sub-strings in the VarArgs of the ShowHTMLDialog parameter, the first string is used as the Dialog Title.
The second as the "INFO" text written to the HTML page with JScript. And all of the remaining sub-strings are added to the Combo box.
For more advanced HTML Dialog boxes, it is also posible to set up an IDispatch link between the dialog box and your program, so the dialog box could call code in in your delphi program through IDispatch.


USING A RESOURCE FOR THE HTML FILE SOURCE
===================================================================================
You can use the Same code above for a Program Resource Html File, Except you must change the UrlStr to -

UrlStr := 'res://'+ExtractFileName(ParamStr(0)+'/#101';
OLECheck(CreateURLMoniker(nil, StringToOleStr(UrlStr), URLMoniker));

and add a resource to your program where you will need to Define the HTML file as number 23 and Define the call for that resource as a Number, like this for HtmDlg.rc  -

#define RT_HTML 23
#define Dlg1 101

Dlg1 RT_HTML "HtmlDlg1.htm"

------------------------------------------------------------------------------
You will need to define the RT_HTML as the number  23  (you could use any other designation beside RT_HTML, but thats the MS name).
And then give your htm files a number definition like  101 .

-----------------------------------------------
If you have a Web Browser or other web page display in your program, you may consider using the HTML Dialogs





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
more of HTML for dialog
    wes Mess (Apr 20 2003 7:22PM)


function OkClick()
{
//this return value means that the OK button was clicked
window.returnValue = RBnum+Combo1.options[Combo1.selectedIndex].text+"^"+Edit1.value;
//since the window.returnValue is a variant, it cant get text or numbers or objects
//The Integer  RBnum  is automatically converted to text

//close the dialog window
window.close();
}

function CancelClick()
{
//this -1 return value means that the Cancel button was clicked
window.returnValue = -1;
window.close();
}

function RadioClick(num)
{
RBnum = num;
// check and UnCheck the Radios
RB1.checked = (num == 0);
RB2.checked = (num == 1);
RB3.checked = (num == 2);
}

</script></head>
Respond

RE: more of HTML for dialog
anonymus (Dec 12 2005 10:36PM)

wrwr vrwerew rewr wer werwer wer wer
Respond

second try
    wes Mess (Apr 20 2003 7:19PM)

<!--TOOLBAR_START--><!--TOOLBAR_EXEMPT--><!--TOOLBAR_END-->
<html id=dlg1 style="width: 25.9em; height: 22em">
<!-- If you DO NOT use the PWCHOptions in the ShowHTMLDialog, you can
put dialog window's width and height above -->
<head><title>HTML Dialog Test</title>

<script language="JScript">
var RBnum = 0;

var ArgArray = new Array();
//get the dialog arguments into an array with .split and the delimiter
ArgArray = window.dialogArguments.split("^");

//the ArgArray check below is not nessary, but allows you to have a Default
//dialog box with an empty  PvarArgIn  from ShowHTMLDialog
if (ArgArray.length == 0) {
ArgArray[0] = "Dialog Title";}
if (ArgArray.length == 1) {
ArgArray[1] = "No <b>Info</b> Text";}
if (ArgArray.length == 2) {
ArgArray[2] = "None";}

//the first Array string is the Title
document.title = ArgArray[0];
//set the default return value
window.returnValue = 0;

function StartUp()
{
//clear selections in Combo1
Combo1.options.length = 0;

//add the ArgArray strings to the Combo1 selections
var index;
index = 2;
// start with index of 2 because the first 2 strings are title and info
while(index < ArgArray.length)
   {
   var tempOption = new Option(ArgArray[index]);
   Combo1.options[Combo1.options.length] = tempOption;
   index++;
   }

//set the first Combo1 selection position
Combo1.options[0].selected = true;
}
Respond

crap
    wes Mess (Apr 20 2003 7:14PM)

My second try did not work either, ,  I guess you can not show HTML code here? ?
so you might look at the source code for this web page in your browser and fish out the HTML yourself
Respond

RE: crap
jae rowe (Jul 3 2003 6:31PM)

use xmp tags to embed html in a page and show it as text
Respond

Show HTML Code
    wes Mess (Apr 20 2003 7:10PM)

Seems that the HTML code was rendered as HTML above, so you can not see it. . .  Maybe this will show - - - First part






HTML Dialog Test




 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
E. Irigoyen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)