473,396 Members | 1,608 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,396 software developers and data experts.

How can I get caption of all open windows??

Hi,

I need to to get the caption of all open windows. Not only for my
application, but for all running programs.

I know it has something to do with Win32 EnumWindows, but I've tried some
examples, but can't make it work.

I need the sample code .... please! :o)

Thank you in advance!

M o j o
Mar 31 '06 #1
2 7033
Hi,

Dim cb As CallBack

' VB.NET declaration
Public Delegate Function CallBack( _
ByVal hwnd As IntPtr, _
ByVal lParam As IntPtr) As Boolean

Public Declare Function EnumWindows Lib "user32" ( _
ByVal lpEnumFunc As CallBack, _
ByVal lParam As Integer) As Integer

Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" ( _
ByVal hwnd As IntPtr) As Integer

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As IntPtr, _
ByVal lpString As StringBuilder, _
ByVal cch As Integer) As Integer

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As
IntPtr, _
ByVal hWndNewParent As IntPtr) As Integer

Public Function MyCallBack(ByVal hwnd As IntPtr, ByVal lParam As IntPtr)
As Boolean
Dim intLen As Integer = GetWindowTextLength(hwnd) + 1
If intLen > 1 Then
Dim strText As New StringBuilder(intLen)
Try
GetWindowText(hwnd, strText, intLen)
ListBox1.Items.Add(strText.ToString)
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
End If
Return True
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cb = New CallBack(AddressOf MyCallBack)
EnumWindows(cb, 0)
End Sub

Ken
----------------
"M O J O" <MO**@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Hi,

I need to to get the caption of all open windows. Not only for my
application, but for all running programs.

I know it has something to do with Win32 EnumWindows, but I've tried some
examples, but can't make it work.

I need the sample code .... please! :o)

Thank you in advance!

M o j o

Mar 31 '06 #2
Hi Ken,

THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I've spent two days now searching for the answer, converting vb6 and cs
files without any luck.

Your solution works PERFECTLY! :o))))

Thanks once more!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Kind regards,
M o j o

"Ken Tucker [MVP]" wrote:
Hi,

Dim cb As CallBack

' VB.NET declaration
Public Delegate Function CallBack( _
ByVal hwnd As IntPtr, _
ByVal lParam As IntPtr) As Boolean

Public Declare Function EnumWindows Lib "user32" ( _
ByVal lpEnumFunc As CallBack, _
ByVal lParam As Integer) As Integer

Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" ( _
ByVal hwnd As IntPtr) As Integer

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As IntPtr, _
ByVal lpString As StringBuilder, _
ByVal cch As Integer) As Integer

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As
IntPtr, _
ByVal hWndNewParent As IntPtr) As Integer

Public Function MyCallBack(ByVal hwnd As IntPtr, ByVal lParam As IntPtr)
As Boolean
Dim intLen As Integer = GetWindowTextLength(hwnd) + 1
If intLen > 1 Then
Dim strText As New StringBuilder(intLen)
Try
GetWindowText(hwnd, strText, intLen)
ListBox1.Items.Add(strText.ToString)
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
End If
Return True
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cb = New CallBack(AddressOf MyCallBack)
EnumWindows(cb, 0)
End Sub

Ken
----------------
"M O J O" <MO**@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Hi,

I need to to get the caption of all open windows. Not only for my
application, but for all running programs.

I know it has something to do with Win32 EnumWindows, but I've tried some
examples, but can't make it work.

I need the sample code .... please! :o)

Thank you in advance!

M o j o


Mar 31 '06 #3

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

Similar topics

1
by: Colin Ward | last post by:
Hi. I have a popup modal form which gets part of its caption from code. The part of the caption which is determined from code is the name of the event. For example the caption would be "Add Year...
11
by: SELIM ZAIRI | last post by:
hi, to all i was wondering if some one got this problem before and if he had any solution i got a query: SELECT MSysObjects.Name, MSysObjects.Type, GETFRMCAPTION() AS Expr1 FROM MSysObjects...
7
by: Paul T. Rong | last post by:
Hello, Often when I open one form, and (without closing it) open the form in its design view, then all the caption value of the controls in this form remained there in form's design view that is...
5
by: MLH | last post by:
This is one for you gurus. Someone has undoubtedly already done this. How difficult would it be to recurse all command buttons and textbox controls on all forms, appending an incrementing number to...
0
by: Chenghui Li | last post by:
We have a problem with the Windows XP theme: We have a IDE which allows other developers to develop visual programs for their customers. Our IDE allow them to set font for window captions easyly...
2
by: Trammel | last post by:
Hi. I have been trying to make a simple application that will sit in the background and alert me of any changes in window focus (IE: Pop-up windows) on my system. I have used...
0
by: Franky | last post by:
I have a MDI form open and two child forms open in it. Each of the children contains a usercontrol which contains a richtextbox. The topmost form's caption bar is highlighted but I click on the...
9
by: Abhishek | last post by:
Hi, How do i find the window caption by using the hmodule of that window? Regards Abhishek
6
by: slg | last post by:
Is there a simpler way to increase the mdi form caption height? I am following this article but not sure where should i change? I belive its most probably in the WmNCCalcSize TIA ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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...
0
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...
0
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,...

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.