473,698 Members | 2,283 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 53866
"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
2421
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
1148
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
8895
by: TomislaW | last post by:
How to find all user controls (ascx) loaded on a Page?
9
5056
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
5314
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
10392
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
3805
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
2587
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
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
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
9029
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
8898
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
8870
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...
1
6524
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...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3051
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
2332
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.