?
Solved

HTML Dialogs?

Posted on 2003-03-31
7
Medium Priority
?
453 Views
Last Modified: 2010-04-03
Hi,
Can anybody give me some information or links about using HTML dialogs in delphi?
My main question is how I can access data in a HTML dialog ( for example edis boxes ) ?
0
Comment
Question by:Ayd192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 34

Expert Comment

by:Slick812
ID: 8249385
hello Ayd192, You ask about HTML dialogs in delphi, I have tried to use the ShowHTMLDialog( ) function from the MSHTML.DLL and could not get it to work compleatly, I did get a HTML Dialog box to show. For this you will not only need to know Delphi And API, and COM, but JScript and HTML as well, here is some code for a simple HTML Dialog. . . .

FIRST, the HTML code for the for the Dialog.htm

<html>
<!--TOOLBAR_START--><!--TOOLBAR_EXEMPT--><!--TOOLBAR_END-->
<HTML id=Dialog1 STYLE="height: 17em; width: 15em">
<head><title>HTML Dialog</title>
<SCRIPT language="JScript">
<!--
window.returnValue = 0;
--->
</SCRIPT>
</head>
<BODY  BGCOLOR="#DEE2C0" TEXT="#000000" LINK="#0000CC" VLINK="#990099" ALINK="#CC0000">
<center><font size="+2" face="Comic Sans MS, Arial" color = "Red"><b>HTML Dialog</b><br></font><br><br>
This is the HTML Dialog page, So What<br><br>
<HR width="70%">
<FONT SIZE="+1" face="Arial">Click a Button to close this HTML Dialog Box</FONT>
   
<P><INPUT type=BUTTON value="OK" id="okButton" onClick="window.returnValue = 22; window.close();">
 &nbsp; &nbsp;
<INPUT type=BUTTON value="Cancel" id="cancelButton" class=button onClick="window.returnValue = 30; window.close();">
</body></html>


============================================================

NEXT, the Delphi code for your button press -


uses
UrlMon, ActiveX, ComObj;

procedure TForm1.but_HtmlDialogClick(Sender: TObject);
type
  TShowHTMLDialog = function(hwndParent: Cardinal;
    IMnk: IMoniker; varArgIn: OleVariant;
    PWCHOptions: PWCHAR; varArgOut: OleVariant): HRESULT; stdcall;

var
hLib2: Integer;
ShowHTMLDialog: TShowHTMLDialog;
pURLMoniker: IMoniker;
VarArgs, VarReturn: OLEVariant;
HR1: HRESULT;
Str1: String;
begin
hLib2 := LoadLibrary('MSHTML.DLL');
  if hLib2 <> 0 then
    try
    ShowHTMLDialog := GetProcAddress(hLib2, 'ShowHTMLDialog');
    if @ShowHTMLDialog <> nil then
      begin
      VarReturn := 1;
      OLECheck(CreateURLMoniker(nil, 'file:E:\Dialog.htm', pURLMoniker));
      HR1 := ShowHTMLDialog(Handle, pURLMoniker, VarArgs, nil, VarReturn);
      if HR1 = S_OK then
        begin
        if VarIsEmpty(VarReturn) then
          ShowMessage('varOleStr');
          str1 := VarReturn;
          ShowMessage('VarReturn is '+str1);
        end else
          ShowMessage('The ShowHTMLDialog FAILED');;
      end;
    finally
    FreeLibrary(hLib2);
    end;
end;


================================================================== = = = = = =  ==
I could not find any webpages for info about Delphi using ShowHTMLDialog( ), I did find some for C++,, but they did not provide much more info than the MSDN example web page .. . .
I could not get the VarArgs to be accepted with information in it, only if it was empty
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 150 total points
ID: 8276592
Update!
Here is some code that seems to work, and get the HTML Dialog Boxes. . . .
First I will show the Code for the HtmDlg.rc  Resource file, where you need to define the numerical values for your resources, the sunny.gif is a 68x67 pixel .GIF file. the  Hbut1.jpg  is a 56x31 pixel .JPG file.

