Получить текст из блокнота - VB

Узнай цену своей работы

Формулировка задачи:

Пытаюсь получить текст из блокнота, но что-то не докрутил Длинну текста показывает, а сам текст нет
Листинг программы
  1. Private Sub Выбрать_Click()
  2. Dim HWD&
  3. Dim PROC
  4. Dim strCaption As String
  5. HWD& = GetDesktopWindow()
  6. HWD& = GetWindow(HWD&, GW_CHILD)
  7. Do
  8. DoEvents
  9. dummy& = GetWindowTextLength(HWD&)
  10. If dummy& <> 0 Then
  11. strCaption = String(dummy + 1, " ")
  12. dummy = GetWindowText(HWD&, strCaption, dummy + 1)
  13. ' Debug.Print HWD& & " - " & strCaption
  14. If InStr(strCaption, "livebet") > 0 Then
  15. hChild = FindWindowEx(HWD&, 0, ByVal "edit", vbNullString)
  16. textLen = SendMessage(hChild, 14, 0, 0)
  17. WinText = String(textLen, Chr$(0))
  18. Call SendMessage(hChild, WM_GETTEXT, textLen, ByVal WinText)
  19. Debug.Print Len(WinText), WinText
  20. MsgBox WinText
  21. PROC = "notepad.exe"
  22. Shell "cmd /c tasklist|FindStr /BLIC:" & PROC & "&&taskkill /f /im " & PROC
  23. Exit Sub
  24. End If
  25. End If
  26. HWD& = GetWindow(HWD&, GW_HWNDNEXT)
  27. Loop While HWD& <> 0
  28. End Sub

Решение задачи: «Получить текст из блокнота»

textual
Листинг программы
  1. 'modul
  2. Declare Function GetDesktopWindow Lib "user32.dll" () As Long
  3. Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
  4. Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  5. Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  6.  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
  7.  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
  8.  
  9. Public Const GW_HWNDNEXT = 2
  10. Public Const GW_CHILD = 5
  11. Public Const WM_GETTEXTLENGTH = &HE
  12. Public Const WM_GETTEXT = &HD
  13. '.........................................................................
  14. 'Form
  15. Private Sub Command1_Click()
  16. Dim WinText As String
  17. Dim HWD&
  18. Dim PROC
  19. Dim strCaption As String
  20. HWD& = GetDesktopWindow()
  21.  
  22. HWD& = GetWindow(HWD&, GW_CHILD)
  23. Do
  24. DoEvents
  25.         dummy& = GetWindowTextLength(HWD&)
  26.         If dummy& <> 0 Then
  27.                     strCaption = String(dummy + 1, " ")
  28.                     dummy = GetWindowText(HWD&, strCaption, dummy + 1)
  29. '                    Debug.Print HWD& & "  -  " & strCaption
  30.                    If InStr(strCaption, "livebet") > 0 Then
  31.                         hChild = FindWindowEx(HWD&, 0, ByVal "edit", vbNullString)
  32.                             textLen = SendMessage(hChild, WM_GETTEXTLENGTH, 0, 0)
  33.                                 WinText = String(textLen, Chr$(0))
  34.                                 Call SendMessage(hChild, WM_GETTEXT, textLen + 1, WinText)
  35.                                 'Debug.Print Len(WinText), WinText
  36.                                MsgBox WinText
  37.                                 PROC = "notepad.exe"
  38.                                 'Shell "cmd /c tasklist|FindStr /BLIC:" & PROC & "&&taskkill /f /im " & PROC
  39.                       Exit Sub
  40.                     End If
  41.             End If
  42.         HWD& = GetWindow(HWD&, GW_HWNDNEXT)
  43. Loop While HWD& <> 0
  44. MsgBox "Not"
  45. End Sub

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

11   голосов , оценка 3.727 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы