473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Call SendMessage API Question

Hello!

Thanx to this newgroup I have finally, with the help of you guys, gotten
this to work halfway.. but the final action is still not working, clicking
the "Button2" thru SendMessage().
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As
Long

Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As Long,
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Object) As Long

Private Const WM_KEYDOWN = &H100

Private Const WM_KEYUP = &H101

Private Const VK_SPACE = &H20

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles

hWnd = FindWindow(vbNullString, "Form1")

MsgBox("Form1: " & hWnd)

hWndbutton = FindWindowEx(hWnd, 0&, "Button2", vbNullString)

MsgBox("Button2: " & hWndbutton)

'want to send a Click to button number 2 here

MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0&) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0&))

End Sub

I get a long number from both the SendMEssage Calls.. But the Button2 is not
clicked...

Best Regards/

Lars


Nov 21 '05 #1
18 6520
I probably need to get the button2 in focus first... maybe?

"Lars Netzel" <ui****@adf.se> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
Hello!

Thanx to this newgroup I have finally, with the help of you guys, gotten
this to work halfway.. but the final action is still not working, clicking
the "Button2" thru SendMessage().
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
As Long

Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As
Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Object) As
Long

Private Const WM_KEYDOWN = &H100

Private Const WM_KEYUP = &H101

Private Const VK_SPACE = &H20

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles

hWnd = FindWindow(vbNullString, "Form1")

MsgBox("Form1: " & hWnd)

hWndbutton = FindWindowEx(hWnd, 0&, "Button2", vbNullString)

MsgBox("Button2: " & hWndbutton)

'want to send a Click to button number 2 here

MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0&) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0&))

End Sub

I get a long number from both the SendMEssage Calls.. But the Button2 is
not clicked...

Best Regards/

Lars

Nov 21 '05 #2
Hi,

The .net framework integer is the same as the old long. Change
your longs to integers. Wouldn't button2.performclick work for you?

http://msdn.microsoft.com/library/de...ClickTopic.asp

Ken
----------------------
"Lars Netzel" <ui****@adf.se> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
Hello!

Thanx to this newgroup I have finally, with the help of you guys, gotten
this to work halfway.. but the final action is still not working, clicking
the "Button2" thru SendMessage().
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
As Long

Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As
Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Object) As
Long

Private Const WM_KEYDOWN = &H100

Private Const WM_KEYUP = &H101

Private Const VK_SPACE = &H20

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles

hWnd = FindWindow(vbNullString, "Form1")

MsgBox("Form1: " & hWnd)

hWndbutton = FindWindowEx(hWnd, 0&, "Button2", vbNullString)

MsgBox("Button2: " & hWndbutton)

'want to send a Click to button number 2 here

MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0&) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0&))

End Sub

I get a long number from both the SendMEssage Calls.. But the Button2 is
not clicked...

Best Regards/

Lars

Nov 21 '05 #3
"Lars Netzel" <ui****@adf.se> schrieb:
Thanx to this newgroup I have finally, with the help of you guys, gotten
this to work halfway.. but the final action is still not working, clicking
the "Button2" thru SendMessage().
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
As Long

Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As
Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Object) As
Long
The declaration above is wrong. Use this one instead:

\\\
Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32
///

Note that 'Long' maps to 'Int64', so declares for VB.NET and VB6 cannot be
interchanged.
Private Const WM_KEYDOWN = &H100

Private Const WM_KEYUP = &H101

Private Const VK_SPACE = &H20
=> 'Private Const ... As Int32 = ...'.
MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0&) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0&))


'0&' => '0'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Yes it it would be, in the same application but I'm trying to press a button
in another applications window...

/Lars


"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

The .net framework integer is the same as the old long. Change
your longs to integers. Wouldn't button2.performclick work for you?

http://msdn.microsoft.com/library/de...ClickTopic.asp

Ken
----------------------
"Lars Netzel" <ui****@adf.se> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
Hello!

