Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SHDocVw.WebBrowser with tabs
#20
Hi Gintaras,
Hope all is well! I still use QM to do amazing things everyday.
I was wondering if there is a good way to load up all the tabs at startup, so for the user they are pre-loaded when they go to that tab. For the example below, everything would load quickly at tab selection, but for some websites that is not the case. When I move up the control creation and navigate code up to WM_INITDIALOG, it does preload them, but there is an initial period where things look like they are going crazy, rapidly rotating through all the tabs. Then once everything is loaded, it settles down and behaves like I intend. Is there a better way to do this. Obviously, not good for user to see this. I can hide the tabs during that period but wondering if there is a better way. Also, if I have many many browser tabs, say ~30, it would be nice to now there progress in loading, i.e. when they are all done so I can unhide the controls. Or is this not the ideal way to work with this many tabs.
I also worry about resources of having so many separate ActiveX WebBrowsers - maybe there is a better way to achieve this.
Thanks,
S 


Function dlg_tabbed_web_browser_atstartup
Code:
Copy      Help
\Dialog_Editor

;Opens several web pages in tabs.
;Change the str pagesCSV=... below.

function# hDlg message wParam lParam
if(hDlg) goto messages

out
if(!ShowDialog("" &dlg_tabbed_web_browser_atstartup 0 0 0 0 0 0 0 0 0 "dlg_tabbed_web_browser2")) ret

;BEGIN DIALOG
;0 "" 0x10CF0A48 0x100 0 0 433 265 "QM tabbed web browser"
;3 SysTabControl32 0x54000040 0x0 0 0 434 268 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030400 "" "" ""

ret
;messages

type TWB_TAB ~path ~name hwndwb
ARRAY(TWB_TAB)- ta
int- iTab
SHDocVw.WebBrowser wbDTWB2
int i htb
RECT rct

sel message
,case WM_INITDIALOG
,max hDlg
,;specify tabs in CSV format: title, URL.
,str pagesCSV=
,;QuickMacros, www.quickmacros.com
,;Forum, http://www.quickmacros.com/forum/index.php
,;General, http://www.quickmacros.com/forum/forumdisplay.php?fid=8
,;Programming, http://www.quickmacros.com/forum/forumdisplay.php?fid=9
,;Extensions, http://www.quickmacros.com/forum/forumdisplay.php?fid=14
,;My QM, http://www.quickmacros.com/forum/forumdisplay.php?fid=15
,;Computer World, http://www.quickmacros.com/forum/forumdisplay.php?fid=16
,;Wish List, http://www.quickmacros.com/forum/forumdisplay.php?fid=17
,;Bug Reports,http://www.quickmacros.com/forum/forumdisplay.php?fid=18
,;Post, http://ftp.quickmacros.com/forum/showthread.php?tid=6402&pid=31106
,;
,
,;add tabs
,ICsv csv=CreateCsv(1); csv.FromString(pagesCSV)
,htb=id(3 hDlg)
,TCITEMW ti.mask=TCIF_TEXT
,for i 0 csv.RowCount
,,TWB_TAB& r=ta[]
,,r.path=csv.Cell(i 1)
,,ti.pszText=@csv.Cell(i 0)
,,SendMessage htb TCM_INSERTITEMW i &ti
,,TabControlGetClientRect htb hDlg rct
,,r.hwndwb=CreateControl(0 "ActiveX" "SHDocVw.WebBrowser" 0 rct.left rct.top rct.right-rct.left rct.bottom-rct.top hDlg 100+i)
,,BringWindowToTop r.hwndwb
,,wbDTWB2._getcontrol(r.hwndwb)
,,wbDTWB2._setevents("wbDTWB2_DWebBrowserEvents2")
,,wbDTWB2.Navigate(r.path)
,,
,,
,,
,,
,,
,,;SelectTab htb i ;;none
,iTab=-1
,;SelectTab htb -1 ;;none
,SelectTab htb 0 ;;disable this line if don't want to load page now

,case WM_APP+1
,;A macro can send this message to select a tab and load a page.
,;wParam is tab index, lParam is URL; if lParam 0, just selects tab.
,;Returns current tab index (before changing).
,;Don't send from other process.
,;EXAMPLES
,;int w=win("QM tabbed web browser" "#32770")
,;SendMessage w WM_APP+1 2 0 ;;select tab 2
,;SendMessage w WM_APP+1 1 "www.quickmacros.com" ;;select tab 1 and load URL
,
,_i=iTab
,if wParam>=0 and wParam<ta.len
,,if(wParam!=iTab) SelectTab id(3 hDlg) wParam
,,if lParam
,,,lpstr URL=+lParam
,,,wbDTWB2._getcontrol(ta[wParam].hwndwb)
,,,wbDTWB2.Navigate(@URL)
,ret _i    
,
,
,case WM_DESTROY
,
,case WM_SIZE
,htb=id(3 hDlg)
,GetClientRect hDlg &rct; MoveWindow htb rct.left rct.top rct.right-rct.left rct.bottom-rct.top 1
,TabControlGetClientRect htb hDlg rct
,for(i 0 ta.len) if(ta[i].hwndwb) MoveWindow ta[i].hwndwb rct.left rct.top rct.right-rct.left rct.bottom-rct.top 0
,
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case [101,102,103,104]
,err-
,int hax=ta[iTab].hwndwb
,wbDTWB2._getcontrol(hax)
,sel wParam
,,case 101 wbDTWB2.GoBack
,,case 102 wbDTWB2.Refresh
,,case 103 wbDTWB2.Navigate(ta[iTab].path) ;;Home. Load the start page of this tab.
,,case 104 if(inp(_s "URL:" "Go to" "" 0 "" 0 hDlg)) wbDTWB2.Navigate(_s)
,err+
ret 1
;messages3
NMHDR* nh=+lParam
sel nh.code
,case TCN_SELCHANGE ;;a tab selected
,htb=nh.hwndFrom
,for(i 0 ta.len) if(ta[i].hwndwb) hid ta[i].hwndwb ;;hide all
,i=SendMessage(htb TCM_GETCURSEL 0 0); if(i<0 or i>=ta.len) ret
,iTab=i
,&r=ta[i]
,if(r.hwndwb)
,,hid- r.hwndwb ;;if the control already created, unhide
,,BringWindowToTop r.hwndwb
,else ;;create control and open document
,,TabControlGetClientRect htb hDlg rct
,,r.hwndwb=CreateControl(0 "ActiveX" "SHDocVw.WebBrowser" 0 rct.left rct.top rct.right-rct.left rct.bottom-rct.top hDlg 100+i)
,,BringWindowToTop r.hwndwb
,,wbDTWB2._getcontrol(r.hwndwb)
,,wbDTWB2._setevents("wbDTWB2_DWebBrowserEvents2")
,,wbDTWB2.Navigate(r.path)

;BEGIN MENU
;&Back : 101
;&Reload : 102
;&Home : 103
;&GoTo... :104
;END MENU


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)