April 28, 2024, 11:46:54 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


WebBroswer Control and the Silent Command

Started by Steven Picard, March 18, 2007, 08:21:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Steven Picard

March 18, 2007, 08:21:07 PM Last Edit: March 19, 2007, 08:24:07 AM by Steven Picard
The IE webbrowser has a property for it called "Silent".  This prevents scripting errors from popping up (as long as the debug feature is turned off in IE.)  Do you know how I can call this in EBasic?

Thanks,
Steven

sapero

To do this you need to implement IOleCommandTarget and handle the Exec method with OLECMDID_SHOWSCRIPTERROR flag.
The browser code is good docummented, so i was able to replace a method to extend the library. It was tested only in Aurora, my emergence limit is off :)
WINDOW win


OPENWINDOW win,0,0,800,600,@NOAUTODRAW|@SIZE|@MINBOX|@MAXBOX,0,"BROWSER TEST",&handler
if @IDYES = MessageBox(win,"disabe script errors?","",@MB_YESNO)
BrowserMakeSilent() ':' do it before ATTACHBROWSER
endif
ATTACHBROWSER(win)


BROWSECMD win,@BROWSELOAD,"<html><body><style>body {font-family: verdana; font-size: x-small}</style><table width=100% " + _
"height=100%><tr><td><center><b>A page with errors</b><br><br>This page calls not existing method document.bla" + _
"aahhh().</center></td></tr></table><script>document.blaaahhh();</script></body></html>"

WAITUNTIL win=0
END



SUB handler
if @message = @idcreate then CenterWindow(win)
if @message = @idclosewindow then CloseWindow(win)
RETURN
ENDSUB

'--------------------------------------------------------

type __VARIANT,2:word vt[4]: word boolVal:endtype
const OLECMDID_SHOWSCRIPTERROR = 40
const VARIANT_TRUE = -1
const E_NOINTERFACE = 0x80004002
const E_NOTIMPL = 0x80004001
const VT_BOOL = 11
declare import, WriteProcessMemory(h:int,b:pointer,p:pointer,l:int,w:pointer),int
declare import, GetCurrentProcess(),int
declare import, IsEqualGUID(riid1:GUID, riid2:GUID),int
extern _IID_IOleCommandTarget as GUID



class CCommandTarget
declare virtual QueryInterface(iid:GUID,ppvObject:pointer),int
declare virtual AddRef()
declare virtual Release()
declare virtual QueryStatus(pguidCmdGroup:GUID, cCmds:int,prgCmds:pointer, pCmdText:pointer),int
declare virtual Exec(pguidCmdGroup:GUID, nCmdID:int, nCmdexecopt:int, pvaIn:__VARIANT,pvaOut:__VARIANT),int
endclass


'----------------------------------------------------
' globals

CCommandTarget g_ccmdt ':' IOleCommandTarget manages special commands like OLECMDID_SHOWSCRIPTERROR
' the previous method
uint g_OriginalQueryInterface
declare t_OriginalQueryInterface(site:pointer,iid:GUID,ppvObject:pointer),int
declare CCommandTarget_vtable_()
extern _MyIOleInPlaceSiteTable as int ':' pointer to MyIOleInPlaceSite::QueryInterface


sub BrowserMakeSilent()
' initialize the global class
pointer temp
int myQuery
temp = &g_ccmdt
*<pointer>temp = &CCommandTarget_vtable_

myQuery = &BrowserQueryInterface
g_OriginalQueryInterface = _MyIOleInPlaceSiteTable ':' copy pointer to _Site_QueryInterface@12
WriteProcessMemory(GetCurrentProcess(), &_MyIOleInPlaceSiteTable, &myQuery, 4, NULL)
return
endsub



' replaceent for MyIOleInPlaceSite::QueryInterface, we need to extern supported objects
sub BrowserQueryInterface(site:pointer,iid:GUID,ppvObject:pointer),int

if (IsEqualGUID(iid, _IID_IOleCommandTarget))
*<pointer>ppvObject = &g_ccmdt
return 0
endif
return !<t_OriginalQueryInterface>g_OriginalQueryInterface(site, iid, ppvObject)
endsub

'--------------------------------------------------------
' CCommandTarget methods

sub CCommandTarget::QueryInterface(iid:GUID,ppvObject:pointer),int
return E_NOINTERFACE
endsub

sub CCommandTarget::AddRef()
return
endsub

sub CCommandTarget::QueryStatus(pguidCmdGroup:GUID, cCmds:int,prgCmds:pointer, pCmdText:pointer),int
return E_NOTIMPL
endsub

sub CCommandTarget::Release()
return
endsub

sub CCommandTarget::Exec(pguidCmdGroup:GUID, nCmdID:int, nCmdexecopt:int, pvaIn:__VARIANT,pvaOut:__VARIANT),int
if (nCmdID = OLECMDID_SHOWSCRIPTERROR)
pvaOut.boolVal = VARIANT_TRUE
pvaOut.vt = VT_BOOL
endif
return 0
endsub

Steven Picard

Perfect, Sapero!!  It worked and was exactly what I needed.  Thank you very much!!