473,326 Members | 2,588 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,326 software developers and data experts.

Use FindWindowEx() to find Controls?

Do I use FindWindowEx() to find control ( a button.. ) within a Window or
is that only to find child Windows after using FindWindows()

best regards
/Lars
Nov 21 '05 #1
7 53701
"Lars Netzel" <ui****@adf.se> schrieb:
Do I use FindWindowEx() to find control ( a button.. ) within a Window or
is that only to find child Windows after using FindWindows()


Yes, 'FindWindowEx' is designed for this purpose. Buttons that are placed
on forms are child windows.

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

Nov 21 '05 #2
Thank you.. then.. how come this does not work? my FSM window have a button
with the caption "Button1"
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer

Public Declare Function FindWindowEx Lib "user32" (ByVal hWnd1 As Long,
ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
hWnd = FindWindow(vbNullString, "FSM")
MsgBox("FSM: " & hWnd)

MsgBox("Button1: " & FindWindowEx(hWnd, 0&, "Button1", vbNullString))

It finds the window fine.. but not the button... is the declaration okay?

Best regards
/Lars

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O2*************@tk2msftngp13.phx.gbl...
"Lars Netzel" <ui****@adf.se> schrieb:
Do I use FindWindowEx() to find control ( a button.. ) within a Window
or is that only to find child Windows after using FindWindows()


Yes, 'FindWindowEx' is designed for this purpose. Buttons that are placed
on forms are child windows.

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

Nov 21 '05 #3
"Lars Netzel" <ui****@adf.se> schrieb:
Thank you.. then.. how come this does not work? my FSM window have a
button with the caption "Button1"
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

Public Declare Function FindWindowEx Lib "user32" (ByVal hWnd1 As Long,
ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
[...]
It finds the window fine.. but not the button... is the declaration okay?


Use these declarations and the code below (untested):

\\\
Private Declare Auto Function FindWindow Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As IntPtr

Private Declare Auto Function FindWindowEx Lib "user32.dll" ( _
ByVal hwndParent As IntPtr, _
ByVal hwndChildAfter As IntPtr, _
ByVal lpszClass As String, _
ByVal lpszWindow As String _
) As IntPtr
..
..
..
Dim hWnd As IntPtr = FindWindow(vbNullString, "FSM")
If hWnd.Equals(IntPtr.Zero) Then
Return
End If
Dim hWndButton As IntPtr = _
FindWindowEx(hWnd, IntPtr.Zero, "BUTTON", "Button 1")
If hWndButton.Equals(IntPtr.Zero) Then
Return
End If
....
///

Note that "BUTTON" must be replaced by the Win32 window class name of the
control. This is typically "BUTTON" for C-based applications, but the class
name can differ for applications written in Classic Visual Basic and .NET.
You can use the Spy++ utility which comes with VS.NET to grab the control's
class name. The last parameter of 'FindWindowEx' expects the button's
caption. Make sure you don't forget the leading "&" character if the
caption contains an accelerator key.

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

Nov 21 '05 #4
Hi Lars,
It finds the window fine.. but not the button... is the declaration

okay?

Nope, it isn't.

You better try this instead:

~
Private Declare Auto Function FindWindow Lib "user32.dll" ( _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpClassName As
String, _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpWindowName As
String _
) As IntPtr

Private Declare Auto Function FindWindowEx Lib "user32.dll" ( _
ByVal hWndParent As IntPtr, _
ByVal hWndChildAfter As IntPtr, _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpszClass As
String, _
<MarshalAs(UnmanagedType.LPTStr), [In]()> ByVal lpszWindow As
String _
) As IntPtr
~

Roman
Nov 21 '05 #5
Thank you, that worked!:) Just that little Auto word missing... what does
that mean?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Lars Netzel" <ui****@adf.se> schrieb:
Thank you.. then.. how come this does not work? my FSM window have a
button with the caption "Button1"
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

Public Declare Function FindWindowEx Lib "user32" (ByVal hWnd1 As Long,
ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As
Long
[...]
It finds the window fine.. but not the button... is the declaration
okay?


Use these declarations and the code below (untested):

\\\
Private Declare Auto Function FindWindow Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As IntPtr

Private Declare Auto Function FindWindowEx Lib "user32.dll" ( _
ByVal hwndParent As IntPtr, _
ByVal hwndChildAfter As IntPtr, _
ByVal lpszClass As String, _
ByVal lpszWindow As String _
) As IntPtr
.
.
.
Dim hWnd As IntPtr = FindWindow(vbNullString, "FSM")
If hWnd.Equals(IntPtr.Zero) Then
Return
End If
Dim hWndButton As IntPtr = _
FindWindowEx(hWnd, IntPtr.Zero, "BUTTON", "Button 1")
If hWndButton.Equals(IntPtr.Zero) Then
Return
End If
...
///

Note that "BUTTON" must be replaced by the Win32 window class name of the
control. This is typically "BUTTON" for C-based applications, but the
class name can differ for applications written in Classic Visual Basic and
.NET. You can use the Spy++ utility which comes with VS.NET to grab the
control's class name. The last parameter of 'FindWindowEx' expects the
button's caption. Make sure you don't forget the leading "&" character if
the caption contains an accelerator key.

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

Nov 21 '05 #6
"Lars Netzel" <ui****@adf.se> wrote in message
news:e8*************@tk2msftngp13.phx.gbl...
Thank you, that worked!:) Just that little Auto word missing... what does
that mean?

It lets the runtime decide whether the strings are passed as Unicode or
ANSI. On Win9X platforms they are passed as ANSI; on all other Windows
platforms they are passed as Unicode

Hope this helps,

Nick Hall
Nov 21 '05 #7
"Nick Hall" <ni***@aslan.nospam.co.uk> schrieb:
Thank you, that worked!:) Just that little Auto word missing... what does
that mean?


It lets the runtime decide whether the strings are passed as Unicode or
ANSI. On Win9X platforms they are passed as ANSI; on all other Windows
platforms they are passed as Unicode


BTW: The documentation for the 'Declare' statement contains an explanation
too.

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

Nov 21 '05 #8

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

Similar topics

1
by: enahar | last post by:
Hello, i want to find out how many instances of a form (say childForm1) is running using FindWindowEx but value return is always zero by this method. What wrong I am doing it..Can anybody...
4
by: Simon Matthews | last post by:
Hi, I'm trying to find a window handle using FindWindowEx. I get an error undecalred identifier if I use FindWindowEx() and not a member of global namespace if I use ::FindWindowEx()... Even...
0
by: Simon Matthews | last post by:
I am trying to find a window handle using FindWindowEx, yet when I compile the code I get an "unresolved identifier" error, usinf ::FindWindowEx() gives me the error "not a member of global...
6
by: TomislaW | last post by:
How to find all user controls (ascx) loaded on a Page?
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
1
by: Geky | last post by:
HWND window = ::FindWindow(NULL,"Internet connect"); while(window == NULL) { window = ::FindWindow(NULL,"Internet connect"); } HWND general = ::FindWindowEx(window,0,"General",NULL); I...
6
by: kru | last post by:
Hi All, I've been trying to get FindWindowEx to work to locate a button, and am stumped on the following: The structure of the external app is as so from Spy++: - "Main Window" -...
1
by: Trompomerson | last post by:
Hello, I am running the code below in an Excell '03 userform, the purpose of the code is to set the form as a child of the workbook so it moves around with it etc. however the last call to the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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)...
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.