- Код: Выделить всё
<DllImport("user32.dll")> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
выдаёт - Ошибка 1 Недопустимый оператор для пространства имен.
как же её прописать?
<DllImport("user32.dll")> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
Imports System.Runtime.InteropServices
Module All
<DllImport("user32.dll")> _
Private Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
Public Sub Main()
MsgBox(FindWindow("", ""))
End Sub
End Module
Imports System.Runtime.InteropServices
Module All
Dim ikw As Long
<DllImport("user32.dll")> _
Private Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
Public Sub Main()
ikw = FindWindow(vbNullString, "1 - Блокнот")
Form1.TextBox1.Text = ikw
End Sub
End Module
Invader писал(а):Form1.TextBox1.Text =0 , хотя в текстовое поле должен был прийти ответ
MSDN писал(а):Return value
Type: HWND
If the function succeeds, the return value is a handle to the window that has the specified class name and window name.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
ikw = FindWindow(vbNullString, "1 - Блокнот")
Imports System.Runtime.InteropServices
Public Class Form1
Private Delegate Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal lParam As IntPtr) As Boolean
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal lclassName As String, ByVal windowTitle As String) As IntPtr
End Function
<DllImport("User32.dll")>
Public Shared Function SendMessage(hWnd As IntPtr, uMsg As Integer, wParam As Integer, lParam As String) As Integer
End Function
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim lpszParentClass As String = "Notepad"
Dim lpszParentWindow As String = "Безымянный " & ChrW(8212) & " Блокнот"
Dim lpszClass As String = "Edit"
Dim ParenthWnd As New IntPtr(0)
Dim hWnd As New IntPtr(0)
ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow)
If ParenthWnd.Equals(IntPtr.Zero) Then
Console.WriteLine("Notepad Not Running!")
Else
hWnd = FindWindowEx(ParenthWnd, hWnd, lpszClass, "")
If hWnd.Equals(IntPtr.Zero) Then
Console.WriteLine("Notepad doesn't have an Edit component, how strange.")
Else
Console.WriteLine("Notepad Window: " & ParenthWnd.ToString())
Console.WriteLine("Edit Control: " & hWnd.ToString())
SendMessage(hWnd, &HC, 0, "Привет")
End If
End If
End Sub
End Class
Dim lpszParentClass As String = ""
Invader писал(а):если я не знаю lpszParentClass тогда2
- Код: Выделить всё
Dim lpszParentClass As String = ""
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindowByClass(ByVal lpClassName As String, ByVal zero As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindowByCaption(ByVal zero As IntPtr, ByVal lpWindowName As String) As IntPtr
End Function
FindWindowByCaption(0, lpszParentWindow)
Invader писал(а): SendDlgItemMessage на http://pinvoke.net что то ничего не увидел
FireFenix писал(а):Да, или использовать другие сигнатуры и посылать 0
Invader писал(а):
- Код: Выделить всё
Dim ikw As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Private Declare Function GetDlgItem Lib "user32.dll" ( _
ByVal hDlg As Long, _
ByVal nIDDlgItem As Long) As Long
Private Declare Function SendDlgItemMessage Lib "user32.dll" Alias "SendDlgItemMessageA" ( _
ByVal hDlg As Long, _
ByVal nIDDlgItem As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Const WM_SETTEXT = &HC
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HE
Const WM_CLOSE = &H10
Const WM_LBUTTONDOWN As Long = &H201
Const BM_CLICK As Long = &HF5&
Dim x As String
Dim hw As Long
Private Sub Text1_Change()
x = Text1.Text
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
hw = FindWindow(vbNullString, "форма2" & Chr(0))
If KeyAscii = 13 Then SendDlgItemMessage hw, 1004, BM_CLICK, 0, 0
If KeyAscii = 13 Then Text1.Text = Empty
End Sub
Private Sub Timer1_Timer()
Dim hw As Long
Dim bw As Long
Dim ikw As Long
Dim sw As Long
Dim WindowHandle As Long
ikw = FindWindow(vbNullString, "форма1" & Chr(0))
SendDlgItemMessage ikw, 1018, BM_CLICK, 0, 0
hw = FindWindow(vbNullString, "форма2" & Chr(0))
bw = FindWindowEx(hw, ByVal 0&, "EDIT", vbNullString)
sw = GetDlgItem(hw, 1002)
SendMessage bw, WM_SETTEXT, 0, x
WindowHandle& = sw
Dim buffer As String, TextLength As Long
TextLength& = SendMessage(WindowHandle&, WM_GETTEXTLENGTH, 0&, 0&)
buffer$ = String(TextLength&, 0&)
Call SendMessageByString(WindowHandle&, WM_GETTEXT, TextLength& + 1, buffer$)
Label3.Caption = buffer$
Label1.Caption = hw
Label2.Caption = bw
End Sub
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindowByCaption(ByVal zero As IntPtr, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("User32.dll")>
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
End Function
<DllImport("User32.dll")>
Private Shared Function SendDlgItemMessage(ByVal hDlg As IntPtr, ByVal nIDDlgItem As Integer, ByVal Msg As UInteger, ByVal wParam As UIntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal lclassName As String, ByVal windowTitle As String) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)>
Private Shared Function GetDlgItem(ByVal hWnd As HandleRef, ByVal nIDDlgItem As Integer) As IntPtr
End Function
Public BM_CLICK As Integer = &HF5
Public WM_SETTEXT = &HC
Dim x As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lpszClass As String = "Edit"
Dim lpszParentWindow As String = "Проекты"
Dim num2 As String = "form2"
Dim ParenthWnd As New IntPtr(0)
Dim hWnd As New IntPtr(0)
Dim naihWnd As New IntPtr(0)
Dim sWnd As New IntPtr(0)
Dim sw As Long
hWnd = FindWindowByCaption(0, lpszParentWindow)
Label1.Text = hWnd
SendDlgItemMessage(hWnd, 1018, BM_CLICK, 0, 0)
naihWnd = FindWindowByCaption(0, num2)
sWnd = FindWindowEx(ParenthWnd, naihWnd, lpszClass, vbNullString)
sw = GetDlgItem(sWnd, 1001) 'Ошибка 1 Невозможно преобразовать значение типа "System.IntPtr" в "System.Runtime.InteropServices.HandleRef"
SendMessage(sWnd, WM_SETTEXT, 0, x)
Label2.Text = naihWnd
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
x = TextBox1.Text
End Sub
End Class
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)>
Private Shared Function GetDlgItem(ByVal sWnd As IntPtr, ByVal nIDDlgItem As Integer) As IntPtr
End Function
naihWnd = FindWindowByCaption(0, num2)
sWnd = FindWindowEx(ParenthWnd, naihWnd, lpszClass, vbNullString)
sw = GetDlgItem(naihWnd, 1001)
SendMessage(sw, WM_SETTEXT, 0, x) 'замечательно передаёт значение x полю edit id1001
'
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
sWnd = FindWindowByCaption(vbNullString, "form2")
If e.KeyChar = ChrW(Keys.Enter) Then SendDlgItemMessage(sWnd, 1004, BM_CLICK, 0, 0) 'нажатие передается form2
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
x = TextBox1.Text
End Sub
sw = GetDlgItem(hw, 1002)
WindowHandle& = sw
Dim buffer As String, TextLength As Long
TextLength& = SendMessage(WindowHandle&, WM_GETTEXTLENGTH, 0&, 0&)
buffer$ = String(TextLength&, 0&)
Call SendMessageByString(WindowHandle&, WM_GETTEXT, TextLength& + 1, buffer$)
Label3.Caption = buffer$
Dim buffer As String
Dim TextLength As Integer
Dim stringBuilder As New StringBuilder(buffer, TextLength)
TextLength = SendMessage(WindowHandle, WM_GETTEXTLENGTH, 0&, 0&)
Call SendMessageByString(WindowHandle, WM_GETTEXT, TextLength + 1, stringBuilder)' Пропускает но ругается на тип stringBuilder
Label3.Text = stringBuilder
FireFenix писал(а):Использовать StringBuilder
Invader писал(а):теперь получилось нагромождено - вызов и запуск екзешника подключение длл, Но работает!
FireFenix писал(а):Для этого нужно вначале открыть учебник, изучить целевой язык, а потом его использовать.
Invader писал(а):а на .NET их мало.
ну да, вполне "русские" ресурсы - можно связаться с автором задать вопросыFireFenix писал(а):
Даже если хорошо погуглить - можно найти готовые решения на codeplex или sourceforge
Invader писал(а):да я разве про мануалы говорил, я говорил про абсолютно рабочие примеры vbstreets.ru столько было хороших примеров статей, вот к примеру работа с word, именно с этого сайта я изучил и решил раз и навсегда все вопросы...
Invader писал(а):помимо грамотной статьи помогли грамотные простые примеры. Где по всем вопросам работы с WORD можно найти статью да и наглядные к ней примеры на vb.net
а поиски реальных примеров по SendMessageByString только нашёл советы по декларации на vb.net и то на английском, я ничего не говорю против языка, знаю я его плохо но в ответах разобраться могу, но это всё таки не то....
Сейчас этот форум просматривают: Yandex-бот и гости: 38