Announcement

Collapse
No announcement yet.

YouTube Search (Embedded Browser)

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

  • YouTube Search (Embedded Browser)

    Jose,

    I noticed this evening that with an embedded browser I can type something into Google and get a valid search return

    But if I pull up YouTube on the embedded browser and do a Search, the results are not valid.

    Any idea what that might be happening?

  • #2
    You have to give to the control a correct address, i.e. https://www.youtube.com. The browser or Google use techniques of autocompletion to guess the correct addres.
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Howdy, Jose!

      I appreciate the response. Do you mean that when I YouTube showing in the embedded browser, I have to intercept the .beforenavigate2 event and substitute a new URL, one that the YouTube site recognizes, which is like this ...

      ... which I got from watching my default browser handle a Search for the word "test".

      There's lots of other stuff passing through beforenavigate2, so I did a test and captured all vURL content coming through once a search was started. But I did not find anything that I could recognize as coming from the Search button - something appropriate for me to change to the query format above.

      Did I understand your suggestion correctly?

      Comment


      • #4
        No. I mean that before calling the Navigate2 method you have to guess the correct address, that you will then pass to the control. The control is not going to guess anything. If you give an incorrect addres to it, it will fail to load the page.

        Internet Explorer uses the WebBrowser control to render the web page, but it does other many things not supported by the control.
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          Jose,

          So, from what you're saying, I need to ...

          1. intercept when the user presses Enter (when inputbox has focus) or presses the Search button - stop them from doing anything
          2. capture the Search term
          3. give the control the correct URL (as in post #3 above)

          I'm not sure I know how to do #1, perhaps #2. But with those in hand, #3 is easy enough to do. Looking at your template for CDWebBrowserEvents2, I don't see the event that lets me capture #1, much less return the value of #2.

          I'll have to give it some more thought. Thanks again for the guidance!


          Comment


          • #6
            > But if I pull up YouTube on the embedded browser and do a Search, the results are not valid.

            I'm confussed. Don't know what you exactly do mean. I thought that you meant passing to Navigate2 an incorrect address and expecting that the control will show a page with various addresses, as Google does. But now I don't know if you mean this or if you are doing the search in the YouTube page. If it is the latter option, it should display a YouTube web page with the results.
            Forum: http://www.jose.it-berater.org/smfforum/index.php

            Comment


            • #7
              Hi Jose!

              I'm sorry for not being more clear. Yes - the latter is correct. Within the embedded browser I am on the YouTube page and type in a Search term. But when I press Enter, the results have nothing to do with the Search term. The result is a YouTube page, just not with any videos related to the Search term.

              The code I'm using is the gbVideoLoop app I released a few days ago.

              For example, I type in "Santa Claus" into the Search box and pressed Enter. What appears to have happened is the YouTube.com page simply refreshed. There's nothing related to "Santa Claus" in the new/refreshed page.

              If I use an external browser, the Search returns expected results - lots of Santa Claus video links!

              Comment


              • #8
                It should work because the results are retrieved and displayed by the YouTube search engine, not the control. I have tried with MDIBrowser, one of my examples, and it works fine.

                I was going to attach a capture, but the forum says that I have exceded my upload quota. Seems that I'm not going to be able to upload anything anymore.
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment


                • #9
                  Jose,
                  Thanks for trying it out on your end. I'll start stripping out code until or if I can get a simple example to demonstrate the results.

                  ... just a moment ...

                  It worked fine in this next, very simple code. So, that should mean my gbVideoLoop code is doing something to mess things up. I'll go bleed off code until the offending code is obvious (I hope! )

                  Code:
                  #Compile Exe
                  #Dim All
                  %Unicode = 1
                  %UseWebBrowser = 1            ' // Use the WebBrowser control
                  #Include Once "CWindow.inc"   ' // CWindow class
                  %IDC_WebBrowser = 1001
                  Function PBMain
                     Local hDlg As Dword, pWindow As IWindow
                     Dialog New Pixels, 0, "WebBrowser", , , 1000, 800, %WS_OverlappedWindow To hDlg
                     pWindow = Class "CWindow"
                     pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, "http://www.youtube.com",Nothing, 0, 0, 1000,800)
                     Dialog Show Modal hDlg
                  End Function

                  Comment


                  • #10
                    Ok, I found the trouble.

                    In my code I have a textbox and I use %IDOK to detect when the users press Enter.in that textbox. In that case, the browser is sent to a URL.

                    It seems that %IDOK is also triggered when the user types something into the YouTube search term textbox and presses Enter. I expected the browser to own/eat the Enter, not the Dialog. Bad assumption on my part.

                    Easy to fix, now that I know what was going on.

                    Thanks again for the help in identifying what was going on.

                    Comment


                    • #11
                      Jose,

                      Well, that testing led to another interesting result.

                      In the embedded browser code of post #9, when I type something into the YouTube search term textbox, a dropdown list appears with suggested terms, as expected. But when I press Enter, the dropdown list does not disappear and a Search is not executed.

                      Could you confirm/deny that you're seeing that result as well?

                      Comment


                      • #12
                        O b e
                        Dale

                        Comment


                        • #13
                          With my example, it works fine. Your DDT modal dialog must be interfering. It must be because dialogs were designed to make auxiliary popup dialogs and catch the Enter key to push the "Ok" button even if it has not the focus. To fully control the Windows messages it is needed to use a modeless dialog (or a SDK window) and a message pump.
                          Forum: http://www.jose.it-berater.org/smfforum/index.php

                          Comment


                          • #14
                            Dale,
                            What does O b e mean? ... out of body experience? ...

                            Jose,
                            Thanks, I'll go test that out.

                            Comment


                            • #15
                              Overcome By Events

                              Your post 11 and a rethink, and I deleted what was there (for maybe 10 seconds) Forum software wants 2 o 3 letters or 2 or 3 words (I forget), or SAVE does not work.

                              That's all.

                              Cheers,
                              Dale

                              Comment


                              • #16
                                Jose,
                                Bummer, but the modeless idea did not work. Even with the message pump (code below), pressing enter in the YouTube search box does not close the dropdown list.

                                As much as I've used your embedded browser code, I'm surprised I've not seen this before. That's just how my day has been going!

                                Code:
                                #Compile Exe
                                #Dim All
                                %Unicode = 1
                                %UseWebBrowser = 1            ' // Use the WebBrowser control
                                #Include Once "CWindow.inc"   ' // CWindow class
                                %IDC_WebBrowser = 1001
                                Function PBMain
                                   Local hDlg As Dword, pWindow As IWindow, count&
                                   Dialog New Pixels, 0, "WebBrowser", , , 600, 400, %WS_OverlappedWindow To hDlg
                                   pWindow = Class "CWindow"
                                   pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, "http://www.youtube.com",Nothing, 0, 0, 600,400)
                                   Dialog Show Modeless hDlg, Call DlgProc
                                   Do
                                      Dialog DoEvents 0 To Count&
                                   Loop While Count&
                                End Function
                                CallBack Function DlgProc() As Long
                                End Function

                                Comment


                                • #17
                                  Don't ask me for workarounds for DDT dialogs because I don't have expertise with them. DDT is a black box in which I don't have the slightest interest.

                                  Here is a little example using my CWindow class. You will see that it works perfectly.

                                  Code:
                                  #COMPILE EXE
                                  #DIM ALL
                                  %UNICODE = 1
                                  
                                  ' // Include files for external files
                                  %USEWEBBROWSER = 1            ' // Use the WebBrowser control
                                  #INCLUDE ONCE "CWindow.inc"   ' // CWindow class
                                  
                                  ' // Identifier
                                  %IDC_WEBBROWSER = 101
                                  
                                  ' ########################################################################################
                                  ' Main
                                  ' ########################################################################################
                                  FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                                  
                                     ' // Create an instance of the class
                                     LOCAL pWindow AS IWindow
                                     pWindow = CLASS "CWindow"
                                     IF ISNOTHING(pWindow) THEN EXIT FUNCTION
                                  
                                     ' // Create the main window
                                     pWindow.CreateWindow(%NULL, "AddWebBrowser Template", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
                                     ' // Set the client siz
                                     pWindow.SetClientSize 600, 350
                                     ' // Center the window
                                     pWindow.CenterWindow
                                  
                                     ' // Add a WebBrowser control
                                     LOCAL hCtl AS DWORD
                                     LOCAL bstrURL AS WSTRING
                                  
                                     ' // You can pass a URL
                                     bstrURL = "http://www.youtube.com"
                                  
                                     ' // Create the control
                                     hCtl = pWindow.AddWebBrowserControl(pWindow.hwnd, %IDC_WEBBROWSER, bstrURL, NOTHING, 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
                                  
                                  
                                     ' // Default message pump (you can replace it with your own)
                                     FUNCTION = pWindow.DoEvents(nCmdShow)
                                  
                                  END FUNCTION
                                  ' ########################################################################################
                                  
                                  ' ========================================================================================
                                  ' Main callback function.
                                  ' ========================================================================================
                                  FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                                  
                                     STATIC pWindow AS IWindow        ' // Reference to the IWindow interface
                                  
                                     SELECT CASE uMsg
                                  
                                        CASE %WM_CREATE
                                           ' // Get a reference to the IWindow interface from the CREATESTRUCT structure
                                           pWindow = CWindow_GetObjectFromCreateStruct(lParam)
                                           EXIT FUNCTION
                                  
                                        CASE %WM_SYSCOMMAND
                                           ' // Capture this message and send a WM_CLOSE message
                                           ' // Note: Needed with some OCXs, that otherwise remain in memory
                                           IF (wParam AND &HFFF0) = %SC_CLOSE THEN
                                              SendMessage hwnd, %WM_CLOSE, 0, 0
                                              EXIT FUNCTION
                                           END IF
                                  
                                        CASE %WM_COMMAND
                                           SELECT CASE LO(WORD, wParam)
                                              CASE %IDCANCEL
                                                 ' // If the Escape key has been pressed...
                                                 IF HI(WORD, wParam) = %BN_CLICKED THEN
                                                    ' // ... close the application by sending a WM_CLOSE message
                                                    SendMessage hwnd, %WM_CLOSE, 0, 0
                                                    EXIT FUNCTION
                                                 END IF
                                           END SELECT
                                  
                                        CASE %WM_SIZE
                                           IF wParam <> %SIZE_MINIMIZED THEN
                                              ' // Resize the control
                                              pWindow.MoveWindow GetDlgItem(hwnd, %IDC_WEBBROWSER), 0, 0, pWindow.ClientWidth, pWindow.ClientHeight, %TRUE
                                           END IF
                                  
                                        CASE %WM_DESTROY
                                           ' // End the application
                                           PostQuitMessage 0
                                           EXIT FUNCTION
                                  
                                     END SELECT
                                  
                                     ' // Pass unprocessed messages to Windows
                                     FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
                                  
                                  END FUNCTION
                                  ' ========================================================================================
                                  Last edited by José Roca; 12 Jul 2017, 03:56 PM.
                                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                                  Comment


                                  • #18
                                    BTW when I said message pump I was thinking in a SDK message pump, not in DIALOG DOEVENTS.

                                    However, my attempt to use a SDK message pump with a DDT dialog also does not work. The DDT dialog engine must we doing something funky with the Enter key.

                                    This it my failed attempt to combine DDT and SDK.

                                    Code:
                                    #Compile Exe
                                    #Dim All
                                    %Unicode = 1
                                    %UseWebBrowser = 1            ' // Use the WebBrowser control
                                    #Include Once "CWindow.inc"   ' // CWindow class
                                    %IDC_WebBrowser = 1001
                                    %WM_FORWARDMSG = &H37F
                                    
                                    Function PBMain
                                       Local hDlg As Dword, pWindow As IWindow, count&
                                       Dialog New Pixels, 0, "WebBrowser", , , 600, 400, %WS_OverlappedWindow To hDlg
                                       pWindow = Class "CWindow"
                                       pWindow.AddWebBrowserControl(hDlg, %IDC_WEBBROWSER, "http://www.youtube.com",Nothing, 0, 0, 600,400)
                                       Dialog Show Modeless hDlg, Call DlgProc
                                    
                                       LOCAL uMsg AS tagMsg
                                       WHILE GetMessage(uMsg, %NULL, 0, 0)
                                          IF IsDialogMessage(hDlg, uMsg) = %FALSE THEN
                                             TranslateMessage uMsg
                                             DispatchMessage uMsg
                                          END IF
                                       WEND
                                    
                                    End Function
                                    
                                    
                                    CallBack Function DlgProc() As Long
                                      LOCAL rc AS RECT
                                    
                                       SELECT CASE CBMSG
                                    
                                          CASE %WM_SYSCOMMAND
                                             ' Capture this message and send a WM_DESTROY message
                                             ' or the program will remain in memory
                                             IF (cbwparam AND &HFFF0) = %SC_CLOSE THEN
                                                SendMessage cbhndl, %WM_DESTROY, cbwParam, cblParam
                                                EXIT FUNCTION
                                             END IF
                                    
                                          CASE %WM_DESTROY
                                             PostQuitMessage 0
                                             EXIT FUNCTION
                                    
                                          CASE %WM_COMMAND
                                             SELECT CASE CBCTL
                                                CASE %IDCANCEL
                                                   IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                      DIALOG END CBHNDL, 0
                                                   END IF
                                             END SELECT
                                    
                                       END SELECT
                                    
                                    END FUNCTION
                                    Forum: http://www.jose.it-berater.org/smfforum/index.php

                                    Comment


                                    • #19
                                      Just for fun. My CWindow example in a smaller version. Not bigger or more difficult that your DDT version, yet more powerful.

                                      Code:
                                      #COMPILE EXE
                                      #DIM ALL
                                      %UNICODE = 1
                                      
                                      ' // Include files for external files
                                      %USEWEBBROWSER = 1            ' // Use the WebBrowser control
                                      #INCLUDE ONCE "CWindow.inc"   ' // CWindow class
                                      
                                      ' // Identifier
                                      %IDC_WEBBROWSER = 101
                                      
                                      ' ########################################################################################
                                      ' Main
                                      ' ########################################################################################
                                      FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                                      
                                         ' // Create an instance of the class
                                         LOCAL pWindow AS IWindow
                                         pWindow = CLASS "CWindow"
                                         IF ISNOTHING(pWindow) THEN EXIT FUNCTION
                                      
                                         ' // Create the main window
                                         pWindow.CreateWindow(%NULL, "WebBrowser", 0, 0, 600, 400, 0, 0, CODEPTR(WindowProc))
                                         ' // Center the window
                                         pWindow.CenterWindow
                                      
                                         ' // Add a WebBrowser control
                                         pWindow.AddWebBrowserControl(pWindow.hwnd, %IDC_WEBBROWSER, "http://www.youtube.com", NOTHING, 0, 0, 600, 400)
                                      
                                         ' // Default message pump (you can replace it with your own)
                                         FUNCTION = pWindow.DoEvents(nCmdShow)
                                      
                                      END FUNCTION
                                      ' ########################################################################################
                                      
                                      ' ========================================================================================
                                      ' Main callback function.
                                      ' ========================================================================================
                                      FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                                      
                                         SELECT CASE uMsg
                                      
                                            CASE %WM_DESTROY
                                               ' // End the application
                                               PostQuitMessage 0
                                               EXIT FUNCTION
                                      
                                         END SELECT
                                      
                                         ' // Pass unprocessed messages to Windows
                                         FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
                                      
                                      END FUNCTION
                                      ' ========================================================================================
                                      And still more minimal, yet it works!

                                      Code:
                                      #COMPILE EXE
                                      #DIM ALL
                                      %UNICODE = 1
                                      
                                      ' // Include files for external files
                                      %USEWEBBROWSER = 1            ' // Use the WebBrowser control
                                      #INCLUDE ONCE "CWindow.inc"   ' // CWindow class
                                      
                                      ' // Identifier
                                      %IDC_WEBBROWSER = 101
                                      
                                      ' ########################################################################################
                                      ' Main
                                      ' ########################################################################################
                                      FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                                      
                                         ' // Create an instance of the class
                                         LOCAL pWindow AS IWindow
                                         pWindow = CLASS "CWindow"
                                         IF ISNOTHING(pWindow) THEN EXIT FUNCTION
                                      
                                         ' // Create the main window
                                         pWindow.CreateWindow(%NULL, "WebBrowser", 0, 0, 600, 400, 0, 0, %NULL)
                                         ' // Center the window
                                         pWindow.CenterWindow
                                      
                                         ' // Add a WebBrowser control
                                         pWindow.AddWebBrowserControl(pWindow.hwnd, %IDC_WEBBROWSER, "http://www.youtube.com", NOTHING, 0, 0, 600, 400)
                                      
                                         ' // Default message pump (you can replace it with your own)
                                         FUNCTION = pWindow.DoEvents(nCmdShow)
                                      
                                      END FUNCTION
                                      ' ########################################################################################
                                      Make yourself a favor and switch to SDK. Sorry, I could not resist!
                                      Last edited by José Roca; 12 Jul 2017, 06:19 PM.
                                      Forum: http://www.jose.it-berater.org/smfforum/index.php

                                      Comment


                                      • #20
                                        Howdy, Jose!

                                        ... switch to SDK.
                                        Yes, it's on my list but I just never seem to make the time to get it done! But I will, eventually. I'm only 65 and have lots of time, at least, that's the plan.

                                        I'm afraid that the "Squirrel!" joke applies to me - I'm way to easily distracted..

                                        Thanks for your suggestion and support!

                                        Comment

                                        Working...
                                        X