1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
Imports Microsoft.Office.Interop.Word
Public Class Form3
Dim wordApp1 As Microsoft.Office.Interop.Word.Application
Dim wordApp2 As Microsoft.Office.Interop.Word.Application
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Me.TopMost = True
End Sub
Private Sub btnInstance1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInstance1.Click
wordApp1 = New Microsoft.Office.Interop.Word.Application
'le caption identifiant cette instance
wordApp1.Caption = "New Caption Supplied by Program Instance 1"
'window handle
Dim HwndWord As Long
HwndWord = FindWindow("OpusApp", wordApp1.Caption)
wordApp1.Visible = True
Me.TextBox1.Text = Me.TextBox1.Text & _
"HwndWord ( " & Hex(HwndWord) & " ) contains the Window Handle " & _
"of the Word application created by this program." & vbCr & _
"You can use this Window Handle in various Win 32 APIs, " & _
"such as SetForeGroundWindow," & vbCr & _
"which require a Window Handle parameter to be supplied." & vbCr _
& vbCr & "All Done. "
End Sub
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub btnInstance2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInstance2.Click
wordApp2 = New Microsoft.Office.Interop.Word.Application
'le caption identifiant cette instance
wordApp2.Caption = "New Caption Supplied by Program Instance 2"
'window handle
Dim HwndWord As Long
HwndWord = FindWindow("OpusApp", wordApp2.Caption) 'window handle
wordApp2.Visible = True
Me.TextBox2.Text = Me.TextBox2.Text & _
"hWndXl ( " & Hex(HwndWord) & " ) contains the Window Handle " & _
"of the Word application created by this program." & vbCr & _
"You can use this Window Handle in various Win 32 APIs, " & _
"such as SetForeGroundWindow," & vbCr & _
"which require a Window Handle parameter to be supplied." & vbCr _
& vbCr & "All Done. ."
End Sub
Private Sub btnCloseWordApps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseWordApps.Click
If wordApp1 IsNot Nothing Then
wordApp1.Caption = String.Empty 'Set the original caption back
wordApp1.Quit()
wordApp1 = Nothing
End If
If wordApp2 IsNot Nothing Then
wordApp2.Caption = String.Empty 'Set the original caption back
wordApp2.Quit()
wordApp2 = Nothing
End If
End Sub
Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If wordApp1 IsNot Nothing Then
wordApp1.Caption = String.Empty 'Set the original caption back
wordApp1.Quit()
wordApp1 = Nothing
End If
If wordApp2 IsNot Nothing Then
wordApp2.Caption = String.Empty 'Set the original caption back
wordApp2.Quit()
wordApp2 = Nothing
End If
End Sub
End Class |
Partager