Option Explicit '------------------------------------------ 'App: Internet Browser 'Created By: Laimonas Simutis 'Date : 2001 July ' 'Use and modify source code as you wish ' 'Uses WebBrowser control 'to enable internet browsing from this application. 'Basically, explorer engine is running in the background 'taking care of the hard work. This app might load faster 'than IE and doesn't seem to cause problems which 'explorer constantly did to my machine. '------------------------------------------ Dim objSource As frmSource 'frmSource instance Private strPageSource As String 'html code of a page Private strMail As String 'shortcut to an email website Private strGame As String 'shortcut to a game website Private strCollege As String 'shortcut to my college website Private intDrawPos As Integer 'start where progress line 'will be drawn Private blnProgress As Boolean 'show progress bar or not Private blnLog As Boolean 'log websites visited or not Private blnTimeLog As Boolean 'log time or not Dim strPrevSite As String 'for reducing the size of log file Private Sub cmbAd_Click() On Error GoTo er 'when the user clicks on one of the items in combo 'box cmbAd list, navigate to where this item points to. wb.Navigate cmbAd.Text wb.SetFocus Exit Sub er: MsgBox Err.Description & Err.Number End Sub Private Sub cmbAd_KeyPress(KeyAscii As Integer) On Error Resume Next 'checl if user press enter, and if yes, navigate to that page If cmbAd.Text = "" Then Exit Sub If KeyAscii = 13 Then cmbAd.AddItem cmbAd.Text wb.Navigate cmbAd.Text wb.SetFocus End If End Sub Private Sub cmdBack_Click() On Error Resume Next wb.GoBack wb.SetFocus End Sub Private Sub cmdFoward_Click() On Error Resume Next wb.GoForward wb.SetFocus End Sub Private Sub cmdRefresh_Click() On Error Resume Next wb.Refresh wb.SetFocus End Sub Private Sub cmdStop_Click() On Error Resume Next wb.Stop frmBrowser.Cls wb.SetFocus End Sub Private Sub Form_Load() On Error Resume Next Call QuickLaunch 'set quicklaunch shortcut values lblStat.Caption = "Ready" 'status change wb.Navigate App.Path & "\default.htm" 'page provided with 'application, and is set to appear first cmbAd.Text = App.Path & "\default.htm" blnProgress = True End Sub Private Sub Form_Resize() On Error Resume Next Dim intLen As Integer Dim intPos As Integer 'arrange command buttons at the top of the screen intLen = frmBrowser.Width intLen = intLen / 4 cmdBack.Width = intLen intPos = intLen + 10 cmdFoward.Left = intPos cmdFoward.Width = intLen intPos = intPos + intLen + 10 cmdStop.Left = intPos cmdStop.Width = intLen intPos = intPos + intLen + 10 cmdRefresh.Left = intPos cmdRefresh.Width = intLen - 150 Label1.Left = wb.Left + 50 'arrange other controls With wb .Width = frmBrowser.Width - 100 .Height = frmBrowser.Height - 2000 lblStat.Top = .Top + .Height + 50 lblStat.Left = lblStat.Left + 50 intDrawPos = lblStat.Top + lblStat.Height + 10 cmbAd.Width = .Width - Label1.Width - 120 End With End Sub Private Sub Form_Unload(Cancel As Integer) Set objSource = Nothing End Sub Private Sub Label1_Click() cmbAd.SetFocus End Sub Private Sub mnuAddFoo_Click() 'not existing menu cmbAd.SetFocus End Sub Private Sub mnuFileBack_Click() On Error Resume Next wb.GoBack End Sub Private Sub mnuFileExit_Click() On Error Resume Next Unload frmBrowser End Sub Private Sub mnuFileForward_Click() On Error Resume Next wb.GoForward End Sub Private Sub mnuFileGo_Click() On Error Resume Next If cmbAd.Text <> "" Then wb.Navigate cmbAd.Text End Sub Private Sub mnuFileOffline_Click() On Error Resume Next 'working offline or not 'if working online, some things have to be changed: 'WebBrowser's Offline property has to be changed to TRUE. 'blnProgress is set to false since no progress bar will be 'shown if browsing offline. If mnuFileOffline.Checked = True Then mnuFileOffline.Checked = False 'uncheck menu wb.Offline = False 'set browser to online lblStat.Caption = "Ready" 'change status blnProgress = True Else mnuFileOffline.Checked = True 'check menu wb.Offline = True 'set browser to offline lblStat.Caption = "Working Offline" 'change status blnProgress = False End If End Sub Private Sub mnuFileStop_Click() On Error Resume Next wb.Stop End Sub Private Sub mnuQuickCollege_Click() On Error Resume Next wb.Navigate strCollege wb.SetFocus End Sub Private Sub mnuQuickGames_Click() On Error Resume Next wb.Navigate strGame wb.SetFocus End Sub Private Sub mnuQuickMail_Click() On Error Resume Next wb.Navigate strMail wb.SetFocus End Sub Private Sub mnuToolLog_Click() On Error GoTo er Dim question As VbMsgBoxResult If mnuToolLog.Checked = True Then mnuToolLog.Checked = False blnLog = False blnTimeLog = False Else question = MsgBox("Would you like to log date/time values?", vbQuestion + vbYesNo, "Date/Time?") If question = vbYes Then blnTimeLog = True mnuToolLog.Checked = True blnLog = True End If Exit Sub er: MsgBox "Error occurred: " & Err.Description & ". Can't log.", vbCritical, "Error" End Sub Private Sub mnuToolsViewLog_Click() On Error GoTo er 'opens Text Editor to view log ShellExecute frmBrowser.hwnd, "open", App.Path & "/log.txt", 0, "c:\", 1 Exit Sub er: MsgBox "Couldn't load log file. Please do it manually by checking log.txt", vbCritical, "Can't open log.txt" End Sub Private Sub mnuViewSource_Click() On Error Resume Next Err.Clear 'clear errors so that old dissappear Set objSource = New frmSource 'load form which shows 'source html 'using internet control, get html of page strPageSource = Inet1.OpenURL(cmbAd.Text) If Err Then 'if page is not on web, but local If Err.Description = "URL is malformed" Then strPageSource = Inet1.OpenURL("file://" & cmbAd.Text) End If Err.Clear End If frmSource.SendData strPageSource 'send the data to the 'form which will show it frmSource.Show 'show the form End Sub Private Sub mnuViewToolbar_Click() On Error Resume Next 'show/hide command buttons at the top of the main window If mnuViewToolbar.Checked = True Then mnuViewToolbar.Checked = False cmdBack.Visible = False cmdFoward.Visible = False cmdRefresh.Visible = False cmdStop.Visible = False Else mnuViewToolbar.Checked = True cmdBack.Visible = True cmdFoward.Visible = True cmdRefresh.Visible = True cmdStop.Visible = True End If End Sub Private Sub wb_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long) On Error Resume Next If blnProgress = False Then Exit Sub If Progress > 3000 Then Exit Sub If Progress <= 0 Then frmBrowser.Cls Exit Sub End If Line (50, intDrawPos)-(Progress, intDrawPos + 50), 1, BF Line (50, intDrawPos)-(3000, intDrawPos + 50), 15, B End Sub Private Sub wb_StatusTextChange(ByVal Text As String) On Error Resume Next 'update status label with appropriate status value Dim strTemp As String Dim strTime As String 'if opening or loading pages If Text <> "Done" And Text <> "" Then 'show what is being done lblStat.Caption = Text 'if browser is opening website, show which one If Left$(Text, 12) = "Opening page" Then cmbAd.Text = Mid$(Text, 13, Len(Text) - 15) If Text = strPrevSite Then Exit Sub 'log website If blnLog = True Then 'open log file Open App.Path & "\log.txt" For Append As #1 'time stamp If blnTimeLog = True Then strTime = Now Write #1, strTime 'record time Write #1, cmbAd.Text 'record website Close #1 End If strPrevSite = Text End If Else If mnuFileOffline.Checked Then lblStat.Caption = "Working Offline" Else lblStat.Caption = "Ready" End If frmBrowser.Cls End If End Sub Public Sub QuickLaunch() 'quick launch shortcut values On Error Resume Next strMail = "mail.yahoo.com" strGame = "games.yahoo.com" strCollege = "www.iit.edu" End Sub