November 30, 2020, 02:21:03 AM

Author Topic: [bb] CreateAgent by skidracer [ 1+ years ago ]  (Read 699 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] CreateAgent by skidracer [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : CreateAgent
Author : skidracer
Posted : 1+ years ago

Description : This code demonstrates control of an activex object using the new HTMLViewRun command. You get agents with Microsoft office or download them from

<a href="http://www.microsoft.com/MSAgent" target="_blank">http://www.microsoft.com/MSAgent[/url]

note: BlitzMax/MaxGui code has been posted further below.


Code :
Code: BlitzBasic
  1. Function ReadObject(x,y,w,h,group)
  2. ; read script from data restore point
  3.         script$=""
  4.         While True
  5.                 Read s$
  6.                 If s$="" Exit
  7. ;               s$=Replace$(s$,"'",Chr$(34))
  8.                 If script$<>"" script$=script$+Chr$(13)+Chr$(10)
  9.                 script$=script$+s$
  10.         Wend
  11. ; create a gadget to run our object
  12.         shell=CreateHtmlView(x,y,w,h,group,2)
  13.         While True
  14.                 id=WaitEvent()
  15.                 If id=$401 And EventSource()=shell And EventID=0 Exit
  16.         Wend
  17.         HtmlViewRun shell,script$
  18.         Return shell
  19. End Function
  20.  
  21. Function CreateAgent(x,y,w,h,group)
  22. ; read script from data
  23.         Restore AgentScript
  24.         Return ReadObject(x,y,w,h,group)
  25. End Function
  26.  
  27. Function AgentSpeak(agent,message$)
  28.         HtmlViewRun agent,"Merlin.Speak('"+message$+"')"
  29. End Function
  30.  
  31. .AgentScript
  32.         Data "var AgentControl=new ActiveXObject('Agent.Control')"
  33.         Data "AgentControl.Connected=true"                                     
  34.         Data "AgentControl.Characters.Load('Merlin')"                   ;,"http://agent.microsoft.com//agent2//chars//merlin//merlin.acf");
  35.         Data "var Merlin = AgentControl.Characters.Character('Merlin')"
  36.         Data "Merlin.LanguageID=0x0409"
  37.         Data "Merlin.MoveTo(200,200)"
  38.         Data "Merlin.Show()"
  39.         Data "Merlin.Speak('YO!')"
  40.         Data ""
  41.        
  42. win=CreateWindow("Basic Blitz Web Browser",100,100,500,500,0,35)
  43.  
  44. agent=CreateAgent(0,0,0,0,win)
  45. SetGadgetLayout agent,1,1,1,1
  46.  
  47. timer=CreateTimer(1.0/6)        ;10 secs?
  48.  
  49. Repeat
  50.         id = WaitEvent()
  51.                 If id=$4001 AgentSpeak agent,"The time is "+CurrentTime$()
  52.         If id=$803 Then Exit
  53. Forever
  54.  
  55. End


Comments :


Smokey(Posted 1+ years ago)

 nice work ;)does this code work also with bmax? or could you adapt it to bmax ?


skidracer(Posted 1+ years ago)

 here is blitzmax/maxgui version:
Code: [Select]

Strict

Import maxgui.drivers

Local win:TGadget
Local agent:TGadget
Local timer:TTimer
Local id

win=CreateWindow("MaxGui Window",100,100,500,500,Null,35)

agent=CreateAgent(0,0,0,0,win)

SetGadgetLayout agent,1,1,1,1
timer=CreateTimer(1.0/6) '10 secs?
Repeat
id = WaitEvent()
If id=$4001 AgentSpeak agent,"The time is "+CurrentTime$()
If id=$803 Then Exit
Forever

End



Function CreateAgent:TGadget(x,y,w,h,group:TGadget)
' read script from data
RestoreData AgentScript
Return ReadObject(x,y,w,h,group)
End Function

Function AgentSpeak(agent:TGadget,message$)
HtmlViewRun agent,"Merlin.Speak('"+message$+"')"
End Function


#AgentScript
DefData "var AgentControl=new ActiveXObject('Agent.Control')"
DefData "AgentControl.Connected=true"
DefData "AgentControl.Characters.Load('Merlin')" ',"http://agent.microsoft.com//agent2//chars//merlin//merlin.acf")'
DefData "var Merlin = AgentControl.Characters.Character('Merlin')"
DefData "Merlin.LanguageID=0x0409"
DefData "Merlin.MoveTo(200,200)"
DefData "Merlin.Show()"
DefData "Merlin.Speak('YO!')"
DefData ""

' generic activex object in an htmlview container

Function ReadObject:TGadget(x,y,w,h,group:TGadget)
' read script from data restore point
Local script$,s$
Local shell:TGadget
Local id

While True
ReadData s$
If s$="" Exit
' s$=Replace$(s$,"'",Chr$(34))
If script$<>"" script$=script$+Chr$(13)+Chr$(10)
script$=script$+s$
Wend

DebugLog script
' Create a gadget To run our Object

shell=CreateHTMLView(x,y,w,h,group,2)
While True
id=WaitEvent()
DebugLog id
If id=EVENT_GADGETDONE Exit
Wend

HtmlViewRun shell,script$

Return shell
End Function



 

SimplePortal 2.3.6 © 2008-2014, SimplePortal