Thanx to this newgroup I have finally, with the help of you guys, gotten
this to work halfway.. but the final action is still not working,
clicking the "Button2" thru SendMessage().
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
As Long

Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As
Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Object)
As Long

Private Const WM_KEYDOWN = &H100

Private Const WM_KEYUP = &H101

Private Const VK_SPACE = &H20

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles

hWnd = FindWindow(vbNullString, "Form1")

MsgBox("Form1: " & hWnd)

hWndbutton = FindWindowEx(hWnd, 0&, "Button2", vbNullString)

MsgBox("Button2: " & hWndbutton)

'want to send a Click to button number 2 here

MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0&) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0&))

End Sub

I get a long number from both the SendMEssage Calls.. But the Button2 is
not clicked...

Best Regards/

Lars


Nov 21 '05 #5
Hi, thank you for your reply unfortunately I get an error and can't compile
now..

Since I'm using this declaration now where the first parameter is an IntPtr
instead of a long... I can't call the SendMessage() the same way anymore. I
mean, the hWndbutton variable is a Long... that's what I get back from
FindWindowEx(). How to I get this to be an IntPtr instead?

'My New declaration (as you wrote it)
Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As Int32

'My old call but with 0 instead of 0& in the last parameter.
MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0))
Value of type 'Long' cannot be converted to 'System.IntPtr'. (hWndbutton is
a Long)

Please help/Lars




Nov 21 '05 #6
"Lars Netzel" <ui****@adf.se> schrieb:
Since I'm using this declaration now where the first parameter is an
IntPtr instead of a long... I can't call the SendMessage() the same way
anymore. I mean, the hWndbutton variable is a Long... that's what I get
back from FindWindowEx(). How to I get this to be an IntPtr instead?

'My New declaration (as you wrote it)
Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As Int32

'My old call but with 0 instead of 0& in the last parameter.
MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0))
Value of type 'Long' cannot be converted to 'System.IntPtr'. (hWndbutton
is a Long)


Declare 'hWndButton' As 'IntPtr'. 'Long' is a 64-bit type and thus not
suitable.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
"Lars Netzel" <ui****@adf.se> wrote in message news:Oa****************@TK2MSFTNGP14.phx.gbl...
Hi, thank you for your reply unfortunately I get an error and can't compile
now..

Since I'm using this declaration now where the first parameter is an IntPtr
instead of a long... I can't call the SendMessage() the same way anymore. I
mean, the hWndbutton variable is a Long... that's what I get back from
FindWindowEx(). How to I get this to be an IntPtr instead?

'My New declaration (as you wrote it)
Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As Int32

'My old call but with 0 instead of 0& in the last parameter.
MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0))
Value of type 'Long' cannot be converted to 'System.IntPtr'. (hWndbutton is
a Long)

Please help/Lars


That would indicate that you are using the incorrect data type for the return value from the FindWindowEX call. Since it returns a
HWND which is a DWORD or 32-bit integer, Long is the incorrect .Net data type for the API Declare.

You show your declare as:

Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As
Long

And as it has already been pointed out, Long is the incorrect data type for the hwnd parameters and return value. You need to use
32-bit integer data types for the declares, rather than Longs and you need to be consistent.

Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As
Int32
I hope this helps.

--
Al Reid

Nov 21 '05 #8
Hi

Yeah... I tested that but then of course the FindWindowEx is declared as a
long so.. I get a "Specified Cast Not valid" when trying to assign the
hWndbutton from FindWidowEx()

/Lars
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ew**************@tk2msftngp13.phx.gbl...
"Lars Netzel" <ui****@adf.se> schrieb:
Since I'm using this declaration now where the first parameter is an
IntPtr instead of a long... I can't call the SendMessage() the same way
anymore. I mean, the hWndbutton variable is a Long... that's what I get
back from FindWindowEx(). How to I get this to be an IntPtr instead?

'My New declaration (as you wrote it)
Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As
Int32) As Int32

