Results 1 to 19 of 19

Thread: [RESOLVED] text write

  1. #1

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Resolved [RESOLVED] text write

    hello gingemyboy just told me that what i need help for is api

    i want to add some text in a textbox of another application...

    i have no CLUE from api, so plz explain from the beggining...

    bibi!


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: text write

    Well I was using WinID to see the class name of the control where you enter the text in MSN, but something is weird.... All the controls, buttons, message window, and input window are all under the same Class, "DirectUIHwnd", as if its all drawn into one. I did something similar with a couple programs of mine with yahoo, but the input window was its own control, thus having its own unique hwnd to send the text to. Not sure how to go about it in MSN... Here's some function declarations you will need (.NET declarations...)
    VB Code:
    1. Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    2.       ByVal lpClassName As String, _
    3.       ByVal lpWindowName As String) As Int32
    4.  
    5. Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
    6.       ByVal hWnd1 As Int32, _
    7.       ByVal hWnd2 As Int32, _
    8.       ByVal lpsz1 As String, _
    9.       ByVal lpsz2 As String) As Int32
    10.  
    11. Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
    12.       ByVal hwnd As Int32, _
    13.       ByVal wMsg As Int32, _
    14.       ByVal wParam As Int32, _
    15.       ByVal lParam As String) As Int32
    16.  
    17. Public Const WM_SETTEXT As Long = &HC
    18. Public Const WM_GETTEXT As Long = &HD
    Now I tested this, and as expected, since all the controls are under the same Hwnd, the sendmessage when sending the text only changes the title of the DirectUIHwnd class shild window (and not visible unless you use Spy++ or WinID after)...
    VB Code:
    1. 'IMWindowClass is the class name of a Private message window
    2. 'UserID - Conversation is the title of the messenger window, replace the userid
    3. 'with the userid you wish to test it on
    4.         Dim MainWindow As Integer = FindWindow("IMWindowClass", "UserID - Conversation")
    5.         MsgBox(MainWindow) 'should be a positive value if found
    6.         Dim ChildWindow As Integer = FindWindowEx(MainWindow, 0, "DirectUIHwnd", "")
    7.         MsgBox(ChildWindow) 'should be a positive value if found
    8.         'below, only sets the title text of the DirectUIHwnd class in the window (and isnt displayed anywhere,
    9.         'but viewable in WinID or SPY++
    10.         SendMessage(ChildWindow, WM_SETTEXT, 0, "Test")
    Now if you run this a second time on the same window, you will get 0 for the childwindow, because the Title had changed to "Test" and is not blank. You would have to close out the window and open another...
    Last edited by gigemboy; Jan 14th, 2006 at 03:53 PM.

  3. #3

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: text write

    really tnx but this "sendmessage" wont work...
    how did you found the class it was and all this stuff?
    could you please post the code for the yahoo msngr?

    thanks
    Alex


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: text write

    Quote Originally Posted by frix199
    how did you found the class it was and all this stuff?
    I mentioned how I was using WinID. How do you know the SendMessage doesn't work? As I stated, you will not be able to view the "test" text because since everything is under the DirectUIHwnd class, the sendmessage changes the title of the class, not the text of the input window, and you cannot see this change when looking at the MSN messenger window. If you use WinID and place your cursor over the instant message window, you will see "test" reflected in the title (property) of the class window...

    As for WinID.. find it here:
    http://www.tucows.com/preview/414425

    And the yahoo code is very similar to this code. There is basically no change, except for one more FindWindowEX command to get the handle of the input control (because it is its own control which has a handle, which MSN appears to not have)
    Last edited by gigemboy; Jan 14th, 2006 at 04:37 PM.

  5. #5

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: text write

    tnx, but how do i change the text of the input window???(in yahoo)

    i try to find it out but nothing...

    thanks!


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  6. #6
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: text write

    Well what code have you done? I'm not going to write the program for you I have already given you all the tools you need, with examples...

  7. #7

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Exclamation Re: text write

    i made this:

    VB Code:
    1. Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    2.           ByVal lpClassName As String, _
    3.           ByVal lpWindowName As String) As Int32
    4.  
    5.     Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
    6.           ByVal hWnd1 As Int32, _
    7.           ByVal hWnd2 As Int32, _
    8.           ByVal lpsz1 As String, _
    9.           ByVal lpsz2 As String) As Int32
    10.  
    11.     Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
    12.           ByVal hwnd As Int32, _
    13.           ByVal wMsg As Int32, _
    14.           ByVal wParam As Int32, _
    15.           ByVal lParam As String) As Int32
    16.  
    17.     Public Const WM_SETTEXT As Long = &HC
    18.     Public Const WM_GETTEXT As Long = &HD
    19.  
    20.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    21.         'IMWindowClass is the class name of a Private message window
    22.         'UserID - Conversation is the title of the messenger window, replace the userid
    23.         'with the userid you wish to test it on
    24.         Dim MainWindow As Integer = FindWindow("IMClass", "kulrom - Instant Message")
    25.         MsgBox(MainWindow)
    26.         Dim ChildWindow As Integer = FindWindowEx(MainWindow, 0, "YIMInputWindow", "")
    27.         MsgBox(ChildWindow)
    28.         'below, only sets the title text of the DirectUIHwnd class in the window (and isnt displayed anywhere,
    29.         'but viewable in WinID or SPY++
    30.         SendMessage(ChildWindow, WM_SETTEXT, 0, TextBox2.Text)
    31.     End Sub

    it finds the main window, but not the child... whats wrong?

    thanks


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  8. #8
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: text write

    For an extra cookie, check out this post

    http://www.vbforums.com/showthread.php?t=357460

    ***EDIT - I was using the chat room window, NOT an instant message window (so never tested it out on individial private message windows)...
    Last edited by gigemboy; Jan 14th, 2006 at 05:23 PM.

  9. #9

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: text write

    yea but why do i see an YIMInputWindow and not those html things?
    am i doing something wrong?

    thanks


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  10. #10
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: text write

    those html things are something else, thats just to pull the text out of the chat room window. As for why you are getting zero, try changing the "" to vbnullstring in the parameter...
    VB Code:
    1. Dim ChildWindow As Integer = win32.FindWindowEx(MainWindow, 0, "YIMInputWindow", vbNullString)
    After that, it should be positive, and should send the text to the window when you call sendmessage...

  11. #11

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Exclamation Re: text write

    thanks...
    but how can i click a button?


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  12. #12
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: text write

    Be the same thing as you did when finding the handle to the input window. You use FindWindEX in order to find the handle to the class name and title of the control, then with that hwnd you can use SendMessage with the WM_LBUTTONDOWN and WM_LBUTTONUP constant to simulate a click.

  13. #13

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: text write

    pulbilc const WM_LBUTTONUP = ???
    pulbilc const WM_LBUTTONDOWN = ???



    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  14. #14

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: text write

    Public Const WM_LBUTTONDOWN As Long = &H201
    Public Const WM_LBUTTONUP As Long = &H202

    ^this?


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  15. #15
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: text write

    Those are right, except the "Long" type was VB6, Longs are now integers in .NET, so use this:

    Public Const WM_LBUTTONDOWN As Int32 = &H201
    Public Const WM_LBUTTONUP As Int32 = &H202

    Another program you might want to try out is APIViewer 2004 (search on google, its free). Its what I use, has a .NET mode you can switch it to, with all the .NET declarations of the API functions, as well as constants, etc... It starts up in VB6 mode, but you can change the options to start in .NET mode....

  16. #16

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: text write

    SendMessage(ChildWindow, WM_LBUTTONDOWN, 0, "")
    SendMessage(ChildWindow, WM_LBUTTONUP, 0, "")

    this^???

    well it doesnt work


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  17. #17
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: text write

    Try vbnullstring instead of "" .... see if that helps any

  18. #18

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: text write

    o yea tnx


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  19. #19
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [RESOLVED] text write

    Good deal glad you got it working...

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