You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
453 lines
16 KiB
453 lines
16 KiB
' A simple WebBrowser control host.
|
|
|
|
Imports System.Resources
|
|
Imports System.Runtime.InteropServices
|
|
Imports System.IO
|
|
|
|
Public Class frmWordViewer
|
|
Inherits System.Windows.Forms.Form
|
|
|
|
Dim m_PrintFilename As String
|
|
Property PrintFilename() As String
|
|
Get
|
|
Return m_PrintFilename
|
|
End Get
|
|
Set(ByVal Value As String)
|
|
m_PrintFilename = Value
|
|
End Set
|
|
End Property
|
|
Dim m_printdokumentid As String
|
|
Property PrintDokumentid() As String
|
|
Get
|
|
Return m_printdokumentid
|
|
End Get
|
|
Set(ByVal Value As String)
|
|
m_printdokumentid = Value
|
|
End Set
|
|
End Property
|
|
|
|
'edex banköaternd
|
|
Dim m_showprintmessage As Boolean = True
|
|
Property Show_Print_Message() As Boolean
|
|
Get
|
|
Return m_showprintmessage
|
|
End Get
|
|
Set(ByVal Value As Boolean)
|
|
m_showprintmessage = Value
|
|
End Set
|
|
End Property
|
|
|
|
Private rm As ResourceManager
|
|
Private wasUrlTyped As Boolean = False
|
|
|
|
|
|
#Region " Windows Form Designer generated code "
|
|
|
|
Public Sub New()
|
|
MyBase.New()
|
|
|
|
'This call is required by the Windows Form Designer.
|
|
InitializeComponent()
|
|
|
|
End Sub
|
|
|
|
'Form overrides dispose to clean up the component list.
|
|
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
|
|
If disposing Then
|
|
If Not (components Is Nothing) Then
|
|
components.Dispose()
|
|
End If
|
|
End If
|
|
MyBase.Dispose(disposing)
|
|
End Sub
|
|
|
|
'Required by the Windows Form Designer
|
|
Private components As System.ComponentModel.IContainer
|
|
|
|
'NOTE: The following procedure is required by the Windows Form Designer
|
|
'It can be modified using the Windows Form Designer.
|
|
'Do not modify it using the code editor.
|
|
Friend WithEvents webOCWrapper As WebOCHostCtrl
|
|
Friend WithEvents MenuItem13 As System.Windows.Forms.MenuItem
|
|
Friend Shadows WithEvents contextMenu As System.Windows.Forms.ContextMenu
|
|
Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
|
|
Friend WithEvents addressBar As System.Windows.Forms.ComboBox
|
|
Friend WithEvents addressBarLbl As System.Windows.Forms.Label
|
|
Friend WithEvents ToolBar2 As System.Windows.Forms.ToolBar
|
|
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
|
|
Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
|
|
Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton
|
|
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
|
|
Me.components = New System.ComponentModel.Container()
|
|
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmWordViewer))
|
|
Me.webOCWrapper = New EDOKAApp.WebOCHostCtrl()
|
|
Me.contextMenu = New System.Windows.Forms.ContextMenu()
|
|
Me.MenuItem13 = New System.Windows.Forms.MenuItem()
|
|
Me.StatusBar1 = New System.Windows.Forms.StatusBar()
|
|
Me.addressBar = New System.Windows.Forms.ComboBox()
|
|
Me.addressBarLbl = New System.Windows.Forms.Label()
|
|
Me.ToolBar2 = New System.Windows.Forms.ToolBar()
|
|
Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton()
|
|
Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton()
|
|
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
|
|
Me.SuspendLayout()
|
|
'
|
|
'webOCWrapper
|
|
'
|
|
Me.webOCWrapper.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
|
|
Or System.Windows.Forms.AnchorStyles.Left) _
|
|
Or System.Windows.Forms.AnchorStyles.Right)
|
|
Me.webOCWrapper.BrowserContextMenu = False
|
|
Me.webOCWrapper.ImeMode = System.Windows.Forms.ImeMode.NoControl
|
|
Me.webOCWrapper.Location = New System.Drawing.Point(0, 24)
|
|
Me.webOCWrapper.Name = "webOCWrapper"
|
|
Me.webOCWrapper.Size = New System.Drawing.Size(864, 520)
|
|
Me.webOCWrapper.TabIndex = 0
|
|
Me.webOCWrapper.TabStop = False
|
|
'
|
|
'contextMenu
|
|
'
|
|
Me.contextMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem13})
|
|
'
|
|
'MenuItem13
|
|
'
|
|
Me.MenuItem13.Index = 0
|
|
Me.MenuItem13.Text = "Print..."
|
|
'
|
|
'StatusBar1
|
|
'
|
|
Me.StatusBar1.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
|
|
Or System.Windows.Forms.AnchorStyles.Right)
|
|
Me.StatusBar1.Dock = System.Windows.Forms.DockStyle.None
|
|
Me.StatusBar1.Location = New System.Drawing.Point(0, 549)
|
|
Me.StatusBar1.Name = "StatusBar1"
|
|
Me.StatusBar1.Size = New System.Drawing.Size(864, 24)
|
|
Me.StatusBar1.TabIndex = 1
|
|
'
|
|
'addressBar
|
|
'
|
|
Me.addressBar.Location = New System.Drawing.Point(16, 56)
|
|
Me.addressBar.Name = "addressBar"
|
|
Me.addressBar.Size = New System.Drawing.Size(352, 21)
|
|
Me.addressBar.Sorted = True
|
|
Me.addressBar.TabIndex = 3
|
|
Me.addressBar.Visible = False
|
|
'
|
|
'addressBarLbl
|
|
'
|
|
Me.addressBarLbl.Location = New System.Drawing.Point(16, 12)
|
|
Me.addressBarLbl.Name = "addressBarLbl"
|
|
Me.addressBarLbl.Size = New System.Drawing.Size(100, 16)
|
|
Me.addressBarLbl.TabIndex = 8
|
|
Me.addressBarLbl.TextAlign = System.Drawing.ContentAlignment.MiddleRight
|
|
'
|
|
'ToolBar2
|
|
'
|
|
Me.ToolBar2.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1, Me.ToolBarButton2})
|
|
Me.ToolBar2.DropDownArrows = True
|
|
Me.ToolBar2.ImageList = Me.ImageList1
|
|
Me.ToolBar2.Name = "ToolBar2"
|
|
Me.ToolBar2.ShowToolTips = True
|
|
Me.ToolBar2.Size = New System.Drawing.Size(864, 25)
|
|
Me.ToolBar2.TabIndex = 9
|
|
'
|
|
'ToolBarButton1
|
|
'
|
|
Me.ToolBarButton1.ImageIndex = 0
|
|
'
|
|
'ToolBarButton2
|
|
'
|
|
Me.ToolBarButton2.ImageIndex = 1
|
|
'
|
|
'ImageList1
|
|
'
|
|
Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
|
|
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
|
|
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
|
|
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
|
|
'
|
|
'frmWordViewer
|
|
'
|
|
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
|
|
Me.ClientSize = New System.Drawing.Size(864, 573)
|
|
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ToolBar2, Me.addressBarLbl, Me.StatusBar1, Me.addressBar, Me.webOCWrapper})
|
|
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
|
|
Me.Name = "frmWordViewer"
|
|
Me.Text = "Office-Dokumentanzeige"
|
|
Me.ResumeLayout(False)
|
|
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
|
|
Private Sub exitMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
' Clean up app.
|
|
|
|
Close()
|
|
End Sub
|
|
|
|
Public Sub New(ByVal printable As Boolean)
|
|
MyBase.New()
|
|
'This call is required by the Windows Form Designer.
|
|
InitializeComponent()
|
|
If printable = False Then
|
|
Me.ToolBarButton2.Visible = False
|
|
Else
|
|
Me.ToolBarButton2.Visible = True
|
|
End If
|
|
Me.WindowState = FormWindowState.Maximized
|
|
End Sub
|
|
|
|
' Update the available menu commands, particularly for cut/copy/paste.
|
|
' Also update the enabled state of the forward/back buttons.
|
|
' !TODO: Not the best place to do this. Find somewhere else.
|
|
|
|
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
|
webOCWrapper.Navigate(addressBar.Text)
|
|
End Sub
|
|
|
|
Private Sub webOCWrapper_StatusTextChange(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent) Handles webOCWrapper.StatusTextChange
|
|
StatusBar1.Text = e.text
|
|
End Sub
|
|
|
|
Private Sub findMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
webOCWrapper.Find()
|
|
End Sub
|
|
|
|
Private Sub inetOptionsMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
webOCWrapper.InternetOptions()
|
|
End Sub
|
|
|
|
Private Sub addressBar_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles addressBar.KeyDown
|
|
If (e.KeyCode = Keys.Return) Then
|
|
' Validate URL.
|
|
Try
|
|
' TODO: This won't accept URLs like "www.amazon.com",
|
|
' like IE will.
|
|
' Dim u As New Uri(addressBar.Text)
|
|
Catch
|
|
MessageBox.Show(rm.GetString("Error_InvalidUrlOrFile") + " : " + Err.GetException().Message, rm.GetString("Caption_InvalidUrlOrFile"), MessageBoxButtons.OK, MessageBoxIcon.Error)
|
|
Exit Sub
|
|
End Try
|
|
webOCWrapper.Navigate(addressBar.Text)
|
|
' Add to the list of available web sites - but wait
|
|
' for NavigateComplete2, so we get the fully-formatted,
|
|
' redirected URL.
|
|
wasUrlTyped = True
|
|
' Cancel the event so the address bar never sees this.
|
|
|
|
End If
|
|
End Sub
|
|
|
|
|
|
Private Sub backButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
webOCWrapper.GoBack()
|
|
End Sub
|
|
|
|
Private Sub forwardButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
webOCWrapper.GoForward()
|
|
End Sub
|
|
|
|
Private Sub homeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
webOCWrapper.GoHome()
|
|
End Sub
|
|
|
|
Private Sub webOCWrapper_TopLevelNavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles webOCWrapper.TopLevelNavigateComplete2
|
|
addressBar.Text = Convert.ToString(e.uRL)
|
|
If wasUrlTyped Then
|
|
wasUrlTyped = False
|
|
addressBar.Items.Add(e.uRL)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub cutMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
webOCWrapper.Cut()
|
|
End Sub
|
|
|
|
Private Sub copyMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
webOCWrapper.Copy()
|
|
End Sub
|
|
|
|
Private Sub pasteMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
webOCWrapper.Paste()
|
|
End Sub
|
|
|
|
Private Sub printMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
|
|
Try
|
|
webOCWrapper.Print(doUI:=True)
|
|
' webOCWrapper.webBrowser.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT2, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT)
|
|
Catch
|
|
End Try
|
|
End Sub
|
|
|
|
Public Sub Print_Doc()
|
|
Try
|
|
If print_word() = True Then Exit Sub
|
|
Catch
|
|
End Try
|
|
Try
|
|
webOCWrapper.Print(doUI:=True)
|
|
Catch ex As Exception
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
Private Sub MenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem13.Click
|
|
Try
|
|
If print_word() = True Then Exit Sub
|
|
webOCWrapper.Print(doUI:=True)
|
|
Catch
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub ToolBar2_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar2.ButtonClick
|
|
Dim i As Integer
|
|
|
|
Select Case Me.ToolBar2.Buttons.IndexOf(e.Button)
|
|
Case 0 'close button
|
|
Me.Close()
|
|
Case 1 'pint
|
|
Try
|
|
If print_word() = True Then Exit Sub
|
|
Catch
|
|
End Try
|
|
Try
|
|
webOCWrapper.Print(doUI:=True)
|
|
Catch
|
|
End Try
|
|
Case Else
|
|
End Select
|
|
|
|
End Sub
|
|
|
|
Private Sub frmWordViewer_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
|
|
Try
|
|
Try
|
|
|
|
'docword = Nothing
|
|
'objword.Quit(False)
|
|
'objword = Nothing
|
|
Catch
|
|
|
|
End Try
|
|
File.Delete(Me.addressBar.Text)
|
|
Catch
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
|
|
' Dim objword As Word.Application()
|
|
' Dim docword As Word.Document()
|
|
|
|
Dim W As Integer
|
|
Dim H As Integer
|
|
|
|
Private Function print_word() As Boolean
|
|
Dim objword As New Word.Application()
|
|
Dim FileReader As New DocMgmt()
|
|
Dim dokument As String
|
|
Try
|
|
dokument = DivFnkt.Get_Filename("View_" + Format(Now, "yyyyMMddHHmmss") + "_" + Me.PrintFilename, "")
|
|
If FileReader.Get_From_DB(Me.PrintDokumentid, dokument) = False Then
|
|
Return False
|
|
End If
|
|
Catch
|
|
Finally
|
|
FileReader = Nothing
|
|
End Try
|
|
|
|
If UCase(Microsoft.VisualBasic.Right(Me.PrintFilename, 4)) <> ".DOC" Then
|
|
Return False
|
|
End If
|
|
|
|
Application.DoEvents()
|
|
Try
|
|
StartWord()
|
|
Application.DoEvents()
|
|
objword.Documents.Open(dokument)
|
|
|
|
'docword = objword.Documents.Open(dokument)
|
|
'Try
|
|
' docword.Activate()
|
|
'Catch
|
|
'End Try
|
|
Try
|
|
objword.Activate()
|
|
Catch
|
|
End Try
|
|
Try
|
|
objword.Run("Autoexec")
|
|
Catch
|
|
End Try
|
|
Try
|
|
objword.Activate()
|
|
Catch
|
|
End Try
|
|
'Try
|
|
' docword.Activate()
|
|
'Catch
|
|
'End Try
|
|
System.Windows.Forms.Application.DoEvents()
|
|
'Dim cmbr As Microsoft.Office.Core.CommandBar 'RS:2006-08-22
|
|
Dim cmbr As Office.CommandBar
|
|
For Each cmbr In objword.CommandBars
|
|
'Dim cbctl As Microsoft.Office.Core.CommandBarControl 'RS:2006-08-22
|
|
Dim cbctl As Office.CommandBarControl
|
|
For Each cbctl In cmbr.Controls
|
|
If cbctl.Id = 2521 Then
|
|
' MyMsg.show_standardmessage(250, MsgBoxStyle.Information)
|
|
System.Windows.Forms.Application.DoEvents()
|
|
objword.Selection.HomeKey(Unit:=Word.WdUnits.wdLine, Extend:=Word.WdMovementType.wdExtend)
|
|
System.Windows.Forms.Application.DoEvents()
|
|
cbctl.Execute()
|
|
System.Windows.Forms.Application.DoEvents()
|
|
objword.Visible = False
|
|
System.Threading.Thread.Sleep(5500)
|
|
If Me.Show_Print_Message = True Then
|
|
MyMsg.show_standardmessage(250, MsgBoxStyle.Information)
|
|
Return True
|
|
End If
|
|
Return True
|
|
Exit Function
|
|
End If
|
|
Next
|
|
Next
|
|
Return True
|
|
Catch ex As Exception
|
|
Return False
|
|
Finally
|
|
objword.Quit(False)
|
|
objword = Nothing
|
|
End Try
|
|
End Function
|
|
|
|
Private Function StartWord()
|
|
'Try
|
|
' objword = GetObject(, "Word.application")
|
|
' 'objword = CreateObject("Word.application")
|
|
'Catch
|
|
' Try
|
|
' objword = CreateObject("Word.application")
|
|
' Catch ex As Exception
|
|
' MsgBox(ex.Message)
|
|
' End Try
|
|
'Finally
|
|
' 'objword.Visible = False
|
|
' 'objword.WindowState = Word.WdWindowState.wdWindowStateNormal
|
|
' objword.WindowState = Word.WdWindowState.wdWindowStateMinimize
|
|
' 'W = objword.Width
|
|
' 'H = objword.Height
|
|
' 'objword.Width = 10
|
|
' 'objword.Height = 10
|
|
' objword.Visible = True
|
|
|
|
'End Try
|
|
'Try
|
|
' objword.Run("Autoexec")
|
|
'Catch
|
|
'End Try
|
|
End Function
|
|
|
|
End Class |