Получить текст из блокнота - VB
Формулировка задачи:
Пытаюсь получить текст из блокнота, но что-то не докрутил
Длинну текста показывает, а сам текст нет
Листинг программы
- Private Sub Выбрать_Click()
- Dim HWD&
- Dim PROC
- Dim strCaption As String
- HWD& = GetDesktopWindow()
- HWD& = GetWindow(HWD&, GW_CHILD)
- Do
- DoEvents
- dummy& = GetWindowTextLength(HWD&)
- If dummy& <> 0 Then
- strCaption = String(dummy + 1, " ")
- dummy = GetWindowText(HWD&, strCaption, dummy + 1)
- ' Debug.Print HWD& & " - " & strCaption
- If InStr(strCaption, "livebet") > 0 Then
- hChild = FindWindowEx(HWD&, 0, ByVal "edit", vbNullString)
- textLen = SendMessage(hChild, 14, 0, 0)
- WinText = String(textLen, Chr$(0))
- Call SendMessage(hChild, WM_GETTEXT, textLen, ByVal WinText)
- Debug.Print Len(WinText), WinText
- MsgBox WinText
- PROC = "notepad.exe"
- Shell "cmd /c tasklist|FindStr /BLIC:" & PROC & "&&taskkill /f /im " & PROC
- Exit Sub
- End If
- End If
- HWD& = GetWindow(HWD&, GW_HWNDNEXT)
- Loop While HWD& <> 0
- End Sub
Решение задачи: «Получить текст из блокнота»
textual
Листинг программы
- 'modul
- Declare Function GetDesktopWindow Lib "user32.dll" () As Long
- Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
- Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
- Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
- Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
- 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
- Public Const GW_HWNDNEXT = 2
- Public Const GW_CHILD = 5
- Public Const WM_GETTEXTLENGTH = &HE
- Public Const WM_GETTEXT = &HD
- '.........................................................................
- 'Form
- Private Sub Command1_Click()
- Dim WinText As String
- Dim HWD&
- Dim PROC
- Dim strCaption As String
- HWD& = GetDesktopWindow()
- HWD& = GetWindow(HWD&, GW_CHILD)
- Do
- DoEvents
- dummy& = GetWindowTextLength(HWD&)
- If dummy& <> 0 Then
- strCaption = String(dummy + 1, " ")
- dummy = GetWindowText(HWD&, strCaption, dummy + 1)
- ' Debug.Print HWD& & " - " & strCaption
- If InStr(strCaption, "livebet") > 0 Then
- hChild = FindWindowEx(HWD&, 0, ByVal "edit", vbNullString)
- textLen = SendMessage(hChild, WM_GETTEXTLENGTH, 0, 0)
- WinText = String(textLen, Chr$(0))
- Call SendMessage(hChild, WM_GETTEXT, textLen + 1, WinText)
- 'Debug.Print Len(WinText), WinText
- MsgBox WinText
- PROC = "notepad.exe"
- 'Shell "cmd /c tasklist|FindStr /BLIC:" & PROC & "&&taskkill /f /im " & PROC
- Exit Sub
- End If
- End If
- HWD& = GetWindow(HWD&, GW_HWNDNEXT)
- Loop While HWD& <> 0
- MsgBox "Not"
- End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д