Exetools

Exetools (https://forum.exetools.com/index.php)
-   General Discussion (https://forum.exetools.com/forumdisplay.php?f=2)
-   -   Controling app from outside (https://forum.exetools.com/showthread.php?t=9639)

LaBBa 05-23-2006 15:49

Controling app from outside
 
Hi
i would like to know what Api are in used if i want to create an app
that would control another app..

like all of those KazaA find more sources.. they all control kazaa and sending
to it the inside command of kazaa to find more sources...

i have an app (a Dialog) that i want to send it like it was clicked on the "OK"
button

how to do so. ?
if you have source codes (VB is more then welcomed!!!) i will be more then
thankful.

LaBBa

stephenteh 05-23-2006 18:33

SendMessage or SendDlgItemMessage

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/messagesandmessagequeuesreference/messagesandmessagequeuesfunctions/sendmessage.asp

laola 05-25-2006 03:57

First get yourself a tool like Spy++ (comes with MS Visual Studio, let me know if you need a download) to find out the particular IDs in question. In general, (basically) all GUI elements are windows. To influence the behaviour of a certain control (button, checkbox, etc.), you just have to know the window handle and what message you want to send to it. You can find a list of common messages in a particular header file (let me know if you need it). This way, you can just (for example) send the button the message that the user pressed the mouse button while the mouse cursor was within the limits of the button. The application does usually not pay attention to the source of the messages it receives.
I'm not too familiar with VB (I'm rather a C++ fan *g*), but I'll see if I can find some example source.

If you want to do it completely programmatically, these are the steps:

a) Find the top-level window of the application in question
b) enumerate the child windows until you find the appropriate one
c) send it the message you want :)

I can make up some VC++/MFC sample code if you like. You will be able to find most API calls as VB definitions on the net, so that shouldn't be much of a problem...

DCA 05-25-2006 15:10

Source vb
 
Hi,

Here's an example on clicking keys for the windows calculator
Easily to adjust for your own purposes.

br
DCA

:D

-----------

VERSION 5.00
Begin VB.Form Form1
Caption = "Button Example"
ClientHeight = 3060
ClientLeft = 165
ClientTop = 735
ClientWidth = 3480
Icon = "Form1.frx":0000
LinkTopic = "Form1"
ScaleHeight = 3060
ScaleWidth = 3480
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmd_2
Caption = "2"
Height = 495
Left = 2040
TabIndex = 1
Top = 1680
Width = 495
End
Begin VB.CommandButton cmd_1
Caption = "1"
Height = 495
Left = 720
TabIndex = 0
Top = 1680
Width = 495
End
Begin VB.Label Label1
Caption = "Open the windows calculator and then press the buttons on this form to press the number one or 2 on the calculator."
Height = 975
Left = 240
TabIndex = 2
Top = 240
Width = 2895
End
Begin VB.Menu button_menu
Caption = "Menu"
Begin VB.Menu button_about
Caption = "About"
End
Begin VB.Menu button_exit
Caption = "Exit"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_1_Click()
Dim hWnd As Long ' receives handle to the found window
Dim ChildID As Long
Dim Nul As Integer
Dim lParam As Long
Dim nRtn As Long
Dim Btn As Integer, T As String, Pos As Integer
Dim Length As Integer


hWnd = FindWindow(vbNullString, "Calculator")
If hWnd = 0 Then
Debug.Print "Calculator is not running."
Else

'Now to use some apis
hWnd = GetDesktopWindow() 'Get Desktop handle
hWnd = GetWindow(hWnd, GW_Child) 'Find Child Windows of Desktop
Do
If hWnd = 0 Then Exit Do 'No (more) matches found
Length = GetWindowTextLength(hWnd) 'Find out how long the text in this window is
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(hWnd, T, Length + 1)
Pos = InStr(1, T, "Calculator", 1)
If (Pos > 0) Then
hWnd = GetWindow(hWnd, GW_Child)
Do
If hWnd = 0 Then Exit Do
Length = GetWindowTextLength(hWnd)
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(hWnd, T, Length + 1)
If InStr(UCase$(T), "1") Then
'This is the handle we want
ChildID = GetWindowLong(hWnd, GWL_ID)
Nul = SendMessage(GetParent(hWnd), WM_COMMAND, ChildID, ByVal CLng(hWnd))
Exit Sub 'Exit the do loop
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) 'Keep looking
Loop
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) 'Keep looking
Loop
End If
End Sub

Private Sub cmd_2_Click()
Dim hWnd As Long ' receives handle to the found window
Dim ChildID As Long
Dim Nul As Integer
Dim lParam As Long
Dim nRtn As Long
Dim Btn As Integer, T As String, Pos As Integer
Dim Length As Integer


hWnd = FindWindow(vbNullString, "Calculator")
If hWnd = 0 Then
Debug.Print "Calculator is not running."
Else

'Now to use some apis
hWnd = GetDesktopWindow() 'Get Desktop handle
hWnd = GetWindow(hWnd, GW_Child) 'Find Child Windows of Desktop
Do
If hWnd = 0 Then Exit Do 'No (more) matches found
'Find out how long the text in this window is
Length = GetWindowTextLength(hWnd)
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(hWnd, T, Length + 1)
Pos = InStr(1, T, "Calculator", 1)
If (Pos > 0) Then
hWnd = GetWindow(hWnd, GW_Child)
Do
'Find out how long the text in this window is
If hWnd = 0 Then Exit Do
Length = GetWindowTextLength(hWnd)
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(hWnd, T, Length + 1)
If InStr(UCase$(T), "2") Then
'This is the handle we want
ChildID = GetWindowLong(hWnd, GWL_ID)
Nul = SendMessage(GetParent(hWnd), WM_COMMAND, ChildID, ByVal CLng(hWnd))
Exit Sub 'Exit the do loop
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) 'Keep looking
Loop
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) 'Keep looking
Loop
End If
End Sub
Private Sub Form_Load()
frmSplash.Show
frmSplash.Timer1.Enabled = True
End Sub
Private Sub button_about_Click()
frmSplash.Show
End Sub

Private Sub button_exit_Click()
Unload Me
End Sub


All times are GMT +8. The time now is 18:15.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX