Make a project using below code. Compile it and call it SendKeysA.exe
Code:
Dim ReturnValue As Long
Private Sub Cpmmand1_Click()
ReturnValue = Shell(App.Path & "\SendKeysB.exe", 1)
End Sub
Private Sub Command2_Click()
AppActivate ReturnValue
SendKeys "Hello from program A" & vbCrLf
Exit Sub
MsgBox "Press OK to do a Ctrl+M - " & Chr(34) & "^M" & Chr(34)
SendKeys "^M", True ' Send Ctrl + M
MsgBox "Press OK to do a Ctrl+M - " & Chr(34) & "^(M)" & Chr(34)
SendKeys "^(M)", True ' Send Ctrl + M
MsgBox "Press OK to do a Alt+S - " & Chr(34) & "%S" & Chr(34)
SendKeys "%S", True ' Send Alt + S
MsgBox "Press OK to do a Alt+S - " & Chr(34) & "%(S)" & Chr(34)
SendKeys "%(S)", True ' Send Alt + S
End Sub
Now make another project and put a Text1 on it. Compile it and call it SendKeysB.exe
Run SendKeysA.exe only. Click on Command1. SendKeysB.exe will be launched. Now click on Command2.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Also, is the other program Calcu a VB project and you have access to it? If yes then just make it invisible.
However, hiding or making invisible could have adverse effects depending on what is taking place
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
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 SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_SETTEXT = &HC
Private Const BM_CLICK = &HF5
Private Const WM_SETFOCUS = &H7
Private Sub Command1_Click()
Dim PID As Long
Dim EDITX As Long
PID = FindWindow(vbNullString, "exact words on the titlebar of other application")
EDITX = FindWindowEx(PID, 0&, "t", vbNullString)
If PID Then
'
' If here then text will be sent to the titlebar
'
Call SendMessageByString(PID, WM_SETTEXT, 0, "BOO!")
Else
If EDITX Then
'
' If here then text will be sent to the textbox
'
Call SendMessageByString(EDITX, WM_SETTEXT, 0, "Hello from another application")
Else
Call SendMessageByString(EDITX, BM_CLICK, 0, "Send Some")
End If
End If
End Sub
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Just change the title of the other program from "Calcu" to "BOO!"
Note: "Calcu" program have a blank textbox but i don't know which tab it lay on
Note: if you could help me to sendkeys to that program, that will be better
Just change the title of the other program from "Calcu" to "BOO!"
I was just presenting that sample as an example and not necessarily an answer to your problem
Note: "Calcu" program have a blank textbox but i don't know which tab it lay on
Note: if you could help me to sendkeys to that program, that will be better
I do not have an application with a titlebar that says Calcu
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
There are two projects in the zip file. One is called App1 and the other App2. App1 is the target application and App2 is the application that sends messages to App1.
After you unzip, load App1 project into VB and run it. Now load App2 into another VB project and run it. You will see App1 in the small textbox. Click the button below it. This puts all of the objects from App1 in the list. Click on any listing and then click one or more of the other two buttons.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Did you change the text in Textbox1 from App1 to Calcu?
I tested it with Calculator, and a few other misc applications running and it worked in all cases.
Last edited by jmsrickland; May 26th, 2011 at 09:59 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
It depends on the application and what you want to do. For example, I tried it on MS Paint and the only thing I could do was to change the titlebar and the status line.
What is Calcu, anyway? If I had a copy of it I could test. Maybe the App2 program does not have the correct features (API calls, for example) to perform on Calcu. Here's anothe thing the program App2 only gets the object's handles from the top level and there are more but I didn't go down that deep. It gets more complex to do that. Everything on a program has a handle but you need to know a few things about the application so as to know what handles you need.
One thing you can do is to run Calcu then run SpyXX (I think that is part of VB or Visual Studio). Using SpyXX you can get down to all of the handles. Copy them down. Now, do not close Calcu (if you do the handles are no longer any good) but while it is still running you can hard code these handles into the source of App2 and see what you can do with them.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Yes it worked with calculator and i tried some programs and it works perfectly
but with "Calcu" it give nothing
maybe because "Calcu" built in c++ ? or it doesn't matter ??
All applications that run on Windows are assigned a handle number. Objects on a Form like buttons, textboxes, pictureboxes, list boxes, treeviews, listviews, everything (well, maybe not WinSock, for example) has a handle. Even menu have handles and they in turn have sub-menu items that also have handles. The small example I posted for you only deals with the very top-most object handles; like the ones I mentioned above except it doesn't get down to the other handles like menu handles.
Before you can start manipulating an external application by using it's handles you need to understand what these handles are in reference to and what is it you need to accompolish.
If you don't have SpyXX (or even if you do) here is an application, which goes deeper than the one I posted before, that you can use just like you would use SpyXX except here you get the source code and you can modify it to your likings until you have accompolished your task. Hope this will help.
Last edited by jmsrickland; May 28th, 2011 at 08:18 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
in "SpyXX"
it bring some handles to the program but i dont know how to use them
in "EnumAllWindows"
every program and process in the listbox1 have its full handles in listbox2 except my prog
i can just [Minimize,Maximize,Show,Hide,Change program title]
but the right listbox clear with my program only.
Maybe you should tell me what it is you want to do with Calcu and tell me how I can get a copy of it.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.