code for  HtmDlg.rc
-------------------------------------------------------


#define RT_HTML 23
#define GIF 701
#define JPG 801
#define Dlg1 101
#define Dlg2 102
#define TopL 201
#define TopR 202


Dlg1 RT_HTML "Dialog1.htm"
Dlg2 RT_HTML "Dialog2.htm"
TopL GIF "sunny.gif"
TopR JPG "Hbut1.jpg"


------------------------------------------------------

Next is the HTML code for the  Dialog1.htm  file, this uses the JScript
ArgArray = window.dialogArguments.split("^");
to get the VarArgs Variant String and Split it into an Array
--------------------------------------------------------

<!--TOOLBAR_START--><!--TOOLBAR_EXEMPT--><!--TOOLBAR_END-->
<HTML id=dlgAbout STYLE="width: 25.9em; height: 22em">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<HEAD><TITLE>Sample HTML Dialog</TITLE></HEAD>

<SCRIPT language="JScript">
var ArgArray = new Array();
//get the sub-Strings in VarArgs
ArgArray = window.dialogArguments.split("^");
if (ArgArray.length == 0) {
ArgArray[0] = "AlphaBlend.exe";}
// set values if none are received
if (ArgArray.length == 1) {
ArgArray[1] = "Dialog Title";}
if (ArgArray.length == 2) {
ArgArray[2] = "No <b>Info</b> Text";}
if (ArgArray.length == 3) {
ArgArray[3] = "None";}

// ArgArray[0] is the Apps File Name used for resource of the images
var Gif_Img = '<img src="res://'+ArgArray[0]+'/#701/#201" width="68" height="67" align="Left">';
var Jpg_Img = '<img src="res://'+ArgArray[0]+'/#801/#202" width="56" height="31" align="Right">';

// ArgArray[1] is the Title Bar Text
document.title = ArgArray[1];

//set the default return value
window.returnValue = 0;

function StartUp()
{
//clear the list
Combo1.options.length = 0;

//add the arguments to the list
var index;
index = 3;
while(index < ArgArray.length)
   {
   var tempOption = new Option(ArgArray[index]);
{you need to Typecast the ArgArray[index] string to a Option}
   Combo1.options[Combo1.options.length] = tempOption;
   index++;
   }

//set the first argument to be selected
Combo1.options[0].selected = true;
}

function OkClick()
{
//this return value means that the OK button was clicked
// window.returnValue is the VarReturn Variant
window.returnValue = Combo1.options[Combo1.selectedIndex].text+"^"+Edit1.value;
//close the dialog
window.close();
}

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

<body onload="StartUp()" BGCOLOR="#A0E2E2" TEXT="Black">
<center><script language="JScript">document.write(Gif_Img)
// you need to write any Passed Info with document.write
</script>
<script language="JScript">document.write(Jpg_Img)</script>
<font size="4">A HTML Dialog Box</font>
<p><br><br><SCRIPT language="JScript">document.write(ArgArray[2])</script>
<br><INPUT type=TEXTAREA NAME="Edit1" value="No Name" ROWS="1" COLS="38">
<P>Pick your Size - <SELECT NAME="Combo1"></SELECT>    
<P><INPUT type=BUTTON value="OK" id="OkButton" onClick="OkClick()">&nbsp; &nbsp; &nbsp; &nbsp;
<INPUT type=BUTTON value="Cancel" id="cancelButton" class=button onClick="CancelClick()">
</center>
</body></html>


------------------------------------------------------------------------------------

Next is the HTML code for the  Dialog2.htm  file
--------------------------------------------------------

<!--TOOLBAR_START--><!--TOOLBAR_EXEMPT--><!--TOOLBAR_END-->
<HTML id=Dialog1 STYLE="height: 18em; width: 15em">
<head><title>d</title>
<SCRIPT language="JScript">
var arrArgs = new Array();
// this HTML does NOT have anything in it except the document.write(arrArgs[1]) to compleatly create this page from the VarArgs
arrArgs = window.dialogArguments.split("^");
if (arrArgs.length == 0) {
arrArgs[0] = "Dialog Title";}
if (arrArgs.length == 1) {
arrArgs[1] = '</head><body><center>NOTHING HERE<br><br><INPUT TYPE="button"  VALUE=" OK "  onClick="window.close();"></center>';}

document.title = arrArgs[0];
window.returnValue = 0;

document.write(arrArgs[1])
</SCRIPT>
</body></html>

----------------------------------------------------------------------------------

Next is the code for a button click event that will display the Dialog1.htm from resource
-----------------------------------------------

procedure TForm1.button_HtmDlg1Click(Sender: TObject);
type
  TShowHTMLDialog = function(hwndParent: Cardinal;
    IMnk: IMoniker; varArgIn: PVariantArg;
    PWCHOptions: PWChar; varArgOut: PVariantArg): HRESULT; stdcall;

var
hLib2: Integer;
ShowHTMLDialog: TShowHTMLDialog;
pURLMoniker: IMoniker;
VarArgs, VarReturn: TVariantArg;
ArugStr, ResStr, Return: String;
POptions: PWChar;
begin
hLib2 := LoadLibrary('MSHTML.DLL');
  if hLib2 <> 0 then
    try
    ShowHTMLDialog := GetProcAddress(hLib2, 'ShowHTMLDialog');
    if @ShowHTMLDialog <> nil then
      begin
{to load Images in the Html Dialog I need to pass the App's file name in ResStr, this is added
to the ArugStr as the first index}
      ResStr := ExtractFileName(ParamStr(0));
{the ArugStr will go to the Dialog Box in the VarArgs Variant as the window.dialogArguments.split("^");
I use the  ^  as the delimiter}
      ArugStr := ResStr+'^Dialog Top Title^This is Information text passed to the Dialog<br><b>'+
                 'Type your Name Here</b>^Small^Medium^Large^My Size';
      VarArgs.vt := VT_BSTR;
      VarArgs.bstrVal := StringToOleStr(ArugStr);
      ResStr := 'res://'+ResStr+'/#101';
{ResStr will be the Resource location for the Htm file that the pURLMoniker will get as a IMoniker
you must use the resource creation with the RT_HTML as 23}
      POptions := 'dialogHeight:17;dialogWidth:23;resizable:yes;help:no;center:yes';
{POptions sets the width, height and resizable of the dialog box, it is Optional}
      OLECheck(CreateURLMoniker(nil, StringToOleStr(ResStr), pURLMoniker));
      VariantInit(OleVariant(VarReturn));
{for IE4 you need to call VariantInit}
      if ShowHTMLDialog(Handle, pURLMoniker, @VarArgs, POptions, @VarReturn) = S_OK then
        begin
{you can check to see what type of data comes back with, , if VarReturn.vt = VT_BSTR}
        if VarReturn.vt = VT_BSTR then
          begin
          Return := VarReturn.bstrVal;
{I use the  ^  as a delimeter for the return string}
          ShowMessage('OK was Clicked'#10'Combo1 was '+Copy(Return,1,Pos('^',Return)-1)+
          #10'Edit Text was  '+Copy(Return,Pos('^',Return)+1, 512));
          end;
        if VarReturn.vt = VT_I4 then
          ShowMessage('OK was NOT clicked'#10'the VarReturn is '+IntToStr(VarReturn.lVal));
        end else
          ShowMessage('The ShowHTMLDialog FAILED');
      end;
    finally
    FreeLibrary(hLib2);
    end;
end;

----------------------------------------------------------------------

The Next code is for a button Click that shows a HTML Dialog Box, , but
ALL of the HTML code for it is Written in the VarArgs String and passed to the Dialog box
Look at the Dialog2.htm code above
---------------------------------------------------------------


procedure TForm1.but_HtmDlg2Click(Sender: TObject);
type
  TShowHTMLDialog = function(hwndParent: Cardinal;
    IMnk: IMoniker; varArgIn: PVariantArg;
    PWCHOptions: PWChar; varArgOut: PVariantArg): HRESULT; stdcall;

var
hLib2: Integer;
ShowHTMLDialog: TShowHTMLDialog;
pURLMoniker: IMoniker;
VarArgs, VarReturn: TVariantArg;
ArugStr, ResStr, Return: String;
POptions: PWChar;
begin
hLib2 := LoadLibrary('MSHTML.DLL');
  if hLib2 <> 0 then
    try
    ShowHTMLDialog := GetProcAddress(hLib2, 'ShowHTMLDialog');
    if @ShowHTMLDialog <> nil then
      begin
{in the ArugStr the first text block is the Title of the Dialog
the next Text block is ALL of the HTML that will be used in for display of the HTML Dialog,
this way you can compleately change the Dialog Display and write ALL of it's contents, so you can
create many different diaologs using the same resource HTML file}


      ArugStr := 'Dialog Title^<SCRIPT language="JScript">function okButtonClick()'+
      '{window.returnValue = Edit1.value;window.close();}</SCRIPT>'+
      '</head><body BGCOLOR="#00D2F0"><br><center>Type Your Name here<br><br>'+
      '<INPUT type=TEXTAREA NAME="Edit1" value="No Name" ROWS="1" COLS="38"><br><br><br><INPUT TYPE="button"  '+
      'VALUE=" OK "  onClick="okButtonClick();"></center>';
      VarArgs.vt := VT_BSTR;
      VarArgs.bstrVal := StringToOleStr(ArugStr);
      ResStr := ExtractFileName(ParamStr(0));
      ResStr := 'res://'+ResStr+'/#102';
      POptions := 'dialogHeight:13;dialogWidth:21;resizable:no;help:no;center:yes';
      OLECheck(CreateURLMoniker(nil, StringToOleStr(ResStr), pURLMoniker));
      VariantInit(OleVariant(VarReturn));
      if ShowHTMLDialog(Handle, pURLMoniker, @VarArgs, POptions, @VarReturn) = S_OK then
        begin
        if VarReturn.vt = VT_BSTR then
          begin
          Return := VarReturn.bstrVal;
          ShowMessage(Return);
          end;
        if VarReturn.vt = VT_I4 then
          ShowMessage('OK was NOT clicked'#10'the VarReturn is '+IntToStr(VarReturn.lVal));
        end else
          ShowMessage('The ShowHTMLDialog FAILED');
      end;
    finally
    FreeLibrary(hLib2);
    end;
end;
0
 
LVL 1

Author Comment

by:Ayd192
ID: 8286187
Hi Slick812,
Sorry for my late reply.

Thank you for your answers, they helped a lot ( Actually they answered almost all of my questions).

I should confess I didn't understand the part you use resources to pass images to dialog and your code dind't work right on this, but rest of the code was great.

thanx
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 34

Expert Comment

by:Slick812
ID: 8286927
Yea, I did this in win XP with IE  ver 6, I'm not sure if the images from resources is suppose to work in all versions of IE (four and above)  or not, but it works for me in IE 6. I fould the code to get the images from resources, but it did not say anything about the version of IE that it did or did not work in. This was a tough one to figure out the code for, since the only sample code I could find was in C++
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8304661
do you need somethig else?
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8821355
Ayd192  

Is this question still active?

Do you need more help with this?
0
 
LVL 1

Author Comment

by:Ayd192
ID: 8823267
Thank you Slick812,
as I've told you, your answers helped a lot.
I've forget to Accept your answer, but I'll do it now.

Excuse me for being late.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question