[RESOLVED] Get Spacific text from window within a 3rd party program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

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

  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

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

    Gremmy,

    Thanks for all your help so far. After I put your function in and tried to use it, I got a out of memory error.

    So I got to thinking a bit more and tried this instead:

    tmpString = TheText

    inpStr = Right(tmpString, 100)

    TheText is all the text from the window since the program started watching the window.

    I figured I would just use the Right(tmpString, 100) to grab the last 100 charecters.

    then I just directed the output to a richtextbox to see what I was getting:

    RichTextBox1.Text = inpStr

    That does what I want for the moment. However, I tried several ways to search the inpStr for what I am looking for and I am running into problems.

    It seems inStr just tells me the position of what I am looking for, and
    I cant get the Filter function to work at all.

    Here is what I tried for a Filter function:

    pMatch = ": !ver * "
    strSearch = Filter(inpStr, pMatch, vbTextCompare)

    RichTextBox1.Text = strSearch

    I want the resulting text to go to the richtextbox to just make sure I know what I am finding then I will turn around and put that into a trigger for my other code (which works without a hitch so far :-) )

    Should I be using something else? and if so, what?

    Thank you for your continued input.

    Intercepter

  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
    Gremmy,

    Thanks for all your help so far. After I put your function in and tried to use it, I got a out of memory error.

    So I got to thinking a bit more and tried this instead:

    tmpString = TheText

    inpStr = Right(tmpString, 100)
    I'm surprised it gave you that error.. Was this some time during runtime or imidiately at runtime???

    This code defeates the porpose.. if there was no update in the time-limit it will return the same string, Leading to multiple triggers..

    Quote Originally Posted by intercepter
    However, I tried several ways to search the inpStr for what I am looking for and I am running into problems.

    It seems inStr just tells me the position of what I am looking for, and
    I cant get the Filter function to work at all.

    Here is what I tried for a Filter function:

    pMatch = ": !ver * "
    strSearch = Filter(inpStr, pMatch, vbTextCompare)

    RichTextBox1.Text = strSearch

    I want the resulting text to go to the richtextbox to just make sure I know what I am finding then I will turn around and put that into a trigger for my other code (which works without a hitch so far :-) )
    Not quite sure is the filter function working or not ???

    Zip and post your project then i can get a good look at it...

    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

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

    Gremmy,

    I figured out what I did wrong. I used TheText in that sub instead of trimming it down. TheText is the holder for all the text in the room. And as the sub was running, it was getting bigger and bigger. So, I ran out of memory after it had been running a while.

    So, I am going to try your sub with the right() command to see if it works.

    And it had some odd actions when I tried it with the right() command.

    Here is the code we are dealing with:

    Code:
    Private Sub Timer1_Timer()
    
    Timer1.Interval = 1000
    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
    Dim strSearch, tmpString, pMatch, inpStr As String
    Dim MyLen
    
    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
    
    
    'pMatch = ": !ver * "
    'strSearch = Filter(inpStr, pMatch, vbTextCompare)
    
    Call Get_Last_Text(TheText)
    
    
    End Sub
    
    
    
    Private Function Get_Last_Text(New_Text As String) As String
    'Private prev_100 As Sting
    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
    When I just pasted the function into my code, the IDE put a divider line between
    Code:
    Private prev_100 As String
    and
    Code:
    Private Function Get_Last_Text(New_Text As String) As String
    And gave me an error: Only comments can appear after an End Sub, End Function or End Property.

    So I commented out the Private prev_100 line.

    So, I must be going about this sub all wrong. What needs to be in the () after Call Get_New_Text?

    Like I said, using "TheText" will pull everything out of the chat window that I am watching and that builds quite large.
    Last edited by intercepter; December 18th, 2005 at 01:40 AM.

  10. #10
    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
    Gremmy,

    I figured out what I did wrong. I used TheText in that sub instead of trimming it down. TheText is the holder for all the text in the room. And as the sub was running, it was getting bigger and bigger. So, I ran out of memory after it had been running a while.

    So, I am going to try your sub with the right() command to see if it works.

    ----- SNIP -------

    When I just pasted the function into my code, the IDE put a divider line between
    Code:
    Private prev_100 As String
    and
    Code:
    Private Function Get_Last_Text(New_Text As String) As String
    And gave me an error: Only comments can appear after an End Sub, End Function or End Property.

    So I commented out the Private prev_100 line.

    So, I must be going about this sub all wrong. What needs to be in the () after Call Get_New_Text?

    Like I said, using "TheText" will pull everything out of the chat window that I am watching and that builds quite large.
    Move this
    Code:
    Private prev_100 As String
    to the Top -- Under declarations. Then the function should work...

    If you still get 'Out of Memory Errors' then we can look into putting the function into a class module and making a Dll out of it .. This puts it in its own memory allocation and Effectively Doubles the Availalable memory used for variables.. I remember reading somewhere that VB has a limit of 64K for declared variable's.. cant find the quote right now..

    If we split into two we can get 128K...

    But try the above first..

    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.

  11. #11
    Join Date
    May 2005
    Posts
    49

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

    Hi Gremmy,

    Yep the changes you suggested made it work just fine.

    And here is the line in that function that I had to make 1 minor change.

    Code:
    S_Len = Len(New_Text) + 1
    Then it sized up nicely. I ran the program for an hour and no memory errors. So that looks great.

    Now, this little tidbit, works at finding what I am looking for as far as the trigger text. pMatch is the pattern that I want to match with the instr code.

    Code:
    'Finds the command trigger
    pMatch = "!ver "
    
    cmdPos = InStr(1, Prev_100, pMatch, vbBinaryCompare)
    If cmdPos = 0 Then Exit Sub
    
    'this stripes out the matching trigger and just grabs the text I want
    cmdVer = Trim$(Right$(Prev_100, (100 - cmdPos) - 4))
    But the problem I am having now is, I see 2 Squares at the end of the string I want to send to the search function. This is in the ide when I look at the code and hover the mouse pointer over the string container.

    I cant tell if they are chr(13) or (10) or what. But if I put the string into a richtextbox, I dont see anything out of the ordinary. Otherwise when I put the string into a textbox, I see 2 vertial bars that extend down past the bottom of the line.

    Any idea on how to figure out what these 2 squares represent? Remember that I am watching a richtextbox in the other program.
    Each text break has these 2 squares in the whole string, so I am guessing they might be vbcr or crlf. But I cant tell for sure. Not without just trial and error on all the chr strings that dont have a graphic representation anyway.

    Here is a screen shot. The top box is a RichTextBox and the bottom box is a regular text box.

    See the 2 lines at the end?
    Attached Images Attached Images  
    Last edited by intercepter; December 20th, 2005 at 01:03 PM.

  12. #12
    Join Date
    May 2005
    Posts
    49

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

    Hi Gremmy,

    Actually that is a non issue. I was able to get the projcet to work and even added some error code.

    But I guess I found one problem, that is the program doesnt keep its focus on the window I am waching.

    I am using a bunch of api stuff to watch this window, and was wondering if you knew how to set in code a forced watch on the room?

    I keep focus by just keeping the OS focus on the watched chat program.

    Any ideas?

    Intercepter

  13. #13
    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
    Now, this little tidbit, works at finding what I am looking for as far as the trigger text. pMatch is the pattern that I want to match with the instr code.

    Code:
    'Finds the command trigger
    pMatch = "!ver "
    
    cmdPos = InStr(1, Prev_100, pMatch, vbBinaryCompare)
    If cmdPos = 0 Then Exit Sub
    
    'this stripes out the matching trigger and just grabs the text I want
    cmdVer = Trim$(Right$(Prev_100, (100 - cmdPos) - 4))
    But the problem I am having now is, I see 2 Squares at the end of the string I want to send to the search function. This is in the ide when I look at the code and hover the mouse pointer over the string container.

    I cant tell if they are chr(13) or (10) or what. But if I put the string into a richtextbox, I dont see anything out of the ordinary. Otherwise when I put the string into a textbox, I see 2 vertial bars that extend down past the bottom of the line.

    Any idea on how to figure out what these 2 squares represent?
    Okay a few little things i noticed now .. Dont use Call Get_Last_Text(TheText)Rather use
    Code:
    New_text = Get_last_Text(TheText)
    
    ' and in your code use
    
    cmdPos = InStr(1, New_Text, pMatch, vbBinaryCompare)
    If cmdPos = 0 Then Exit Sub
    With your Locked focus problem.. your code your looking up the window handle every time the timer ticks.. Rather look for the Handle in your form _load sub and use it in the timer_tick event.. using it this way it will find whichever window that matches the criteria in Z order check out M$ MSDN info on findwindowex

    The two 'Boxs' Could be Null chars.. 'Char (0)'... Not too sure.. but you can trim them off if need be...

    Hope This Helps..


    Gremmy...
    Last edited by GremlinSA; December 22nd, 2005 at 03:10 PM.
    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.

  14. #14
    Join Date
    May 2005
    Posts
    49

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

    Hi Gremmy,

    Believe it or not, this code works:

    Code:
    Private Sub Timer1_Timer()
    
    On Error GoTo Timer1Err
    
    Timer1.Interval = 700
    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
    Dim strSearch, tmpString, pMatch, inpStr, cmdVer, mVerse, txtRoom As String
    Dim Book, Chapter, Verse As String
    Dim Book1 As Variant
    Dim SQLStr
    Dim db1 As Database
    
    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
          Label1.Caption = "Please Join A Paltalk Chatroom"
          Exit Sub
       End If
    
    
    Get_Last_Text (TheText)
    RichTextBox1.Text = Prev_100
    
    'Find the command trigger
    pMatch = "!ver "
    
    cmdPos = InStr(1, Prev_100, pMatch, vbBinaryCompare)
    If cmdPos = 0 Then Exit Sub
    
    cmdVer = Trim$(Right$(Prev_100, (100 - cmdPos) - 4))
    If cmdVer = 0 Then Exit Sub
    
    RichTextBox2.Text = RTrim(cmdVer)
    Text1.Text = RTrim(cmdVer)
    
    'I always UCASE and TRIM all user inputs to avoid unexpected errors creeping in
    userselectedverse = UCase$(Trim$(cmdVer))
    tmpString = userselectedverse
    
    'Get the first space
    SpacePos = InStr(1, userselectedverse, " ", vbBinaryCompare)
    If (SpacePos = 0) Then Exit Sub
    
    'Get the book name
    Book = Trim$(Left$(userselectedverse, SpacePos - 1))
    
    'Get the chapter and verse
    ChapterAndVerse = Trim$(Mid$(userselectedverse, SpacePos + 1))
    
    'Split the chapter and verse
    For i = 1 To Len(ChapterVerseSeperators)
        BreakPos = InStr(1, ChapterAndVerse, Mid$(ChapterVerseSeperators, i, 1))
        If BreakPos <> 0 Then Exit For
    Next i
    If (BreakPos = 0) Then Exit Sub
    
    Chapter = Left$(ChapterAndVerse, BreakPos - 1)
    Verse = Mid$(ChapterAndVerse, BreakPos + 1)
    
    
    
    SQLStr = "Select tblBOOK.Book_ID,tblBOOK.Book_Title From tblBOOK Where (tblBOOK.Book_Title = '" & Book & "') Order By tblBOOK.Book_ID "
    
    Set db1 = OpenDatabase(App.Path & "\kjvbible.mdb")
    Set Recordset = db1.OpenRecordset(SQLStr)
    
    Book1 = (Recordset.Fields(0))
    
    ' Close RecordSet and Database
    Recordset.Close
    db1.Close
    
    
    datPrimaryRS.Recordset.MoveFirst
    datPrimaryRS.Recordset.Find "tblQUOTE.Book_ID = " & Book1 & " ", 0, adSearchForward
    datPrimaryRS.Recordset.Find "Chapter = " & Chapter & " ", 0, adSearchForward
    datPrimaryRS.Recordset.Find "Verse = " & Verse & " ", 0, adSearchForward
    
    RTB5 = (RTB1.Text & " " & RTB2.Text & ":" & RTB3.Text & " " & RTB4.Text)
    
    With RTB5
         .Font.Bold = True
         .Font.Size = 14
    End With
    
    Call PALSEND(RTB5, True)
    datPrimaryRS.Recordset.MoveFirst
    Exit Sub
    
    Timer1Err:
        Err.Description = " :-( Can't Find The Verse, Please Check Your Spelling Or Include The Whole Book Name And Spaces Between Ver & Book.  Please Try Again :-("
        RTB5 = Err.Description
        'If tmpString = userselectedverse Then Exit Sub
        With RTB5
             .Font.Bold = True
             .Font.Size = 20
        End With
        Call PALSEND(RTB5, True)
    cmdVer = ""
    RichTextBox2.Text = userselectedverse
    Text1.Text = ""
    
    End Sub
    I have placed an extra richtextbox and regular textbox just to watch the information that comes in.

    Now, this was some very minor changes that from what you had suggested a while back.

    I am surpised that it works. And with the little error trapping that I did, I can catch most of the typical errors from a user.

    I also just tried to put the section of code into a function that checks for the window, however, I dont know what to make the arguments. (I am still learning)

    Here is the function:


    Code:
    Public Function GetTheText()
    
    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 Function
    End If
    
    txtRoom = TheText
    
    
    End Function
    And when I try to call this, I get datatype mismatch errors.

    So, I guess, it basically works but this function does not.

    Would you suggest doing this as a public function or private function. I know the difference between the two, just wondering which is better. Also, what should I put for the arguments for the function? It works as part of the sub, but not as a stand alone function.

    Or maybe I am missing all this from a mile away.

    Oh, and btw, the squares have no effect on the lookup code for the database so, I am not even going to worry about them. :-)
    Last edited by intercepter; December 23rd, 2005 at 01:55 AM.

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

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

    I'm quite surpised that it works.. Well it will work to a certain extent.. If activity is a bit more than 100 chars this could miss a request.. if activity is slow it will retrigger on the request.. If 2 or more requests are sent you will only responed to the first one..

    If posible zip and post your entire project (with'Manage Attachements in the post window..)

    i will look at it, Make the relavant changes & fixes, and repost it for you...


    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.

Page 1 of 2 12 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)