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
Printable View
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
You should be able to do this with the SendMessage API, do a search with google, or search http://www.pscode.com/vb
If you find a solution to your problem, please let me know as I am also interested in this.
You could try DDE (Dynamic Data Exchange). People on here say its old, but it still works. :)
I think I might have an answer for you using SendMessage, check it out here: http://www.vbforums.com/showthread.php?t=36212
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...
Can you post the code you tried? What window is it?
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
You need to changeReplace "Edit" with the class of the control inside the progVB Code:
lNotepadEdit = FindWindowEx(lNotepadHwnd, 0&, "Edit", vbNullString)
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
But it can't even find the window...the problem is before thatQuote:
Originally Posted by shirazamod
I get lNotepadHwnd = 0 always
There is no code in the form you submitted, just controls.
Do you have the Class of the window?
I found the window using Spy++ and i needed something more to find it.
No need for code in that form, i just want to fill it.Quote:
Originally Posted by shirazamod