473,732 Members | 2,217 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 53892
"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
2423
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
1149
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
8896
by: TomislaW | last post by:
How to find all user controls (ascx) loaded on a Page?
9
5062
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
5321
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
10400
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
3807
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
2589
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
8946
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
8774
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
9447
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
9307
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...
0
8186
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...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.