COMatePLUS version 1.2

Developed or developing a new product in PureBasic? Tell the world about it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

besko wrote:Srod The Best :)

If you post more examples for web :) it would be cool
I'm sure it would, but producing examples for using COMatePLUS is not really my job as I see it. I do what I can and what time allows me to do, but at the end of the day I cannot possibly envisage every possible use to which COMatePLUS may be put and to then construct suitable examples etc. That would be a fulltime job in itself!

If you have a specific request then post it. I'm sure someone already has code to do what you are after or can quickly knock up some code for you.

By the way Besko, I may well address the threading issue for the next update and allow COM objects created in one thread to be marshalled for use in another thread etc. Will avoid you having to use that timer instead.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Update - 4th Mayl 2009.

Version 1.0.4.

COMatePLUS version 1.0.4 makes a slight alteration to event handlers in that a global handler (\SetEventHandler(#COMate_CatchAllEvents,...)) can now return values through the #COMate_OtherReturn flag. That is, you can specify that your global handler be geared up for returning values through a variant structure which is passed to your handler etc.

This was motivated by a new web demo which essentially shows how to use COMatePLUS to validate HTML form data without any Javascript etc. This demo will be posted in the tips-and-tricks section as well.

See the nxSoftware site for the download.
I may look like a mule, but I'm not a complete ass.
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post by besko »

How to block with COMmate Plus new popup windows when i click on the links in webGadget?

i have old code :

Code: Select all

Procedure NewWindow2(*THIS.DispatchObject, *ppDisp.LONG, *Cancel.LONG)
  Debug "----------------------------------------------"
  Debug "NewWindow2"
  Debug "Blocking status: " + Str(WindowBlockerEnabled)
  
  Protected connectionPointContainer.IConnectionPointContainer
  Protected connectionPoint.IConnectionPoint, Cookie
  
  If WindowBlockerEnabled = 1
    Protected X.l, Y.l, Width.l, Height.l, ID.l, Disp.l
    
    ; Receives current WebGadget coordinates
    X = GadgetX(*THIS\GadgetID)
    Y = GadgetY(*THIS\GadgetID)
    Width = GadgetWidth(*THIS\GadgetID)
    Height = GadgetHeight(*THIS\GadgetID)
    
    ; Hides current WebGadget
    HideGadget(*THIS\GadgetID, 1)
    
    ; Creates new WebGadget with coordinates received
    ; OpenGadgetList(0,0)
    BrowserID = WebGadget(#PB_Any, X, Y, Width, Height, "About:Blank")
    
    Delay(150)
    
    ; CloseGadgetList()
    SetGadgetAttribute(BrowserID, #PB_Web_NavigationCallback, @WebGadgetCallback())
    ; Recovers IWebBrowser2 interface of the new WebGadget
    WebBrowser.IWebBrowser2 = GetWindowLong_(GadgetID(BrowserID), #GWL_USERDATA)
    ; Recovers Idispatch interface
    Webbrowser\Get_Application(@Disp)
    
    ; It affects the interface Idispactch of created WebGadget the setting * ppDisp
    *ppDisp\l = Disp
    
    ; It destroys the current element
    DeleteElement(DispatchObject())
    
    ; It destroys the former WebGadget
    FreeGadget(*THIS\GadgetID)
    
    ; It adds to the list the new WebGadget
    AddElement(DispatchObject())
    DispatchObject()\IDispatch = ?dispatchFunctions
    DispatchObject()\GadgetID = BrowserID
    
    ; Create On a point of connection To the IDispatch interface
    WebBrowser\QueryInterface(?IID_IConnectionPointContainer, @connectionPointContainer.IConnectionPointContainer)
    connectionPointContainer\findconnectionpoint(?IID_DWebBrowserEvents2, @connectionPoint.IConnectionPoint)
    connectionPoint\Advise(DispatchObject(), @Cookie)
    connectionPoint\release()
    connectionPointContainer\release()
  EndIf
EndProcedure
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Well, as far as I can see your code will not do much of anything! Not sure how exactly it prevents popups from showing?

Why not use a Purebasic navigation callback?

Anyhow, the following COMatePLUS code is a quick hack and prevents the web-gadget from displaying any additional window's; pop-ups or other!

If you want more control over the pop-ups (e.g. decide which links to allow etc.) then switch my use of the 'NewWindow2' event for 'NewWindow3' and read up on this event! :wink:

Code: Select all

IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"

Define browser.COMateObject


;-BROWSER CALLBACK.

;/////////////////////////////////////////////////////////////////////////////////
;The following is the event procedure for our browser object.
;We use this in order to prevent new windows being opened from our web-gadget.
Procedure BrowserEventProc(Object.COMateObject, eventName$, parameterCount) 
  Protected *ptrBoolean.WORD
  If eventName$ = "NewWindow2"
    ;The second parameter for this event is a boolean passed by reference which we simply set to #True to cancel the navigation.
      If Object\IsEventParamPassedByRef(2, @*ptrBoolean)
        ;Cancel the navigation.
          *ptrBoolean\w = #VARIANT_TRUE
      EndIf
  EndIf
EndProcedure 
;/////////////////////////////////////////////////////////////////////////////////


URL$ = "http://www.mathsguru.co.uk" ;Try clicking the 'Acrobat reader' link which would normally open a new window.

#WebGadget = 0

If OpenWindow(0, 0, 0, 800, 600, "WebGadget - cancel pop-ups", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  WebGadget(#WebGadget, 0, 0, WindowWidth(0),WindowHeight(0), URL$) 
  browser = COMate_WrapCOMObject(GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA)) 
  If browser
    ;Set the 'global' event handler for the browser object.
    ;We wish to trap the "NewWindow2" event which means that we must use the DWebBrowserEvents2 out-going interface.
    ;In order to over-ride COMatePLUS' selection of 'connection point' we pass a pointer to the IID of the DWebBrowserEvents2 out-going interface
    ;within the second optional parameter.
      If COMate_GetIIDFromName("DWebBrowserEvents2", @iid.IID) = #S_OK
        browser\SetEventHandler(#COMate_CatchAllEvents, @BrowserEventProc(), 0, iid)
      Else
        MessageRequester("COMatePLUS -web demo", "IID for the DWebBrowserEvents2 interface was not found on this system!" + #CRLF$ + #CRLF$ + "Please contact the author of COMatePLUS.")     
      EndIf

    Repeat 
      Event = WaitWindowEvent(); 
      Select Event 
        Case #PB_Event_CloseWindow 
          Break 
      EndSelect 
    ForEver 
    browser\Release()
  Else
    MessageRequester("COMatePLUS - cancel pop-ups demo", "Couldn't create the browser object!")
  EndIf
EndIf  
I may look like a mule, but I'm not a complete ass.
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post by besko »

when i click on the 'Acrobat reader' link nothing happen :)

i want to prevent open IE windows not in webgadget, when i click on links.

Your example works but not with all links hmmm

I have IE v 8.

Srod try to enter with this example in gmail acc and click on links in some emails :)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Works okay here with all pages I have tested with.

It would help if you provided me with a concrete URL in which the code fails.
I may look like a mule, but I'm not a complete ass.
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post by besko »

you test with Gmail?

and what heppen when you click on 'Acrobat reader' link?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I don't use gmail.

When I click the Acrobat reader link it does not open a new window - which is what is supposed to happen!

Without the code, clicking the link would open a new window with the Acrobat reader main page in it! I was just demonstrating how to use COMatePLUS to prevent these new windows from appearing which is what I thought you wanted?
I may look like a mule, but I'm not a complete ass.
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post by besko »

I have webgadget browser, without preventing code in some pages if i click they open in native IE browser not in my webgadget :)

i want to prevent this and all pages must open only in webgadget window.

huh :) english not my native language sorry :)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You want all links to open in a new web-gadget rather than a new instance of Internet Explorer?
I may look like a mule, but I'm not a complete ass.
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post by besko »

Not new, in same web gadget, but not in IE browser window
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Is this what you are after?

Code: Select all

IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"

Define browser.COMateObject

URL$ = "http://www.mathsguru.co.uk" ;Try clicking the 'Acrobat reader' link which would normally open a new window.

#WebGadget = 0


;-BROWSER CALLBACK.

;/////////////////////////////////////////////////////////////////////////////////
;The following is the event procedure for our browser object.
;We use this in order to prevent new windows being opened from our web-gadget.
Procedure BrowserEventProc(Object.COMateObject, eventName$, parameterCount) 
  Protected *ptrBoolean.WORD
  If eventName$ = "NewWindow3"
    ;The second parameter for this event is a boolean passed by reference which we simply set to #True to cancel the navigation.
      If Object\IsEventParamPassedByRef(2, @*ptrBoolean)
        ;Cancel the navigation.
          *ptrBoolean\w = #VARIANT_TRUE
        SetGadgetText(#WebGadget, Object\GetStringEventParam(5))
      EndIf
  EndIf
EndProcedure 
;/////////////////////////////////////////////////////////////////////////////////


If OpenWindow(0, 0, 0, 800, 600, "WebGadget - cancel pop-ups", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  WebGadget(#WebGadget, 0, 0, WindowWidth(0),WindowHeight(0), URL$) 
  browser = COMate_WrapCOMObject(GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA)) 
  If browser
    ;Set the 'global' event handler for the browser object.
    ;We wish to trap the "NewWindow3" event which means that we must use the DWebBrowserEvents2 out-going interface.
    ;In order to over-ride COMatePLUS' selection of 'connection point' we pass a pointer to the IID of the DWebBrowserEvents2 out-going interface
    ;within the second optional parameter.
      If COMate_GetIIDFromName("DWebBrowserEvents2", @iid.IID) = #S_OK
        browser\SetEventHandler(#COMate_CatchAllEvents, @BrowserEventProc(), 0, iid)
      Else
        MessageRequester("COMatePLUS -web demo", "IID for the DWebBrowserEvents2 interface was not found on this system!" + #CRLF$ + #CRLF$ + "Please contact the author of COMatePLUS.")     
      EndIf

    Repeat 
      Event = WaitWindowEvent(); 
      Select Event 
        Case #PB_Event_CloseWindow 
          Break 
      EndSelect 
    ForEver 
    browser\Release()
  Else
    MessageRequester("COMatePLUS - cancel pop-ups demo", "Couldn't create the browser object!")
  EndIf
EndIf  
If this doesn't work with all websites then there will not be much I can do.
I may look like a mule, but I'm not a complete ass.
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post by besko »

Tnx maybe its what i need. I will test.

Are ComMate Plus can work with Mozilla Com+?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

It can work with any ActiveX control.
I may look like a mule, but I'm not a complete ass.
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post by besko »

Can be this done in PB with ComMate Plus?

Spoofing the Referrer

Code: Select all

Function FetchURL(SomeURL as String) as String
Dim WebResp as HTTPWebresponse
Dim HTTPGetRequest as HttpWebRequest
Dim sr As StreamReader
dim myString as String

HTTPGetRequest = WebRequestFactory.Create(SomeURL)
HTTPGetRequest.KeepAlive = false
HTTPGetRequest.Referer = "http://www.microsoft.com"
WebResp = HTTPGetRequest.GetResponse()
sr = new StreamReader(WebResp.GetResponseStream(), Encoding.ASCII)
myString = sr.ReadToEnd()

Return myString
End Function

Dim PageString As String
PageString = FetchURL("http://www.google.com/","http://www.microsoft.com")
:roll: Srod ? :roll:
Post Reply