Code archives/BlitzPlus Gui/CreateAgent
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This code demonstrates control of an activex object using the new HTMLViewRun command. You get agents with Microsoft office or download them from http://www.microsoft.com/MSAgent note: BlitzMax/MaxGui code has been posted further below. | |||||
Function ReadObject(x,y,w,h,group) ; read script from data restore point script$="" While True Read s$ If s$="" Exit ; s$=Replace$(s$,"'",Chr$(34)) If script$<>"" script$=script$+Chr$(13)+Chr$(10) script$=script$+s$ Wend ; create a gadget to run our object shell=CreateHtmlView(x,y,w,h,group,2) While True id=WaitEvent() If id=$401 And EventSource()=shell And EventID=0 Exit Wend HtmlViewRun shell,script$ Return shell End Function Function CreateAgent(x,y,w,h,group) ; read script from data Restore AgentScript Return ReadObject(x,y,w,h,group) End Function Function AgentSpeak(agent,message$) HtmlViewRun agent,"Merlin.Speak('"+message$+"')" End Function .AgentScript Data "var AgentControl=new ActiveXObject('Agent.Control')" Data "AgentControl.Connected=true" Data "AgentControl.Characters.Load('Merlin')" ;,"http://agent.microsoft.com//agent2//chars//merlin//merlin.acf"); Data "var Merlin = AgentControl.Characters.Character('Merlin')" Data "Merlin.LanguageID=0x0409" Data "Merlin.MoveTo(200,200)" Data "Merlin.Show()" Data "Merlin.Speak('YO!')" Data "" win=CreateWindow("Basic Blitz Web Browser",100,100,500,500,0,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 |
Comments
| ||
nice work ;) does this code work also with bmax? or could you adapt it to bmax ? |
| ||
here is blitzmax/maxgui version: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 |
Code Archives Forum