Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Using Internet Explorer for Cardbox message - how to give focus to IE window"

Using Internet Explorer for Cardbox message - how to give focus to IE window

Current user: [none]
Register / Log In · Help

Posted By Post

Mary Doyle (DAF)

29-Jul-2008 10:32

Hi All,
 
There are times when I would like to present longer and / or more vibrant messages in macros than is possible with MsgBox or Pause. I can do this with Internet Explorer.

My problem is that Internet Explorer and the new window giving the message to the user doesn't automatically get the focus i.e. it stays minimised in the task bar, though it does at least flash. Nevertheless the user has to click on it to view it.

Below is the basic macro I have started experimenting with to generate the message using IE.

If anyone has tried this successfully before and would like to share it, it could save me some work trying to work it out for myself.

Many thanks.

Mary

Set objExplorer = CreateObject("InternetExplorer.Application")
With objExplorer
.Navigate "about:blank"
.Toolbar = 0
.Width = 400
.Height = 200
.Left = 0
Do While (.Busy)
   Sleep 200
Loop
.Visible = 1

.Document.Body.InnerHTML = "Message test from Cardbox"

End With

Set objExplorer = Nothing

bert

29-Jul-2008 11:37

Mary,
Strange, this script should 'steal' the focus...! I tried on my pc and and IE was on foreground with focus.
Perhaps you has to change in you macro also the (xp?) reg settings for preventing to steal focus by an application.
Look at http://www.tek-tips.com/viewthread.cfm?qid=950036&page=6.
Perhaps contains this page some useful info for you.

Kind Regards,
Bert

bert

29-Jul-2008 13:04

Hi Mary,
Bizar.... Now IE does not get focus anymore. Without any change....!
I am anxious to know now, so I wil search also.
B.t.w. it seems not an simple problem. Most 'solutions' on the web has the same problem.
To be continued.
Regards
bert

bert

29-Jul-2008 13:56

Mary,
After reboot of my machine, IE was on foreground again however... I do not use IE as browser. So, when IE was not running, IE got focus. When IE was running, IE did not get focus.

I now found a source which I think will help you. I tried e tested, seens to work good. One important thing: fill sHTMLTitle on the rigt way. Is essential.

Succes,
Bert

  Dim oShell, oWSHShell, sTitle, wndw, bMatch, IE
  sHTMLTitle = "Windows Internet Explorer"
  set oShell = createobject("shell.application")
  set oWSHShell = createobject("Wscript.shell")

  bMatch = false
  for each wndw in oShell.windows
    if instr(lcase(typename(wndw.document)), "htmldocument") > 0 then
      sTitle = wndw.document.title
      if Instr(sTitle, sHTMLTitle)<> 0 then
        bMatch = true
        exit for
      end if
    end if
  next

  if bMatch then

    oWSHShell.AppActivate sHTMLTitle
    oWSHShell.sendkeys "%{enter}" ' Restore if minimized

  else
    set oIE = CreateObject("InternetExplorer.Application")
    oIE.FullScreen = false
    oIE.Navigate "about:blank"
    oIE.Toolbar = 0
    oIE.Application.Width = 400
    oIE.Application.Height = 200
    oIE.Application.Left = 10
    oIE.Application.Document.Body.InnerHTML = "Message test from Cardbox"
    do until oIE.ReadyState = 4 : wsh.sleep 100 : loop
    oIE.visible = true
    oWSHShell.AppActivate sHTMLTitle
  end if

Mary Doyle (DAF)

29-Jul-2008 14:29

Hi Bert,

Very many thanks for all that research. I have tried shutting IE and, as you said, IE got the focus.

I will try your 2nd solution later, as I am a bit tied up now. I will report back on the outcome. It will be very handy if it works as people might pay more attention to the messages if they are more prominent. The Pause message in Cardbox is so small and hard to read that I find people only half read it.

Thanks again.

Mary

Charles Welling

29-Jul-2008 14:40

I may be missing something, but what is wrong with

run "c:\MyMessages\Message01.htm"

The default browser is started with focus, and it shows the page. Execution of the macro is suspended until the user closes the browser. Works fine for me.

Charles

bert

29-Jul-2008 15:21

Nothing wrong, however, no possibility for screenpositioning and in case of dynamic generated content of your message you have to write to a (temp)file.
regards
bert

Mary Doyle (DAF)

29-Jul-2008 16:20

Hi Bert,

You have answered Charles' question perfectly. That is exactly why I was approaching the problem as detailed.

I have just tried your 2nd solution. Works perfectly. Thank you very much.

Mary

Mary Doyle

29-Jul-2008 22:38

Hi Bert and Charles and anyone else that is interested:

Just for the record: when I finalised my test macro I substituted

".Document.Body.InnerHTML = "Message test from Cardbox""

with

"With .document
.Write MessageToShow
End With ' document "

Example below

This is more versatile, or at least it makes it easier to produce a nicely formatted message.

Again, thanks for your help and suggestions.

Mary

Note: The following is just a demo of the possibilities, the message itself is rubbish and at this hour I am not going to replace it with anything else!

MessageToShow = "<li><font color=""#993300"" face=""Birch"">Check SAP details</font></li>" &_
"<li><font color=""#993300"" face=""Birch"">Transfer to SAP</font></li>" &_
"<li><font color=""#993300"" face=""Birch"">Come back to Cardbox and </font></li>" &_
"<li><font color=""#993300"" face=""Birch"">Press F5 to continue</font></li>"
Call ShowMessage(MessageToShow)
Pause "F5 to Continue"

Sub ShowMessage(MesssageToShow)
Set objExplorer = CreateObject("InternetExplorer.Application")
With objExplorer
.Navigate "about:blank"
.Toolbar = 0
.Width = 400
.Height = 200
.Left = 0

Do While (.Busy)
   Sleep 200
Loop
.Visible = 1

'.Document.Body.InnerHTML = "Message test from Cardbox"

With .document
  .Write MessageToShow
End With ' document

End With

Set objExplorer = Nothing

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home