Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2006, 15:49
LaBBa LaBBa is offline
VIP
 
Join Date: Jul 2003
Posts: 150
Rept. Given: 0
Rept. Rcvd 16 Times in 4 Posts
Thanks Given: 0
Thanks Rcvd at 11 Times in 11 Posts
LaBBa Reputation: 16
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
Reply With Quote
  #2  
Old 05-23-2006, 18:33
stephenteh
 
Posts: n/a
SendMessage or SendDlgItemMessage

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/messagesandmessagequeues/messagesandmessagequeuesreference/messagesandmessagequeuesfunctions/sendmessage.asp
Reply With Quote
  #3  
Old 05-25-2006, 03:57
laola
 
Posts: n/a
Thumbs up

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...
Reply With Quote
  #4  
Old 05-25-2006, 15:10
DCA's Avatar
DCA DCA is offline
VIP
 
Join Date: Aug 2005
Posts: 137
Rept. Given: 36
Rept. Rcvd 29 Times in 13 Posts
Thanks Given: 20
Thanks Rcvd at 37 Times in 16 Posts
DCA Reputation: 29
Source vb

Hi,

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

br
DCA



-----------

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controling access to HDD Hero General Discussion 2 08-09-2006 18:13


All times are GMT +8. The time now is 09:52.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )