Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Showing a modal HTML Dialog from VB

21 views
Skip to first unread message

Csaba2000

unread,
Aug 1, 2003, 2:22:38 PM8/1/03
to
Be a web pioneer - offer some discussion on largely unexplored topic:

The usual way to display a modal dialog is to create a form in your VB project and then do something like myForm.Show
vbModal

But suppose I want to display an HTML Modal Dialog. Then I could create an instance of Internet Explorer, give it an
empty document, and then do myResult = IE.document.parentWindow.showModalDialog (myPage, myArgument). This has been
working tremendously well for me and, beside the obvious, is useful for several tricks such as obtaining the
.Document attribute at the expense of a screen flicker (that capitalization is not a mistake), which I've not found
a way to get to from straight VB.


Recently (03 July 22) I have seen a post on microsoft.public.win32.programmer.ui wherein Christian Astor recommends:
ShowHTMLDialog()
(or WebBrowser control : KB 189634)

I see very little discussion of this ShowHTMLDialog on the web and no examples, and I am really mystified by it. Can
someone enlighten me or would anyone have an example of this that they'd care to donate to the web? Especially as it
relates to VB? Here is Microsoft's documentation:
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/functions/ShowHTMLDialog.asp

Perhaps I'm missing something really basic here, but I don't find ShowHTMLDialog at AllAPI.net, but on the above page
it shows under MSHTML Reference, and I am using mshtml.tlb.
Should I be able to use this call from VB? If so, how do the declares go?, cause that is what I'm having the most
trouble following.

Looking forward to your responses,
Csaba Gabor from New York

Steven

unread,
Aug 1, 2003, 3:57:15 PM8/1/03
to
Hi (Szervusz!)

Steven (Szakats Istvan!)


Eduardo A. Morcillo [MS MVP]

unread,
Aug 1, 2003, 7:10:51 PM8/1/03
to
> Should I be able to use this call from VB?

Yes.

> If so, how do the declares go?

Private Declare Function CreateURLMoniker Lib "urlmon.dll" ( _
ByVal MkCtx As Long, _
ByVal URL As Long, _
Moniker As IUnknown) As Long

Private Declare Function apiShowHTMLDialog Lib "mshtml.dll" _
Alias "ShowHTMLDialog" ( _
ByVal hwndParent As Long, _
ByVal pMk As IUnknown, _
Optional pvarArgIn As Variant, _
Optional ByVal pchOptions As Long, _
Optional pvarArgOut As Variant) As Long

And here is a function that wraps the API calls:

Function ShowHTMLDialog( _
ByVal URL As String, _
Optional ByVal Args As Variant, _
Optional ByVal Options As String, _
Optional ByVal Parent As Form) As Variant
Dim oUrlMk As IUnknown
Dim lRes As Long
Dim hWnd As Long

lRes = CreateURLMoniker(0, StrPtr(URL), oUrlMk)
If lRes Then Err.Raise lRes

If Not Parent Is Nothing Then hWnd = Parent.hWnd

lRes = apiShowHTMLDialog(hWnd, oUrlMk, Args, _
StrPtr(Options), ShowHTMLDialog)
If lRes Then Err.Raise lRes

End Function

ShowHTMLDialog "www.yahoo.com", "param", _
"dialogWidth:100px;dialogHeight:100px"

--
Eduardo A. Morcillo [MS MVP - VB]
http://www.mvps.org/emorcillo


Csaba2000

unread,
Aug 1, 2003, 7:20:00 PM8/1/03
to
Ahem.
In all the excitement, I forgot to add what motivated the original post. While a modal HTML Dialog is up, I want
events on it to be able to cause a change in my underlying OCX.

Suppose a sequence of events like so: A .VBS file is double clicked, it invokes (CreateObject) an .OCX, which in
turn instantiates IE and does the myResult = IE.document.parentWindow.showModalDialog (myPage, myArgument) line. But
while the HTML modal dialog is up, I want to interact with the OCX. For example, the user hits a button on the
dialog and an OCX variable should get changed. Or simply read, for that matter.

One way to do this would be to have a timer in my OCX and check some variable (mySemaphore) within the modal dialog
on each pass. I just hate using timers for this kind of thing, though. And to read a variable would take two
"timers" (one to get the OCX to stuff it into IE's dialog, the second to tell the dialog it's OK to make use of the
variable. Ugly).

That's what led to my interest when I saw the ShowHTMLDialog. So I'm still interested in the original question, but
I'm also curious about alternate approaches to this motivating issue.

Szia (Ciao),
Csaba

"Csaba2000" <ne...@CsabaGabor.com> wrote in message news:#et8$jFWDH...@tk2msftngp13.phx.gbl...

Eduardo A. Morcillo [MS MVP]

unread,
Aug 1, 2003, 7:36:35 PM8/1/03
to
> Suppose a sequence of events like so: A .VBS file is double clicked,
> it invokes (CreateObject) an .OCX, which in turn instantiates IE and
> does the myResult = IE.document.parentWindow.showModalDialog (myPage,
> myArgument) line. But while the HTML modal dialog is up, I want to
> interact with the OCX. For example, the user hits a button on the
> dialog and an OCX variable should get changed. Or simply read, for
> that matter.

Since dialogArguments is a variant you can pass a control reference to the
dialog using it. Using the code from the previous post:

ShowHTMLDialog "www.yahoo.com", Me, ....

If you want to pass more parameters add them to a collection and pass the
collection to the dialog.

Csaba2000

unread,
Aug 1, 2003, 8:26:36 PM8/1/03
to
Eduardo, thank you, Thank You, THANK YOU!
This is majorly cool. And it's also instructive about certain aspects of API declarations. Neat.

I had to make one small change. On my system (VB5/Win2K Pro), I need to prefix www.yahoo.com with http:// in order
for the page to show. Without it I got a blank dialog.

Thanks again for your example!

Csaba

"Eduardo A. Morcillo [MS MVP]" <emorcilloATmvps.org> wrote in message news:umzEoIIW...@TK2MSFTNGP11.phx.gbl...

Csaba2000

unread,
Aug 1, 2003, 8:35:32 PM8/1/03
to
Yea, I got this right as I sent it, but it takes a while for the post to appear.

The funny thing is I posted about how to use this same technique in a slightly different context a day or two ago (in
microsoft.public.scripting.vbscript: Returning arrays from a .vbs file; Passing arrays to VBScript caveat). How soon
I forget, eh?

Good call,
Csaba

"Eduardo A. Morcillo [MS MVP]" <emorcilloATmvps.org> wrote in message news:O0AbAXIW...@TK2MSFTNGP11.phx.gbl...

0 new messages