'My old call but with 0 instead of 0& in the last parameter.
MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0))
Value of type 'Long' cannot be converted to 'System.IntPtr'. (hWndbutton
is a Long)


Declare 'hWndButton' As 'IntPtr'. 'Long' is a 64-bit type and thus not
suitable.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9
Well I must admit this is a little bit above my normal "areas" in
programming.. but it can't be that hard to get to work...

I have this...
-----------------------------------------------------------
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As
Int32

Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As Int32

Private Const WM_KEYDOWN As Int32 = &H100

Private Const WM_KEYUP As Int32 = &H101

Private Const VK_SPACE As Int32 = &H20

Dim hWndbutton As IntPtr

Dim hWnd As Long

hWnd = FindWindow(vbNullString, "FSM Klient")

hWndbutton = FindWindowEx(hWnd, 0&, "Button2", vbNullString)

SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0)

SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0)

------------------------------------------------------------
It underlines the "FindWindowEx(hWnd, 0&, "Button2", vbNullString)" row now
and says "Integer cannot be converted to IntPtr"

/Lars

"Al Reid" <ar*****@reidDASHhome.com> wrote in message
news:Oj**************@TK2MSFTNGP14.phx.gbl...
"Lars Netzel" <ui****@adf.se> wrote in message
news:Oa****************@TK2MSFTNGP14.phx.gbl...
Hi, thank you for your reply unfortunately I get an error and can't
compile
now..

Since I'm using this declaration now where the first parameter is an
IntPtr
instead of a long... I can't call the SendMessage() the same way anymore.
I
mean, the hWndbutton variable is a Long... that's what I get back from
FindWindowEx(). How to I get this to be an IntPtr instead?

'My New declaration (as you wrote it)
Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As
Int32)
As Int32

'My old call but with 0 instead of 0& in the last parameter.
MsgBox(SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0) & " " &
SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0))
Value of type 'Long' cannot be converted to 'System.IntPtr'. (hWndbutton
is
a Long)

Please help/Lars


That would indicate that you are using the incorrect data type for the
return value from the FindWindowEX call. Since it returns a
HWND which is a DWORD or 32-bit integer, Long is the incorrect .Net data
type for the API Declare.

You show your declare as:

Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
As
Long

And as it has already been pointed out, Long is the incorrect data type
for the hwnd parameters and return value. You need to use
32-bit integer data types for the declares, rather than Longs and you need
to be consistent.

Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String)
As
Int32
I hope this helps.

--
Al Reid

Nov 21 '05 #10
"Lars Netzel" <ui****@adf.se> wrote in message news:ek*************@TK2MSFTNGP15.phx.gbl...
Well I must admit this is a little bit above my normal "areas" in
programming.. but it can't be that hard to get to work...


It really is simple. You just have to use consistent data types.

Change all API parameters and variables that reference Hwnd's to IntPtr or Int32. As you have it now you are using Long, Int32 and
IntPtr for the Hwnd's. Fix that first. I would suggest using IntPtr.

Once you resolve the issues with data types, it should work. Hint: There should be no "Long" data types in the API declares.

--
Al Reid
Nov 21 '05 #11
"Lars Netzel" <ui****@adf.se> schrieb:
Yeah... I tested that but then of course the FindWindowEx is declared as a
long so.. I get a "Specified Cast Not valid" when trying to assign the
hWndbutton from FindWidowEx()


Mhm... I suggest to use the declaration of 'FindWindowEx' I gave you in a
previous thread.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #12
"Lars Netzel" <ui****@adf.se> schrieb:
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String)
As Int32
'ByVal hWnd1 As Long, ByVal hWnd2 As Long' => 'ByVal hWnd1 As IntPtr, ByVal
hWnd2 As IntPtr'.

'...) As Int32' => '...) As IntPtr'.
Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As Int32

Private Const WM_KEYDOWN As Int32 = &H100

Private Const WM_KEYUP As Int32 = &H101

