CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 22

Hybrid View

  1. #1
    Join Date
    May 2005
    Posts
    49

    [RESOLVED] Get Spacific text from window within a 3rd party program

    Hi Everyone,

    This has been a great rescource for me. Just reading had taught a lot.

    However, I am puzzled by a problem and if someone could help I sure appricate it.

    I have seen various threads, but nothing spacific to my problem.

    I want to write my own auto greeter program for Paltalk. (Yes that pesky chat program) I also want to write it for another chat program, and I figure if I can get something to work on paltalk, I should be able to just change the windows to look for new handles, yes?

    I have code that works perfectly fine sending text to the chat room. However, I can't seem to get anything to work on looking for spacific text and then triggering a fuction based on that text.

    *** SomeUserName has joined the group ***

    That is the trigger text.

    I want the program to be able to use a variable, most are using %S for screen name, so that it can wait for any user name like this: *** AnyUserName has joined the group *** and then trigger text to be sent, like this:
    Welcome AnyUsername to "the room they just joined" and maybe some other text after that.

    I have been asking some people who have written programs for paltalk and they dont seem to want to share this bit of code. Or even help for that matter.

    So, I turn to the gurus at CodeGuru.


    Here is my send text code that works great with some direction from people here.


    Code:
    Private Function PALSEND(Text2Send As RichTextBox, ColoredText As Boolean)

    Dim MYWindowClass As Long
    Dim wtlsplitterwindow As Long
    Dim ATLD As Long
    Dim atlaxwin As Long
    Dim X As Long
    Dim richedita As Long

    MYWindowClass = FindWindow("my window class", vbNullString)
    wtlsplitterwindow = FindWindowEx(MYWindowClass, 0&, "wtl_splitterwindow", vbNullString)
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0&, "wtl_splitterwindow", vbNullString)
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0&, "wtl_splitterwindow", vbNullString)
    ATLD = FindWindowEx(wtlsplitterwindow, 0&, vbNullString, vbNullString)
    atlaxwin = FindWindowEx(ATLD, 0&, "atlaxwin71", vbNullString)
    X = FindWindowEx(atlaxwin, 0&, "#32770", vbNullString)
    richedita = FindWindowEx(X, 0&, "richedit20a", vbNullString)
    richedita = FindWindowEx(X, richedita, "richedit20a", vbNullString)
    '>>>>>>>>>>
    If ColoredText = True Then
    Call SendMessageByString(richedita, WM_SETTEXT, 0&, Text2Send.TextRTF)
    Else
    Call SendMessageByString(richedita, WM_SETTEXT, 0&, Text2Send.Text)
    End If
    '<<<<<<<<<<
    '>>>>>>>>>>
    If richedita <> 0 Then
    Do
    DoEvents
    Call SendMessage(richedita, WM_KEYDOWN, VK_RETURN, 0)
    Call SendMessage(richedita, WM_KEYUP, VK_RETURN, 0)
    Loop Until richedita <> 0
    Else
    Exit Function
    End If
    '<<<<<<<<<<


    End Function
    Private Sub Command1_Click()

    RTB5 = (RTB1.Text & " " & RTB2.Text & ":" & RTB3.Text & " " & RTB4.Text)

    With RTB5
    .Font.Bold = True
    .Font.Size = 10
    End With

    Call PALSEND(RTB5, True)

    End Sub


    As I understand it, I need to just count back one from the input RTB to the text window above it which is where the text to watch for is located.

    I do have this code:



    Code:
    Public Function GetText()


    Dim wtlsplitterwindow As Long, atl As Long, atlaxwin As Long
    Dim X As Long, richedita As Long
    wtlsplitterwindow = FindWindow("wtl_splitterwindow", vbNullString)
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0&, "wtl_splitterwindow", vbNullString)
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0&, "wtl_splitterwindow", vbNullString)
    atl = FindWindowEx(wtlsplitterwindow, 0&, "atl:00504680", vbNullString)
    atlaxwin = FindWindowEx(atl, 0&, "atlaxwin71", vbNullString)
    X = FindWindowEx(atlaxwin, 0&, "#32770", vbNullString)
    richedita = FindWindowEx(X, 0&, "richedit20a", vbNullString)
    Dim TheText As String, TL As Long
    TL = SendMessageLong(richedita, WM_GETTEXTLENGTH, 0&, 0&)
    TheText = String(TL + 1, " ")
    Call SendMessageByString(richedita, WM_GETTEXT, TL + 1, TheText)
    TheText = Left(TheText, TL)
    End Function


    and what I wanted to do was put another command button with a text window to just press and let it grab what ever was in the text window in question and place that in the text box to make sure I was watching the right window.

    So I did this:


    Code:
    Private Sub Command2_Click()
    Call GetText

    Text1.Text = TheText

    End Sub


    But that seemed too simple.

    I also used the winspector spy and got a lot of message traffic, but I guess it must be over my head with regard to using it.

    I have found out what I needed to do with GetText.

    Now I can populate a textbox with the text from the correct window.

    Here is what I am looking for:

    I would like help for a trigger type event to watch for a spacific symbol. The "!" Or the " ***"
    This is the trigger to tell my program to run another event. Like !find (and the search string, etc) To search a database and return the results back to the chatroom.

    What api call should I use? Would it work to use some sort of timer event to watch for that particular symbol and that word?

    The window that I am watching has all sorts of text as its the main chat window for the program I would like to capture the text from.

    I had thought of useing a timer subroutine to look for new text, but wouldnt that cause a large amount of system rescources to be used? Looping and looping till the time interval is up?

    Any help would be appreciated

    Intercepter

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Get Spacific text from window within a 3rd party program

    Use the timer control. It uses very little resources, actualy near none, until the Interval has lappsed. then any code in timer sub executes..

    Hope this Helps

    Gremmy.
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    May 2005
    Posts
    49

    Re: Get Spacific text from window within a 3rd party program

    Yes that helps, Thank you.

    The problem I am running into is that with the "GetText" function it will update with the latest lines of text but it grabs everything that is in the ritchtextbox that the program is watching. From the first line to the very last one.

    What I am interested in now is the ability to grab only new text and discard everything else looking for my "!" or "***"

    So that each time the timer runs the code and resets, I am looking at new text only. Not what allready has been checked.

    I did try to use some pattern machting but it seems like there is just too much there to get the job done.

    How do I filter out what I dont need to get to what I need.

    If anyone needs properties, I can get them, but was wondering if any suggestions right off the bat.

    Intercepter.

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Get Spacific text from window within a 3rd party program

    Quote Originally Posted by intercepter
    Yes that helps, Thank you.

    The problem I am running into is that with the "GetText" function it will update with the latest lines of text but it grabs everything that is in the ritchtextbox that the program is watching. From the first line to the very last one.

    What I am interested in now is the ability to grab only new text and discard everything else looking for my "!" or "***"

    So that each time the timer runs the code and resets, I am looking at new text only. Not what allready has been checked.

    I did try to use some pattern machting but it seems like there is just too much there to get the job done.

    How do I filter out what I dont need to get to what I need.

    If anyone needs properties, I can get them, but was wondering if any suggestions right off the bat.

    Intercepter.
    Unfortunately you will have to parce out what is new and what isn't in your code. Try buy keeping a copy of the, hmm, say last 100 characters.. use the Instr to find it in the collected text.. Then start your check from there.. copy the Last 100 char back into your check string..

    This is about the best way i can think off..

    Gremmy
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  5. #5
    Join Date
    May 2005
    Posts
    49

    Exclamation Re: Get Spacific text from window within a 3rd party program

    Ok, I think I understand, but the question is how? I honestly dont know how to get the last 100 or so.

    But here is some background info that might help.

    Right now, to make sure the code that gets the text from the window I am watching, is actually getting text from the right place, I put it in a timer function like you suggested to a richtextbox on my form. But the foreign window that holds the text I want to process has a rather large capacity.

    At least count, it could hold over 1700 lines of text and is consistently updating to add new lines. What I want to do is search through the text parse out the new line or lines that were added since the last tine through the timer sub and check to see if a particular set of characters are present. I am looking for ": !ver" or ": ***"

    This is a chat room watching program and is looking for the above strings and to trigger other events.

    The foreign richtextbox is again at least 1700 lines long or longer and each line can hold 113 characters per line (in full screen mode) and 46 characters per line (in windowed mode)

    The user can actually put up to 443 characters per post before they get an overflow message saying the post is too long.
    If more than the max amount in each line (either 46 or 113) is reached, it simply word wraps till the text is finished.

    This code gets the text from the window that is being watched:


    Code:Private Sub Command2_Click()
    Dim TheText As String, TL As Long
    Dim mywindowclass As Long
    Dim wtlsplitterwindow As Long
    Dim atl As Long
    Dim atlaxwin As Long
    Dim x As Long
    Dim richedita As Long

    mywindowclass = FindWindow("my window class", vbNullString)
    wtlsplitterwindow = FindWindowEx(mywindowclass, 0&, "wtl_splitterwindow", vbNullString)
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0&, "wtl_splitterwindow", vbNullString)
    wtlsplitterwindow = FindWindowEx(wtlsplitterwindow, 0&, "wtl_splitterwindow", vbNullString)
    atl = FindWindowEx(wtlsplitterwindow, 0&, "atl:00504680", vbNullString)
    atlaxwin = FindWindowEx(atl, 0&, "atlaxwin71", vbNullString)
    x = FindWindowEx(atlaxwin, 0&, "#32770", vbNullString)
    richedita = FindWindowEx(x, 0&, "richedit20a", vbNullString)
    TL = SendMessageLong(richedita&, WM_GETTEXTLENGTH, 0&, 0&)
    TheText = String(TL + 1, " ")
    Call SendMessageByString(richedita&, WM_GETTEXT, TL + 1, TheText)
    TheText = Left(TheText, TL)

    If richedita = 0 Then
    MsgBox "Error: Cannot find window"
    Exit Sub
    End If


    RichTextBox1.Text = TheText


    End Sub

    But it gets ALL the text in the foreign window.

    I need some help going through it to only return anything new after last time through the timer sub.

    I put this code in a timer sub, and it dutifully updates the richtextbox with everything that was posted when the program was started and it began its watch on the window.

    I would still like to put text in the richtextbox on my form as well as allowing it to trigger another sub. Just to watch it work properly before I move on.

    From your last post, I need to use some sort of InStr function but quite honestly, I don't know where to start. I am still learning and any code suggestions would be appreciated.

    The varible "TheText" seems to be able to hold whatever I get from the other window.

    Intercepter

  6. #6
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Get Spacific text from window within a 3rd party program

    Quote Originally Posted by intercepter
    Ok, I think I understand, but the question is how? I honestly dont know how to get the last 100 or so.
    Here is a function i quickly wrote to help you with this.. It may need a little debug( Mostly a +1 or -1 in the Mid function..
    Code:
    Private Prev_100 As String
    Private Function Get_Last_Text(New_Text As String) As String
    Dim S_Pos As Long
    Dim S_Len As Long
    S_Len = Len(New_Text)
    S_Pos = InStr(1, New_Text, Prev_100, vbTextCompare)
    If S_Pos > 0 Then
        S_Pos = S_Pos + Len(Prev_100) ' Add the length of the previous to get start of new text
        Get_Last_Text = Mid(New_Text, S_Pos, S_Len - S_Pos)
    Else
        Get_Last_Text = New_Text
    End If
    If S_Len > 100 Then
        Prev_100 = Right(New_Text, 100)
    Else
        Prev_100 = New_Text
    End If
    End Function
    Try this in your proggy..

    1) Get all the text from the Chat..
    2) Call this function to parse out the Last entered text..
    3) Scan the last enterd text for your 'Triggers'


    Gremmy...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  7. #7
    Join Date
    May 2005
    Posts
    49

    Smile Re: Get Spacific text from window within a 3rd party program

    Hi Gremmy,

    Here is the final project. Let me know what else I might need to add or change. It should all be ado code.

    The question is, what am I missing?

    Intercepter
    Attached Files Attached Files

  8. #8
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Get Spacific text from window within a 3rd party program

    Quote Originally Posted by intercepter
    Hi Gremmy,

    Here is the final project. Let me know what else I might need to add or change. It should all be ado code.

    The question is, what am I missing?

    Intercepter
    I like your Code.. just a few things.. use Tab spacing in your code
    Code:
    Select Case asxToolbar2.ButtonChecked(ButtonIndex)
    Case Is = asxToolbar2.ButtonChecked(1) = True
    RichTextBox3.SelFontSize = 8
    Case Is = asxToolbar2.ButtonChecked(2) = True
    RichTextBox3.SelFontSize = 10
    Case Is = asxToolbar2.ButtonChecked(3) = True
    RichTextBox3.SelFontSize = 12
    End Select
    looks ok but formating it
    Code:
    Select Case asxToolbar2.ButtonChecked(ButtonIndex)
        Case Is = asxToolbar2.ButtonChecked(1) = True
            RichTextBox3.SelFontSize = 8
        Case Is = asxToolbar2.ButtonChecked(2) = True
            RichTextBox3.SelFontSize = 10
        Case Is = asxToolbar2.ButtonChecked(3) = True
            RichTextBox3.SelFontSize = 12
    End Select
    makes it easier for you to keep track... If for eg. you left out End Select, it would be very dificult to notice...

    You have a few pieces of unused code still stuck in the project, When compiling this is still added and just Bloats and slows your app...
    Code:
    (IN adoPrimaryRS_WillChangeRecord)
    Select Case adReason
      Case adRsnAddNew
      Case adRsnClose
      Case adRsnDelete
      Case adRsnFirstChange
      Case adRsnMove
      Case adRsnRequery
      Case adRsnResynch
      Case adRsnUndoAddNew
      Case adRsnUndoDelete
      Case adRsnUndoUpdate
      Case adRsnUpdate
    End Select
    
    Private Function Get_Last_Text(New_Text As String) As String         (This sub Is never called.)
    A feture you might consiider adding is Random Quotes... Most Religious people (Myself included) belive more in Accidental, or Randomly found Bible verses... (My wife opens the bible at random every morning and we read a few verses.). Adding this will definately give value to its use..

    Other than these The coding looks good.. (Unfortunatly i cannot Run it as I'm missing the DB...)

    but it's good work..

    keep it up..

    Gremmy....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  9. #9
    Join Date
    May 2005
    Posts
    49

    Thumbs up Re: Get Spacific text from window within a 3rd party program

    Thanks Gremmy,

    You have yourself and Pinkey98 to also give cudos for it. As you 2 helped quite a bit. If not in actual code snippets, in direction as well.

    My main concern was that all the db opens and closes looked fine and that everything required to run ado code is all there.

    I will be adding you 2 to the credits window that I will add.

    I like your suggestion. I have had tons of ideas on what else I would like to see this program do but I wanted to get something that functions first, before I go tweaking it. I had a basic list of what I wanted the program to do first before adding any more bells or whistles.

    Again, thanks for your help and if you want the db, when I find the link where I found it, I will send it to ya.

    Intercepter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured