473,842 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 53921
"Lars Netzel" <ui****@adf.s e> 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 "FindWindow A" (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(vbNu llString, "FSM")
MsgBox("FSM: " & hWnd)

MsgBox("Button1 : " & FindWindowEx(hW nd, 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******** *****@tk2msftng p13.phx.gbl...
"Lars Netzel" <ui****@adf.s e> 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.s e> 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 "FindWindow A"
(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(vbNu llString, "FSM")
If hWnd.Equals(Int Ptr.Zero) Then
Return
End If
Dim hWndButton As IntPtr = _
FindWindowEx(hW nd, IntPtr.Zero, "BUTTON", "Button 1")
If hWndButton.Equa ls(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(Unma nagedType.LPTSt r), [In]()> ByVal lpClassName As
String, _
<MarshalAs(Unma nagedType.LPTSt r), [In]()> ByVal lpWindowName As
String _
) As IntPtr

Private Declare Auto Function FindWindowEx Lib "user32.dll " ( _
ByVal hWndParent As IntPtr, _
ByVal hWndChildAfter As IntPtr, _
<MarshalAs(Unma nagedType.LPTSt r), [In]()> ByVal lpszClass As
String, _
<MarshalAs(Unma nagedType.LPTSt r), [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******** ********@TK2MSF TNGP15.phx.gbl. ..
"Lars Netzel" <ui****@adf.s e> 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 "FindWindow A"
(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(vbNu llString, "FSM")
If hWnd.Equals(Int Ptr.Zero) Then
Return
End If
Dim hWndButton As IntPtr = _
FindWindowEx(hW nd, IntPtr.Zero, "BUTTON", "Button 1")
If hWndButton.Equa ls(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.s e> wrote in message
news:e8******** *****@tk2msftng p13.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.no spam.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
2300
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 help me to find the no. of form instances running ? Thanks.
4
2424
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 though FindWindow() works perfectly well. I have imported <windows.h> but being quite new to C++ I can't find a solution, can anyone help me?
0
1151
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 namespace" I have imported <windows.h> and FindWindow() works fine. As I am quite new to C++ I can't fins a solution, can anyone help?
6
8904
by: TomislaW | last post by:
How to find all user controls (ascx) loaded on a Page?
9
5070
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: ******************************************************************************* <asp:DataGrid visible="False" border=1
10
5331
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 certain control by id, but I want to find all controls of a certain type (DropDownList in this case). Is there an easier way than to get a control count of the page, loop through all controls on that page, examine their type and, if they're a...
1
10405
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 retrieve always general as NULL. I'm using the internet connection window with winXP where there are two tabs, general and details. How is
6
3812
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" - ThunderRT6FrmDC - "" - ThunderRT6Frame (outer panel) - "" - ThunderRT6Frame (inner panel)
1
2592
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 FindWindowEx function only works on my PC when run but not on my end-user's. The frustrating part is that the first call to the function runs fine but not the second. Hopefully someone with more experience using API's may have an answer to this since...
0
9870
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10940
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10610
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10670
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10308
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7854
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4499
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4087
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.