Private Const VK_SPACE As Int32 = &H20

Dim hWndbutton As IntPtr

Dim hWnd As Long
'As Long' => 'As IntPtr'.
hWnd = FindWindow(vbNullString, "FSM Klient")

hWndbutton = FindWindowEx(hWnd, 0&, "Button2", vbNullString)
'0&' => 'IntPtr.Zero'.
SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0)

SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0)


--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #13

Okay.. I'm getting more and more confused... I have no Longs what so ever
now...
...and Can't compile cause the "0&" on row "hWndbutton = FindWindowEx(hWnd,
0&, "Button2", vbNullString)" cannot be converted to an IntPtr.. what should
I set that parameter too?
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String)
As IntPtr

Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As IntPtr

Private Const WM_KEYDOWN As Int32 = &H100

Private Const WM_KEYUP As Int32 = &H101

Private Const VK_SPACE As Int32 = &H20

Dim hWndbutton As IntPtr

Dim hWnd As IntPtr

hWnd = FindWindow(vbNullString, "FSM Klient")

hWndbutton = FindWindowEx(hWnd, 0&, "Button2", vbNullString)

SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0)

SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0)

/Lars
"Al Reid" <ar*****@reidDASHhome.com> wrote in message
news:ec****************@TK2MSFTNGP12.phx.gbl...
"Lars Netzel" <ui****@adf.se> wrote in message
news:ek*************@TK2MSFTNGP15.phx.gbl...
Well I must admit this is a little bit above my normal "areas" in
programming.. but it can't be that hard to get to work...


It really is simple. You just have to use consistent data types.

Change all API parameters and variables that reference Hwnd's to IntPtr or
Int32. As you have it now you are using Long, Int32 and
IntPtr for the Hwnd's. Fix that first. I would suggest using IntPtr.

Once you resolve the issues with data types, it should work. Hint: There
should be no "Long" data types in the API declares.

--
Al Reid

Nov 21 '05 #14
Pass an IntPtr rather than an Integer. One way of doing it is shown inline.

"Lars Netzel" <ui****@adf.se> wrote in message news:Or**************@TK2MSFTNGP14.phx.gbl...

Okay.. I'm getting more and more confused... I have no Longs what so ever
now...
..and Can't compile cause the "0&" on row "hWndbutton = FindWindowEx(hWnd,
0&, "Button2", vbNullString)" cannot be converted to an IntPtr.. what should
I set that parameter too?
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String)
As IntPtr

Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As IntPtr

Private Const WM_KEYDOWN As Int32 = &H100

Private Const WM_KEYUP As Int32 = &H101

Private Const VK_SPACE As Int32 = &H20

Dim hWndbutton As IntPtr

Dim hWnd As IntPtr

hWnd = FindWindow(vbNullString, "FSM Klient")

////
hWndbutton = FindWindowEx(hWnd, New IntPtr(0), "Button2", vbNullString)<<<

\\\\

SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0)

SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0)

/Lars

Nov 21 '05 #15
"Lars Netzel" <ui****@adf.se> schrieb:
Okay.. I'm getting more and more confused... I have no Longs what so ever
now...
..and Can't compile cause the "0&" on row "hWndbutton =
FindWindowEx(hWnd, 0&, "Button2", vbNullString)" cannot be converted to an
IntPtr.. what should I set that parameter too?
'0' is treated as 'Int32', '0&' as 'Long'. Pass 'IntPtr.Zero' instead of
'0&'.
Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Remove the 'Alias "FindWindowA"'. I posted the correct declares recently,
you only have to copy them.
hWndbutton = FindWindowEx(hWnd, 0&, "Button2", vbNullString)


'0&' => 'IntPtr.Zero'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #16
It still doesn't work... now I can compile but I get a 0 value back from the
FindWindowEx(). The FindWindow() return a value though...

Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As
String, ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String)
As IntPtr

Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As IntPtr

Private Const WM_KEYDOWN As Int32 = &H100

