• 0

[VB.net] Copy textbox value into IM


Question

I was wondering whether it is possible to say make a function that would take a value from a textbox and paste it into textboxes of other programs such as an Instant Messenger.

So if I typed "hello world" in my vb program it would copy that value and in my Instant Messaging program it would also say "hello world"

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Yes it's possible... let's see if I can dig up an example in VB6 for AIM 5.X

Option Explicit

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Public Const WM_SETTEXT = &HC
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202

Public Function Chat(Message As String)
On Error Resume Next

Dim aimchatwnd As Long
Dim wndateclass As Long
Dim ateclass As Long
Dim oscariconbtn As Long
Dim iLoop

aimchatwnd& = FindWindow("aim_chatwnd", vbNullString)
wndateclass& = FindWindowEx(aimchatwnd&, 0&, "wndate32class", vbNullString)
ateclass& = FindWindowEx(wndateclass&, 0&, "ate32class", vbNullString)
wndateclass& = FindWindowEx(aimchatwnd&, wndateclass&, "wndate32class", vbNullString)
SendMessageByString wndateclass&, WM_SETTEXT, 0, Message$
oscariconbtn& = FindWindowEx(aimchatwnd&, 0&, "_oscar_iconbtn", vbNullString)
For iLoop = 0 To 3 Step 1
oscariconbtn& = FindWindowEx(aimchatwnd&, oscariconbtn&, "_oscar_iconbtn", vbNullString)
Next iLoop

SendMessage oscariconbtn&, WM_LBUTTONDOWN, 0&, 0&
SendMessage oscariconbtn&, WM_LBUTTONUP, 0&, 0&

End Function

Basically you have to use the FindWindow API to find the chat box by its class name, then you can use the SendMessage API to set the text of the control and then find and click the 'Send' button...

It's a little difficult to understand how it works if you are not familiar with the Windows API. Also you will need API Spy or something similar to find out the class names, etc.

Link to comment
Share on other sites

  • 0
Lol, its good that you are being helpful ;) :p

I'm still scanning my external hard drives for the Project I have in which I did something similar... I know it's here somewhere!!!

Link to comment
Share on other sites

  • 0
I'm still scanning my external hard drives for the Project I have in which I did something similar... I know it's here somewhere!!!

Yes that would be awesome if you could give me the project as Antaris did for the other question I had... Thanks Antaris :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.