Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Acting on Website elements in a Tabbed Dialog WebBrowser
#1
Hi Gintaras,
I have been using the tabbed webbrowser dialog successfully as a multi-tabbed search engine. Many websites display how they handle their search queries in their URL e.g. searching for "brain tumor" in wikipedia, I just format the URL str as "http://en.wikipedia.org/wiki/brain_tumor" for other sites it is Url Escaped as brain+tumor or brain%20tumor, etc.... whatever works!
However, there are other websites, where the URL search query modification to the website is hidden. In those cases, I would like to wait for the search box element to appear, set the text and click the search button, or hit 'Y return. However, the behaviour of the ActiveX control is to actually not display the main webpage but wait the number of seconds of my wait statement and then err out. See example below. I have even tried doing it as a separate function triggered by the appearance of the web page but I get the same behaviour. Is there any way around this?
Thanks!!! (as always), Stuart

Function dlg_simple_web_browser
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x10CB0A40 0x100 0 0 507 522 ""
;3 SysTabControl32 0x56080240 0x0 2 40 506 642 ""
;77 Button 0x54032000 0x0 542 690 24 14 ">>|"
;6 Button 0x54032000 0x0 456 6 48 30 "Close"
;END DIALOG
;DIALOG EDITOR: "" 0x2030208 "" "" ""

if(!ShowDialog("dlg_simple_web_browser" &dlg_simple_web_browser)) ret
ret
;messages
sel message
,case WM_INITDIALOG
,SHDocVw.WebBrowser c
,int+ htbJB=id(3 hDlg)    
,TCITEM ti.mask=WINAPI.TCIF_TEXT
,ti.pszText="Google"
,SendMessage htbJB WINAPI.TCM_INSERTITEMA 0 &ti
,ti.pszText="Yahoo"
,SendMessage htbJB WINAPI.TCM_INSERTITEMA 1 &ti
,ti.pszText="QuickMacros.Com"
,SendMessage htbJB WINAPI.TCM_INSERTITEMA 2 &ti
,SelectTab htbJB 2 ;;none
,goto g11
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
c._getcontrol(id(3 hDlg))
sel wParam
,case 5 ;;Go
,str a.getwintext(id(4 hDlg))
,c.Navigate(a); err
,
,case 6
,c.GoBack; err

,case IDOK
,but 5 hDlg ;;on Enter press GO
,ret 0 ;;disable closing on Enter
,case IDCANCEL
,ifk(Z) ret 0 ;;disable closing on Esc
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.code
,case WINAPI.TCN_SELCHANGE
,_i=SendMessage(nh.hwndFrom WINAPI.TCM_GETCURSEL 0 0)
,out _i
,int htb=id(3 hDlg)
,RECT rct; GetClientRect htb &rct
,SendMessage htb TCM_ADJUSTRECT 0 &rct
,MapWindowPoints htb hDlg +&rct 2
,int t=CreateControl(0 "ActiveX" "SHDocVw.WebBrowser" 0 rct.left rct.top rct.right-rct.left rct.bottom-rct.top hDlg 100+3)
,BringWindowToTop t
,sel _i
,,case 0;
,,,_s="http://www.google.com";
,,,_s.setwintext(t)
,,,Htm GoogleSearchField=htm("INPUT" "q" "" hDlg 0 2 0x221 3)
,,,GoogleSearchField.SetText("Sample Search")
,,,Htm GoogleSearchButton=htm("INPUT" "Google Search" "" hDlg 0 3 0x421)
,,,GoogleSearchButton.Click            
,,case 1; _s="http://www.yahoo.com"; _s.setwintext(t)
,,case 2; _s="http://www.quickmacros.com"; _s.setwintext(t)
,;g11
,DT_Page hDlg _i
#2
Function dlg_simple_web_browser2
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x10CB0A40 0x100 0 0 507 522 ""
;3 SysTabControl32 0x56080240 0x0 2 40 506 642 ""
;77 Button 0x54032000 0x0 542 690 24 14 ">>|"
;6 Button 0x54032000 0x0 456 6 48 30 "Close"
;END DIALOG
;DIALOG EDITOR: "" 0x2030208 "" "" ""

if(!ShowDialog("dlg_simple_web_browser2" &dlg_simple_web_browser2)) ret
ret
;messages
SHDocVw.WebBrowser c
sel message
,case WM_INITDIALOG
,int htbJB=id(3 hDlg)
,TCITEM ti.mask=WINAPI.TCIF_TEXT
,ti.pszText="Google"
,SendMessage htbJB WINAPI.TCM_INSERTITEMA 0 &ti
,ti.pszText="Yahoo"
,SendMessage htbJB WINAPI.TCM_INSERTITEMA 1 &ti
,ti.pszText="QuickMacros.Com"
,SendMessage htbJB WINAPI.TCM_INSERTITEMA 2 &ti
,SelectTab htbJB 2 ;;none
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
c._getcontrol(child("" "ActiveX" hDlg)); err
sel wParam
,case 5 ;;Go
,str a.getwintext(id(4 hDlg))
,c.Navigate(a); err
,
,case 6
,c.GoBack; err

,case IDOK
,but 5 hDlg ;;on Enter press GO
,ret 0 ;;disable closing on Enter
,case IDCANCEL
,ifk(Z) ret 0 ;;disable closing on Esc
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.code
,case WINAPI.TCN_SELCHANGE
,int htb=nh.hwndFrom
,int iTab=SendMessage(htb TCM_GETCURSEL 0 0)
,RECT rct; GetClientRect htb &rct; SendMessage htb TCM_ADJUSTRECT 0 &rct; MapWindowPoints htb hDlg +&rct 2
,int ctrlId=iTab*100+1000 ;;this id will work with DT_Page
,int isNewTab t=id(ctrlId hDlg)
,if(!t) t=CreateControl(0 "ActiveX" "SHDocVw.WebBrowser" 0 rct.left rct.top rct.right-rct.left rct.bottom-rct.top hDlg ctrlId); isNewTab=1
,DT_Page hDlg iTab
,BringWindowToTop t
,if isNewTab
,,str urls=
,,;http://www.google.com
,,;http://www.yahoo.com
,,;http://www.quickmacros.com
,,str url.getl(urls iTab)
,,url.setwintext(t)
,sel iTab
,,case 0;
,,opt waitmsg 1 ;;always use this in dialogs before a wait function
,,Htm GoogleSearchField=htm("INPUT" "q" "" t 0 2 0x221 3)
,,GoogleSearchField.SetText("Sample Search")
,,Htm GoogleSearchButton=htm("INPUT" "btnG" "" t 0 3 0x221 3)
,,GoogleSearchButton.Click
#3
Thanks! Works great.
Stuart


Forum Jump:


Users browsing this thread: 1 Guest(s)