Private Const WM_KEYUP As Int32 = &H101

Private Const VK_SPACE As Int32 = &H20

Dim hWndbutton As IntPtr

Dim hWnd As IntPtr

hWnd = FindWindow(vbNullString, "FSM Klient")

hWndbutton = FindWindowEx(hWnd, IntPtr.Zero, "Button2", vbNullString)

MsgBox(hWndbutton.ToString)

SendMessage(hWndbutton, WM_KEYDOWN, VK_SPACE, 0)

SendMessage(hWndbutton, WM_KEYUP, VK_SPACE, 0)

/Lars
Nov 21 '05 #17
"Lars Netzel" <ui****@adf.se> schrieb:
It still doesn't work... now I can compile but I get a 0 value back from
the FindWindowEx(). The FindWindow() return a value though...
[...]
hWndbutton = FindWindowEx(hWnd, IntPtr.Zero, "Button2", vbNullString)


I already said that you'll have to pass the window's Win32 control class
name (this is not the same as the .NET class name!) instead of "Button2",
and the caption of the button in the last parameter. You can obtain the
Win32 control class name of the button by using the Spy++ tool to pick the
control of the running application.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #18
Hi!

Thank you, yes I had missed that in your other thread.. .it is now Solved I
have managed to click a button in another Window thru this code.. and I'm
very grateful..

I tested "clicking" a 3 in the Calculator too and that worked.. whohoooo:)

by the Way I used Winspector to look up the Class names and stuff.. couldn't
find SPy ++ fast enough.

Very happy!

best regards
/Lars Netzel

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
"Lars Netzel" <ui****@adf.se> schrieb:
It still doesn't work... now I can compile but I get a 0 value back from
the FindWindowEx(). The FindWindow() return a value though...
[...]
hWndbutton = FindWindowEx(hWnd, IntPtr.Zero, "Button2", vbNullString)


I already said that you'll have to pass the window's Win32 control class
name (this is not the same as the .NET class name!) instead of "Button2",
and the caption of the button in the last parameter. You can obtain the
Win32 control class name of the button by using the Spy++ tool to pick the
control of the running application.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nidhi | last post by:
Hi, I am trying to write code to retrieve the small icon for an application in C#. I am using SendMessage with WM_GETICON for this purpose but the return value I get is 0. I don't understand...
2
by: Sonia Igla | last post by:
Hi. I need to perform DBLCLK on TreeView Node. I try the following: private static extern int SendMessage(IntPtr hWnd, uint msg, UInt32 wParam, UInt32 lParam); private const UInt32...
5
by: Adam Clauss | last post by:
I am attempting to set the text on a richedit control in another application using EM_SETTEXTEX:...
3
by: JSK | last post by:
Hi, As any one worked in VB.NET and made use of Sendmessage API? The Issue I am running into is how to pass pointers of Data Structures (UDT) to the SendMessage. I starting looking at "IntPrt"...
2
by: Abubakar | last post by:
Hi, in my application, different threads send notifications to GUI thread through sendmessage api. They have special integer numbers inside the wParam arg of sendmessage which the gui thread uses...
11
by: NVergunst | last post by:
Hello everyone. I have what I believe to be a simple question, yet I can not find anything that is helpful to me. Basically I have an application, that I want to use to control external...
1
by: Necromis | last post by:
Ok, I have gotten my head around things better regarding SendMessage and FindWindow functions. However, I am running into an issue with my code still. The program I am working with is EXTRA! by...
9
by: Neil | last post by:
Anyone have any idea why SendMessage ctl.hwnd, WM_PASTE, 0, 0 isn't working from a regular Access text box (form is opened normally, not in dialog more)? I realize I can just use...
8
by: Dr1ZZ | last post by:
Hi, I'm currently working on a bot for a game. It works like this: 1: Take a picture of the current playing field 2: Do the calculations on what i gotta do (best move) 3: Use sendmessage...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.