borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Anything wrong with my code?)Next Topic (Task Manager process info) New Topic New Poll Post Reply
AndreaVB Forum : API : Hwnd of all windows on screen Solved Topic
Poster Message
misterxed
Level: VB Lord


Registered: 12-06-2005
Posts: 151

icon Hwnd of all windows on screen

Hi,
I want to know the HWnd of all the windows that are currently on the screen, be it the taskbar, the icons on the desktop, or any other window which is currently displayed on the desktop...
Is there any way to get 'em?


____________________________
lOsT...

27-11-2005 at 03:56 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: Hwnd of all windows on screen

Hi,
Create a new app, with a form, button and listbox.
call the listbox list1
add the following code into a module:

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Public Function WindowEnumerator(ByVal app_hwnd As Long, ByVal lParam As Long) As Long
    Dim length As Long
    Dim Title As String
    Dim buf As String * 256
    
    
    
length = GetWindowText(app_hwnd, buf, Len(buf))
If length = 0 Then
    length = GetClassName(app_hwnd, buf, Len(buf))
    End If
    Title = Left$(buf, length)


    Form1.List1.AddItem app_hwnd & vbTab & Title
    
    WindowEnumerator = True
    
End Function



Now add the following to the form:


Private Sub Command1_Click()
    Me.List1.Clear
    
    EnumWindows AddressOf WindowEnumerator, 0
    
End Sub

Run and click the button.
The listbox is populated with the caption or classname of all windows.

Hope this helps,
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

10-12-2005 at 02:53 PM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: Hwnd of all windows on screen

Add this to the module too.

Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

12-12-2005 at 11:01 AM
View Profile Send Email to User Show All Posts | Quote Reply
misterxed
Level: VB Lord


Registered: 12-06-2005
Posts: 151
icon Re: Hwnd of all windows on screen

Hi,
Thanks for the help guys... (I know I'm thanking a bit toooooo late .  Actually, I had been bz for a couple of months due to a series of events...)

Anywayz, now I want the Handle of the Start MENU. I mean the MENU which is showing the menu items: "Shut down, Run, Help... " etc... (Not the bar...)

Waiting for ur replies...

Regards

____________________________
lOsT...

15-03-2006 at 09:36 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : API : Hwnd of all windows on screen Solved Topic
Previous Topic (Anything wrong with my code?)Next Topic (Task Manager process info) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder