Private Declare Function InitCommonControls Lib "Comctl32.dll" () As Long
Dim miamodificata As Boolean
Dim modificata As Boolean
Private Sub Form_Initialize()
Dim x As Long
x = InitCommonControls
End Sub
Private Sub cmdCattura_Click()
Dim oggetto As New MSHTML.HTMLDocument
Dim documento As MSHTML.HTMLDocument
If pagecode.Text = "" Then
Set documento = oggetto.createDocumentFromUrl("http://" + txtPage.Text, vbNullString)
Do While documento.ReadyState <> "complete"
DoEvents
Loop
pagecode.Text = documento.documentElement.outerHTML
Set documento = Nothing
Set oggetto = Nothing
Else
pagecode.Text = ""
Set documento = oggetto.createDocumentFromUrl("http://" + txtPage.Text, vbNullString)
Do While documento.ReadyState <> "complete"
DoEvents
Loop
pagecode.Text = documento.documentElement.outerHTML
Set documento = Nothing
Set oggetto = Nothing
End If
modificata = True
End Sub
Private Sub cmdPulisci_Click()
WebBrowser1.Document.Script.Document.Clear
WebBrowser1.Document.Script.Document.Write ""
WebBrowser1.Document.Script.Document.Close
RichTextBox1.Text = ""
pagecode.Text = ""
txtPage.Text = ""
End Sub
Private Sub cmdSee_Click()
RichTextBox1.Text = pagecode.Text
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim msg As String
Dim msg2 As String
If miamodificata = True Then
msg = MsgBox("Salvare le modifiche alla tua pagina HTML?", vbExclamation + vbYesNo)
Select Case msg
Case vbYes
On Error GoTo Errore_2
1 CommonDialog1.Filter = "HTML Files|*.html|HTM files|*htm"
CommonDialog1.ShowSave
If Dir(CommonDialog1.FileName) = "" Then
Open CommonDialog1.FileName For Output As #1
Print #1, RichTextBox1.Text
Close #1
Else: uguale = MsgBox("Il file " & Form1.CommonDialog1.FileTitle + " è gia esistente. Si desidera sostituirlo?", vbExclamation + vbYesNo, "Editor e visualizzatore HTML")
Select Case uguale
Case vbYes
Open CommonDialog1.FileName For Output As #1
Print #1, RichTextBox1.Text
Close #1
Case vbNo
GoTo 1
Case Else
MsgBox "Errore interno", vbCritical, "Errore interno"
End Select
End If
Errore_2:
End
Case vbNo
End
Case Else
MsgBox "Errore interno", vbCritical
End
End Select
End If
If modificata = True And miamodificata = False Then
msg2 = MsgBox("Salvare le modifiche alla pagina HTML catturata?", vbExclamation + vbYesNo)
Select Case msg2
Case vbYes
On Error GoTo Errore_3
2 CommonDialog1.Filter = "HTML Files|*.html|HTM files|*htm"
CommonDialog1.ShowSave
If Dir(CommonDialog1.FileName) = "" Then
Open CommonDialog1.FileName For Output As #1
Print #1, pagecode.Text
Close #1
Else: uguale = MsgBox("Il file " & Form1.CommonDialog1.FileTitle + " è gia esistente. Si desidera sostituirlo?", vbExclamation + vbYesNo, "Editor e visualizzatore HTML")
Select Case uguale
Case vbYes
Open CommonDialog1.FileName For Output As #1
Print #1, pagecode.Text
Close #1
Case vbNo
GoTo 2
Case Else
MsgBox "Errore interno", vbCritical, "Errore interno"
End
End Select
End If
Errore_3:
End
Case vbNo
End
Case Else
MsgBox "Errore interno", vbCritical
End
End Select
End If
End Sub
Private Sub mnuAbout_Click()
Form2.Show
End Sub
Private Sub mnuEnd_Click()
End
End Sub
Private Sub mnuOpen_Click()
On Error GoTo Errore
CommonDialog1.Filter = "HTML Files|*.html|HTM Files|*.htm"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
RichTextBox1.Text = Input(LOF(1), #1)
Close #1
RichTextBox1.SelStart = Len(RichTextBox1.Text)
Errore:
End Sub
Private Sub mnuSave_Click()
On Error GoTo Errore_2
1 CommonDialog1.Filter = "HTML Files|*.html|HTM files|*htm"
CommonDialog1.ShowSave
If Dir(CommonDialog1.FileName) = "" Then
Open CommonDialog1.FileName For Output As #1
Print #1, RichTextBox1.Text
Close #1
Else: uguale = MsgBox("Il file " & Form1.CommonDialog1.FileTitle + " è gia esistente. Si desidera sostituirlo?", vbExclamation + vbYesNo, "Editor e visualizzatore HTML")
Select Case uguale
Case vbYes
Open CommonDialog1.FileName For Output As #1
Print #1, RichTextBox1.Text
Close #1
Case vbNo
GoTo 1
Case Else
MsgBox "Errore interno", vbCritical, "Errore interno"
End Select
End If
Errore_2:
Exit Sub
miamodificata = False
End Sub
Private Sub mnuSaveCapture_Click()
On Error GoTo Errore_3
2 CommonDialog1.Filter = "HTML Files|*.html|HTM files|*htm"
CommonDialog1.ShowSave
If Dir(CommonDialog1.FileName) = "" Then
Open CommonDialog1.FileName For Output As #1
Print #1, pagecode.Text
Close #1
Else: uguale = MsgBox("Il file " & Form1.CommonDialog1.FileTitle + " è gia esistente. Si desidera sostituirlo?", vbExclamation + vbYesNo, "Editor e visualizzatore HTML")
Select Case uguale
Case vbYes
Open CommonDialog1.FileName For Output As #1
Print #1, pagecode.Text
Close #1
Case vbNo
GoTo 2
Case Else
MsgBox "Errore interno", vbCritical, "Errore interno"
End
End Select
End If
Errore_3:
Exit Sub
modificata = False
End Sub
Private Sub RichTextBox1_Change()
WebBrowser1.Document.Script.Document.Clear
WebBrowser1.Document.Script.Document.Write RichTextBox1.Text
WebBrowser1.Document.Script.Document.Close
miamodificata = True
End Sub
Private Sub txtPage_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
cmdCattura_Click
End If
End Sub