hello gingemyboy just told me that what i need help for is api :D :duck:
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!
Printable View
hello gingemyboy just told me that what i need help for is api :D :duck:
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!
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...)
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:
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As Int32 Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _ ByVal hWnd1 As Int32, _ ByVal hWnd2 As Int32, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Int32 Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _ ByVal hwnd As Int32, _ ByVal wMsg As Int32, _ ByVal wParam As Int32, _ ByVal lParam As String) As Int32 Public Const WM_SETTEXT As Long = &HC Public Const WM_GETTEXT As Long = &HD
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...VB Code:
'IMWindowClass is the class name of a Private message window 'UserID - Conversation is the title of the messenger window, replace the userid 'with the userid you wish to test it on Dim MainWindow As Integer = FindWindow("IMWindowClass", "UserID - Conversation") MsgBox(MainWindow) 'should be a positive value if found Dim ChildWindow As Integer = FindWindowEx(MainWindow, 0, "DirectUIHwnd", "") MsgBox(ChildWindow) 'should be a positive value if found 'below, only sets the title text of the DirectUIHwnd class in the window (and isnt displayed anywhere, 'but viewable in WinID or SPY++ SendMessage(ChildWindow, WM_SETTEXT, 0, "Test")
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
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...Quote:
Originally Posted by frix199
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)
tnx, but how do i change the text of the input window???(in yahoo)
i try to find it out but nothing...
thanks!
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...
i made this:
VB Code:
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As Int32 Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _ ByVal hWnd1 As Int32, _ ByVal hWnd2 As Int32, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Int32 Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _ ByVal hwnd As Int32, _ ByVal wMsg As Int32, _ ByVal wParam As Int32, _ ByVal lParam As String) As Int32 Public Const WM_SETTEXT As Long = &HC Public Const WM_GETTEXT As Long = &HD Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'IMWindowClass is the class name of a Private message window 'UserID - Conversation is the title of the messenger window, replace the userid 'with the userid you wish to test it on Dim MainWindow As Integer = FindWindow("IMClass", "kulrom - Instant Message") MsgBox(MainWindow) Dim ChildWindow As Integer = FindWindowEx(MainWindow, 0, "YIMInputWindow", "") MsgBox(ChildWindow) 'below, only sets the title text of the DirectUIHwnd class in the window (and isnt displayed anywhere, 'but viewable in WinID or SPY++ SendMessage(ChildWindow, WM_SETTEXT, 0, TextBox2.Text) End Sub
it finds the main window, but not the child... whats wrong?
thanks
For an extra cookie, check out this post :thumb:
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)...
yea but why do i see an YIMInputWindow and not those html things?
am i doing something wrong?
thanks
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...
After that, it should be positive, and should send the text to the window when you call sendmessage...VB Code:
Dim ChildWindow As Integer = win32.FindWindowEx(MainWindow, 0, "YIMInputWindow", vbNullString)
thanks...
but how can i click a button?
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.
pulbilc const WM_LBUTTONUP = ???
pulbilc const WM_LBUTTONDOWN = ???
:D
Public Const WM_LBUTTONDOWN As Long = &H201
Public Const WM_LBUTTONUP As Long = &H202
^this?
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....
SendMessage(ChildWindow, WM_LBUTTONDOWN, 0, "")
SendMessage(ChildWindow, WM_LBUTTONUP, 0, "")
this^???
well it doesnt workhttp://www.vbforums.com/images/ieima...chmentid=37819
Try vbnullstring instead of "" .... see if that helps any
o yea tnx :D
Good deal :) glad you got it working...