Announcement

Collapse
No announcement yet.

José Roca's WebBrowser wrapper functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #21
    nice, jose!

    see a simpler alternative here:


    the last post in the thread uses your original web browser wrapper,
    and launches a local httpd that the ajax example html can talk to.

    currently uses tinyweb, but should be able to put together a simple
    pb httpd with cgi support using erik olsen's and other examples.
    the httpd will need to bind only to localhost for security (already modified
    erik's code to do this, but need to add cgi support and remove the gui)



    ------------------

    Comment


      #22
      Hi Chuck,

      I'm following with great interest your Ajax examples.

      With the new compilers an small modification is needed:

      Code:
      ' ********************************************************************************************
      ' The IUnknown::AddRef method increments the reference count for an interface on an object. It
      ' should be called for every new copy of a pointer to an interface on a given object.
      ' ********************************************************************************************
      FUNCTION IUnknown_AddRef (BYVAL pthis AS DWORD PTR) AS DWORD
          LOCAL DWRESULT AS LONG
          IF ISFALSE pthis THEN EXIT FUNCTION
          CALL DWORD @@pthis[1] USING IUnknown_AddRef(pthis) TO DWRESULT
          FUNCTION = DWRESULT
      END FUNCTION
      ' ********************************************************************************************
      
      ' *********************************************************************************************
      ' Puts the address of an object in a variant and marks it as containing a dispatch variable
      ' *********************************************************************************************
      SUB AtlMakeDispatch (BYVAL lpObj AS DWORD, BYREF vObj AS VARIANT) EXPORT
         LOCAL lpvObj AS VARIANTAPI PTR                 ' Pointer to a VARIANTAPI structure
         LET vObj = EMPTY                               ' Make sure is empty to avoid memory leaks
         lpvObj = VARPTR(vObj)                          ' Get the VARIANT address
         @lpvObj.vt = %VT_DISPATCH                      ' Mark it as containing a dispatch variable
         @lpvObj.vd.pdispVal = lpObj                    ' Set the dispatch pointer address
         IUnknown_AddRef lpObj                          ' Increment the reference counter
      END SUB
      ' *********************************************************************************************
      This is because the new compilers correctly call Release when the
      variant goes out of scope or you assign to them a new value, so we
      must call AddRef to balance the reference count or we risk a GPF.
      I have been unable to modify my original post because I changed my
      password.

      Besides, AtlAxWinTerm is not really needed because Windows unregisters
      the ATL classes when the application ends if you don't do it.

      What I'm exploring is interaction with the loaded html page so it can be
      used to several purposes like GUIs, splash screens, help pages, reports, etc.,
      not only for internet related applications.

      For this purpose I have to use both interfaces derived from IDispatch
      and interfaces derived from IUnknown, so I prefer to use wrappers that
      having to mix PB Automation and direct VTable calls.


      ------------------
      Forum: http://www.jose.it-berater.org/smfforum/index.php

      Comment


        #23
        Jose,

        Thanks, I'll see if the changes work in the 7.0x compiler. I haven't
        upgraded, since I really only use PB as a hobby (although I have
        written a couple of utils with it for work). I'm not really interested
        in the new graphics stuff, so will need a really good reason to
        spend $$$ to upgrade, especially with all the free languages out
        there to play with (check out the Ruby on Rails framework).

        I do understand what you're doing with the browser integration,
        I did something similar a few years back in VB6 when the browser control
        first came out. Don't remember what the project was, but it turned
        out to be impractical, and we went for a standard VB6 app. Mostly,
        I think, it didn't fit well in an MVC (Model-View-Controller)
        architecture, which requires seperation of presentation and business
        logic for code maintainability.

        If I find the time, I would like to play with writing a simple
        httpd that can load DLLs on demand, vs. CGI EXEs. The advantage
        would be not only performance, but the ability to persist things
        like database connections, instead of having to start them up with
        every client connection. CGI isn't used much anymore by enterprise
        apps, which all use application servers in frameworks to handle all
        the session management and database connetivity, etc.


        ------------------

        Comment


          #24
          If you use the debugger at all, you will find the upgrade worthwhile.
          The debugger is now fully integrated into the IDE. You can put in
          breakpoints in edit mode as well as debug mode, in any file loaded.
          Debugging is also much faster to start, exit, and animate, can stop
          as soon as an error is detected, is much better at putting the "run"
          location at the actual stop address even in unusual crash conditions,
          and on and on... plus, moveable register and watch windows, the
          ability to watch variables of indefinite size, support for threads
          and SHELLs, and on and on.

          The IDE is also vastly improved, with the ability to add your own
          custom help files and program templates, bookmarks, block indent/
          outdent/comment, and the option of a full-time output window with
          compiler results and so forth. It'll compile main modules instead
          of include files (e.g., .BAS takes preference to .INC), so you don't
          have to worry so much about which window is active. There are new
          Print and file history buttons, the option to wrap the caret at line
          ends and beginnings, tab compression for smaller and more portable
          source code, new color options, and much more. Right-click on an
          error message for more information. Copy the whole output window to
          the clipboard.

          Not to forget all the new compiler keywords. Awesome graphics and
          printing support, new forward and reverse string manipulation,
          TCP/UDP universal broadcast, fast virtual pointer support, FIELD
          and THREADED variables, bit types, binary operations, better error
          checking, new metacommands, better MACROs... and, if you're porting
          from DOS, you have a whole new list of compatible keywords in PB/CC.

          Could be I'm biased but, I think, if you liked earlier versions,
          you'll go nuts about PB/CC 4 and PB/Win 8. We've addressed a huge
          selection of user requests and added our own special twists. You
          will be happy with the results.

          ------------------
          Tom Hanlin, PowerBASIC Staff
          Opinions expressed may not be those of my employer or myself

          Comment


            #25
            I've noticed that the keyboard doesn't seem to work on webpages (such as filling out a form, or tabbing to controls, and pressing enter). Any idea on how to fix that?

            ------------------

            Comment


              #26
              In IEWBEVT2.INC delete the line
              Code:
              #INCLUDE "IDHUIH.INC"          ' IDocHostUIHandler interface
              and in the sub DWebBrowserEvents2_DocumentComplete delete all these lines:
              Code:
              ' ======================================================================================
              ' After the MSHTML document has been loaded we retrieve a reference to his CustomDoc
              ' interface and give him a pointer to our IDocHostUIHandler interface to allow for
              ' customization.
              ' ======================================================================================
              
              LOCAL hr AS LONG
              LOCAL ppDoc AS DWORD
              LOCAL ppCustomDoc AS DWORD
              LOCAL IID_ICustomDoc AS GUID
              LOCAL ppDocHostUIHandler AS DWORD
              LOCAL IID_IDocHostUIHandler AS GUID
              
              ' Get a reference to the active document
              ppDoc = IWebBrowser2_GetDocument(pthis)
              IF ISFALSE ppDoc THEN EXIT SUB
              
              ' Get a reference to the CustomDoc interface
              IID_ICustomDoc = GUID$("{3050f3f0-98b5-11cf-bb82-00aa00bdce0b}")
              hr = DWebBrowserEvents2_IUnknown_QueryInterface(ppDoc, IID_ICustomDoc, ppCustomDoc)
              IF ISFALSE ppCustomDoc THEN EXIT SUB
              
              ' Get a reference to our IDocHostUIHandler interface
              IID_IDocHostUIHandler = $IID_IDocHostUIHandler
              hr = IDocHostUIHandler_QueryInterface (ppDoc, IID_IDocHostUIHandler, ppDocHostUIHandler)
              
              ' Set our IDocHostUIHandler interface for MSHTML
              IF ppDocHostUIHandler THEN ICustomDoc_SetUIHandler ppCustomDoc, ppDocHostUIHandler
              DWebBrowserEvents2_IUnknown_Release ppCustomDoc
              
              ' ======================================================================================
              This was added to show how to connect the page with the DocHostUIHandler
              interface, but the code inside this interface has not been fully developed
              yet and the keystrokes aren't forwarded to the container of the control.



              ------------------
              Website: http://com.it-berater.org
              SED Editor, TypeLib Browser, Wrappers for ADO, DAO, ODBC, MSXML, WMI, MSAGENT, Microsoft ActiveX Controls (Data Binding, ADODC, Flex Grid, Hierarchical Flex Grid, Masked Edit Control, DataList, DataCombo, MAPI, INET, MCI, Winsock, Common Dialog), Flash Player, Task Scheduler, Accesibility and Microsoft Scripting Components.
              Forum: http://www.jose.it-berater.org/smfforum/index.php

              Comment


                #27
                That did it! Thank you very much.


                ------------------

                Comment


                  #28
                  Jose! WOW!

                  Just experimenting a bit and trying to learn from your code,
                  I tried to use the simpliest case of the ZOOM command of the _ExecWb method,
                  within your minibrowser example. I had hoped a zoom dialog box
                  would magically appear. But nothing seems to happen.
                  Do you have any ideas how to make that work?

                  Thanks for all your contributions. Quite amazing!

                  John Reinking

                  Code:
                  FUNCTION Form1_Toolbar1_ZoomDlg _
                    ( _
                    BYVAL hWnd  AS DWORD _  ' handle of window that owns the menu
                    ) AS LONG
                  
                    LOCAL hCtrl  AS DWORD
                    LOCAL ppvObj AS DWORD
                    
                    ' Get the handle of the window that hosts the webbrowser
                    hCtrl = GetDlgItem(hWnd, %IDC_FORM1_WEBBROWSER1)
                    IF ISFALSE hCtrl THEN EXIT FUNCTION
                    
                    ' Get the IDispatch of the control
                    ppvObj = WbGetInterfacePointer(hCtrl)
                    IF ISFALSE ppvObj THEN EXIT FUNCTION
                    
                    ' Call the ExecWb method
                    IWebBrowser2_ExecWB ppvObj, %OLECMDID_ZOOM, %OLECMDEXECOPT_PROMPTUSER
                    
                    ' Release the interface
                    WbRelease ppvObj
                  
                  END FUNCTION
                  ------------------

                  Comment


                    #29
                    Internet Explorer has not a zoom dialog. Instead, it has a menu option
                    with five choices. Besides, it simply increases the size of the font, so
                    you won't see changes in some pages, as the PowerBasic home page, but
                    you will notice it in the forums page.

                    To retrieve the value of the font use:
                    Code:
                    LOCAL vOut AS VARIANT
                    IWebBrowser2_ExecWB ppvObj, %OLECMDID_ZOOM, %OLECMDEXECOPT_DONTPROMPTUSER, BYVAL %NULL, vOut
                    MSGBOX "Font size = " & STR$(VARIANT#(vOut))
                    To set the size of the font use:
                    Code:
                    LOCAL vIn AS VARIANT
                    vIn = 4 AS LONG   ' Big font
                    IWebBrowser2_ExecWB ppvObj, %OLECMDID_ZOOM, %OLECMDEXECOPT_DONTPROMPTUSER, vIn
                    Please don't forget the AS LONG in the vIn assignment, since PB defaults
                    to single.


                    ------------------
                    Website: http://com.it-berater.org
                    SED Editor, TypeLib Browser, Wrappers for ADO, DAO, ODBC, CDOEX, MSXML, WMI, MSAGENT, Flash Player, Task Scheduler, Accesibility, Structured Storage, WinHTTP, Microsoft ActiveX Controls (Data Binding, ADODC, Flex Grid, Hierarchical Flex Grid, Masked Edit Control, DataList, DataCombo, MAPI, INET, MCI, Winsock, Common Dialog, MSChart, Outlook View Control), and Microsoft Scripting Components.
                    Forum: http://www.jose.it-berater.org/smfforum/index.php

                    Comment


                      #30
                      Yep! That's it.

                      Here's _ZoomUp and _ZoomDn.

                      Many Thanks!

                      John Reinking

                      Code:
                      ' ========================================================================================
                      ' PROCEDURE: Form1_Toolbar1_ZoomUp
                      ' PURPOSE:   Increase the font size
                      ' RETURN:    TRUE if message was processed, FALSE if it was not.
                      ' ========================================================================================
                      
                      FUNCTION Form1_Toolbar1_ZoomUp _
                        ( _
                        BYVAL hWnd  AS DWORD _  ' handle of window that owns the menu
                        ) AS LONG
                        
                         LOCAL hCtrl  AS DWORD
                         LOCAL ppvObj AS DWORD
                        
                         ' Get the handle of the window that hosts the webbrowser
                         hCtrl = GetDlgItem(hWnd, %IDC_FORM1_WEBBROWSER1)
                         IF ISFALSE hCtrl THEN EXIT FUNCTION
                        
                         ' Get the IDispatch of the control
                         ppvObj = WbGetInterfacePointer(hCtrl)
                         IF ISFALSE ppvObj THEN EXIT FUNCTION
                        
                         LOCAL vOut AS VARIANT
                         LOCAL vIn AS VARIANT
                         LOCAL lState&, lRange&
                         
                         ' Call the ExecWb method to GET the current font zoom scale
                         IWebBrowser2_ExecWB ppvObj, %OLECMDID_ZOOM, %OLECMDEXECOPT_DONTPROMPTUSER, BYVAL %null, vOut
                         lState&=VARIANT#(vOut)
                      
                         ' Call the ExecWb method to get the upper limit of zoom range, although it seems to be 0-4.
                         IWebBrowser2_ExecWB ppvObj, %OLECMDID_GETZOOMRANGE, %OLECMDEXECOPT_DONTPROMPTUSER, BYVAL %null, vOut
                         lRange&=VARIANT#(vOut)
                         IF lState&<lRange& THEN INCR lState& ELSE lState&=lRange&
                        
                      
                         ' Call the ExecWb method to SET the new font zoom scale
                         vIn = lState& AS LONG   ' The 'AS LONG' part is important!
                         IWebBrowser2_ExecWB ppvObj, %OLECMDID_ZOOM, %OLECMDEXECOPT_DONTPROMPTUSER, vIn
                      
                         ' Release the interfaces
                         IF ppvObj THEN WbRelease ppvObj
                      
                      END FUNCTION
                      
                      ' ========================================================================================
                      ' PROCEDURE: Form1_Toolbar1_ZoomDn
                      ' PURPOSE:   Decrease the font size
                      ' RETURN:    TRUE if message was processed, FALSE if it was not.
                      ' ========================================================================================
                      
                      FUNCTION Form1_Toolbar1_ZoomDn _
                        ( _
                        BYVAL hWnd  AS DWORD _  ' handle of window that owns the menu
                        ) AS LONG
                      
                         LOCAL hCtrl  AS DWORD
                         LOCAL ppvObj AS DWORD
                      
                         ' Get the handle of the window that hosts the webbrowser
                         hCtrl = GetDlgItem(hWnd, %IDC_FORM1_WEBBROWSER1)
                         IF ISFALSE hCtrl THEN EXIT FUNCTION
                      
                         ' Get the IDispatch of the control
                         ppvObj = WbGetInterfacePointer(hCtrl)
                         IF ISFALSE ppvObj THEN EXIT FUNCTION
                      
                         LOCAL vOut AS VARIANT
                         LOCAL vIn AS VARIANT
                         LOCAL lState&
                         
                         ' Call the ExecWb method to GET the current font zoom scale
                         IWebBrowser2_ExecWB ppvObj, %OLECMDID_ZOOM, %OLECMDEXECOPT_DONTPROMPTUSER, BYVAL %null, vOut
                         lState&=VARIANT#(vOut)
                         IF lState&>0 THEN DECR lState& ELSE lState&=0
                      
                         ' Call the ExecWb method to SET the new font zoom scale
                         vIn = lState& AS LONG   ' The 'AS LONG' part is important!
                         IWebBrowser2_ExecWB ppvObj, %OLECMDID_ZOOM, %OLECMDEXECOPT_DONTPROMPTUSER, vIn
                      
                         ' Release the interfaces
                         IF ppvObj THEN WbRelease ppvObj
                      
                      END FUNCTION
                      ------------------

                      Comment

                      Working...
                      X
                      😀
                      🥰
                      🤢
                      😎
                      😡
                      👍
                      👎