Sep 24th, 2005, 07:13 AM
#1
Thread Starter
Fanatic Member
Send text to other programs [RESOLVED]
Is it possible to send text to fill boxes, clicks to check options and some way to press buttons in other program. Would that be possible? If yes, how would i?
I'v tryed sendkeys but it didn't worked as i wanted to.
Thanks
Last edited by TDQWERTY; Sep 24th, 2005 at 09:53 AM .
Sep 24th, 2005, 07:30 AM
#2
Fanatic Member
Re: Send text to other programs
You should be able to do this with the SendMessage API, do a search with google, or search http://www.pscode.com/vb
Sep 24th, 2005, 07:37 AM
#3
Fanatic Member
Re: Send text to other programs
If you find a solution to your problem, please let me know as I am also interested in this.
Sep 24th, 2005, 08:31 AM
#4
Re: Send text to other programs
You could try DDE (Dynamic Data Exchange). People on here say its old, but it still works.
Attached Files
Last edited by Keithuk; Sep 26th, 2005 at 03:06 PM .
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Sep 24th, 2005, 08:32 AM
#5
Fanatic Member
Re: Send text to other programs
I think I might have an answer for you using SendMessage, check it out here: http://www.vbforums.com/showthread.php?t=36212
Sep 24th, 2005, 09:14 AM
#6
Thread Starter
Fanatic Member
Re: Send text to other programs
the findwindow() doesn't find the window i'm looking for and the window title is correct..
With notepad it works just fine!
I'v tryed with:
"MSN Messenger"
"Mozilla Firefox"
And some others...
Last edited by TDQWERTY; Sep 24th, 2005 at 09:20 AM .
Sep 24th, 2005, 09:18 AM
#7
Sep 24th, 2005, 09:22 AM
#8
Thread Starter
Fanatic Member
Re: Send text to other programs
I'm using one that i'v found on psc:
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
Private Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessageLONG Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_SETTEXT = &HC
Private Const EM_GETLINECOUNT = &HBA
Private Sub CMDOPEN_Click()
Shell "notepad.exe"
End Sub
Private Sub tmrVirus_Timer()
Dim lNotepadHwnd As Long
Dim lNotepadEdit As Long
Dim sCaption As String
lNotepadHwnd = FindWindow("Notepad", vbNullString)
lNotepadEdit = FindWindowEx(lNotepadHwnd, 0&, "Edit", vbNullString)
If lNotepadHwnd Then
lblStatus.Caption = "Open"
Else
lblStatus.Caption = "Closed"
End If
SendMessageSTRING lNotepadHwnd, WM_SETTEXT, 256, "How does it feel?"
SendMessageSTRING lNotepadEdit, WM_SETTEXT, 256, "I told you so!"
End Sub
It works fine on notepad...but not in other apps such as msn messenger or firefoz or whatever
At this moment i would be happy to fin my own project app opened
Last edited by TDQWERTY; Sep 24th, 2005 at 09:34 AM .
Sep 24th, 2005, 09:35 AM
#9
Fanatic Member
Re: Send text to other programs
You need to change
VB Code:
lNotepadEdit = FindWindowEx(lNotepadHwnd, 0&, "Edit", vbNullString)
Replace "Edit" with the class of the control inside the prog
Sep 24th, 2005, 09:36 AM
#10
Thread Starter
Fanatic Member
Re: Send text to other programs
i don't know why but i can't add the attachement.
copy/paste in a *.frm file
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3945
ClientLeft = 60
ClientTop = 390
ClientWidth = 9600
LinkTopic = "Form1"
ScaleHeight = 3945
ScaleWidth = 9600
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "Command3"
Height = 495
Left = 6840
TabIndex = 11
Top = 2760
Width = 1935
End
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 495
Left = 3840
TabIndex = 10
Top = 2760
Width = 1935
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 720
TabIndex = 9
Top = 2760
Width = 1935
End
Begin VB.CheckBox Check3
Caption = "Check3"
Height = 375
Left = 5640
TabIndex = 8
Top = 1920
Width = 1575
End
Begin VB.CheckBox Check2
Caption = "Check2"
Height = 375
Left = 4200
TabIndex = 7
Top = 1920
Width = 1575
End
Begin VB.CheckBox Check1
Caption = "Check1"
Height = 375
Left = 2520
TabIndex = 6
Top = 1920
Width = 1575
End
Begin VB.TextBox Text3
Height = 375
Left = 6600
TabIndex = 5
Top = 240
Width = 2655
End
Begin VB.TextBox Text2
Height = 375
Left = 3360
TabIndex = 4
Top = 240
Width = 2655
End
Begin VB.TextBox Text1
Height = 375
Left = 120
TabIndex = 3
Top = 240
Width = 2655
End
Begin VB.OptionButton Option3
Caption = "Option3"
Height = 255
Left = 5640
TabIndex = 2
Top = 1320
Width = 1575
End
Begin VB.OptionButton Option2
Caption = "Option2"
Height = 255
Left = 4200
TabIndex = 1
Top = 1320
Width = 1575
End
Begin VB.OptionButton Option1
Caption = "Option1"
Height = 255
Left = 2520
TabIndex = 0
Top = 1320
Width = 1575
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
End Sub
Sep 24th, 2005, 09:37 AM
#11
Thread Starter
Fanatic Member
Re: Send text to other programs
Originally Posted by
shirazamod
You need to change
VB Code:
lNotepadEdit = FindWindowEx(lNotepadHwnd, 0&, "Edit", vbNullString)
Replace "Edit" with the class of the control inside the prog
But it can't even find the window...the problem is before that
I get lNotepadHwnd = 0 always
Sep 24th, 2005, 09:51 AM
#12
Fanatic Member
Re: Send text to other programs
There is no code in the form you submitted, just controls.
Do you have the Class of the window?
Sep 24th, 2005, 09:52 AM
#13
Thread Starter
Fanatic Member
Re: Send text to other programs
I found the window using Spy++ and i needed something more to find it.
Sep 24th, 2005, 09:53 AM
#14
Thread Starter
Fanatic Member
Re: Send text to other programs
Originally Posted by
shirazamod
There is no code in the form you submitted, just controls.
Do you have the Class of the window?
No need for code in that form, i just want to fill it.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width