By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

Call SendMessage API Question

P: n/a
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
Share this Question
Share on Google+
18 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
"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

P: n/a
"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

P: n/a

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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.