Solved

Can I read NOTEPAD with MS Agent?

Posted on 2000-05-08
5
259 Views
Last Modified: 2010-05-02
I am trying to make Microsoft Agent read text inserted into the windows applet NOTEPAD. I am using the character 'Peedy' and have not had much luck. I have been able to make him readanything in VB that has a caption or text property. If any expert has knowledge of Agent then please get back to me. Thanks.
0
Comment
Question by:Jubel
  • 3
5 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2789122
you would do it the same way...all you need to do is extract the text from the notepad text file and pass that as the text for the character to say
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2789163
for example, this would read in a text file into a textbox, you can then just pass this string to your character to say:


Const ForReading = 1

Private Sub Command1_Click()
    Dim a, fs As Object
    Dim str As String
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.opentextfile("C:\Windows\Desktop\test.txt", ForReading)
    str = a.ReadAll
    Text1.Text = str
End Sub
0
 

Expert Comment

by:cesarlabitan
ID: 2789186
Try this:


Robby.Show
frm_cliptxt.Text1.Refresh
'rtxt = ""
'rtxt = frm_cliptxt.Text1.Text
Clipboard.SetText frm_cliptxt.Text1
rtxt = Clipboard.GetText
If rtxt = "" Then Exit Sub
'Robby.MoveTo 1, 500
Robby.Speak rtxt
'Robby.hide
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 200 total points
ID: 2789456
in the case you dont know the file that is opened in Notepad and you want to be able to read what is showing in the current running window of Notepad, use this code:


****MODULE CODE****

Public Type ProcData
    AppHwnd As Long
    title As String
    Placement As String
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE

Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDFIRST = 0

Public str As String

Public Function EditInfo(window_hwnd As Long) As String
    Dim txt As String
    Dim buf As String
    Dim buflen As Long
    Dim child_hwnd As Long
    Dim children() As Long
    Dim num_children As Integer
    Dim i As Integer

    ' Get the class name.
    buflen = 256
    buf = Space$(buflen - 1)
    buflen = GetClassName(window_hwnd, buf, buflen)
    buf = Left$(buf, buflen)
   
    ' See if we found an Edit object.
    If buf = "Edit" Then
        EditInfo = WindowText(window_hwnd)
        Exit Function
    End If
   
    ' It's not an Edit object. Search the children.
    ' Make a list of the child windows.
    num_children = 0
    child_hwnd = GetWindow(window_hwnd, GW_CHILD)
    Do While child_hwnd <> 0
        num_children = num_children + 1
        ReDim Preserve children(1 To num_children)
        children(num_children) = child_hwnd
       
        child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT)
    Loop
   
    ' Get information on the child windows.
    For i = 1 To num_children
        txt = EditInfo(children(i))
        If txt <> "" Then Exit For
    Next i

    EditInfo = txt
End Function
' ************************************************
' Return the text associated with the window.
' ************************************************
Public Function WindowText(window_hwnd As Long) As String
    Dim txtlen As Long
    Dim txt As String

    WindowText = ""
    If window_hwnd = 0 Then Exit Function
   
    txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)
    If txtlen = 0 Then Exit Function
   
    txtlen = txtlen + 1
    txt = Space$(txtlen)
    txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)
    WindowText = Left$(txt, txtlen)
End Function


Public Function EnumProc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean
    Dim buf As String * 1024
    Dim title As String
    Dim length As Long

    ' Get the window's title.
    length = GetWindowText(app_hwnd, buf, Len(buf))
    title = Left$(buf, length)

    ' See if the title ends with " - Notepad".
    If Right$(title, 10) = " - Notepad" Then
        ' This is it. Find the ComboBox information.
        str = EditInfo(app_hwnd)

        ' Stop searching.
        EnumProc = 0
    Else
        ' Continue searching til find it.
        EnumProc = 1
    End If
End Function



****FORM CODE****

Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal lParam As Long) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
   
Const BalloonOn = 1
Const SizeToText = 2
Const AutoHide = 4
Const AutoPace = 8

Public genie As IAgentCtlCharacterEx
Dim geniePath As String


Private Sub Form_Load()
    Dim DirName As String
    DirName = GetWindowsDir()
    geniePath = DirName + "msagent\chars\Genie.acs"
   
    Set genie = Nothing
   
    MyGenie.Characters.Load "CharacterID", geniePath
    Set genie = MyGenie.Characters("CharacterID")
    genie.LanguageID = &H409  ' english
    genie.SoundEffectsOn = True
    genie.Balloon.Style = genie.Balloon.Style Or BalloonOn
    genie.Balloon.Style = genie.Balloon.Style Or AutoHide
    genie.Balloon.Style = genie.Balloon.Style Or AutoPace
    genie.Balloon.Style = genie.Balloon.Style Or SizeToText
   
    genie.Commands.RemoveAll
    genie.Commands.Add "AdvCharOptions", "&Advanced Character Options"
   
    genie.Left = (Form1.Left + 4500) / Screen.TwipsPerPixelX
    genie.Top = (Form1.Top + 1500) / Screen.TwipsPerPixelY
   
    genie.Show
    EnumWindows AddressOf EnumProc, 0
    genie.Speak str
End Sub

Function GetWindowsDir() As String
    Dim temp As String
    Dim retval As Long
    Const MAX_LENGTH = 145

    temp = String$(MAX_LENGTH, 0)
    retval = GetWindowsDirectory(temp, MAX_LENGTH)
    temp = Left$(temp, retval)
    If temp <> "" And Right$(temp, 1) <> "\" Then
        GetWindowsDir = temp & "\"
    Else
        GetWindowsDir = temp
    End If
End Function




I used genie as you can see and he said what was in my open Notepad window upon the form load event.



0
 

Author Comment

by:Jubel
ID: 2795191
Thanks for your help. I have been trying to do that since I started using agent in my programs.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now