| |
VB.NET - Ein- und UmsteigerRe: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: GPM | Datum: 26.06.07 21:33 |
| Eine Listbox und ein Button auf eine Form setzen:
Public Class Form1
Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As _
EnumWindowsProc, ByVal lParam As Int32) As Int32
Public Declare Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As _
IntPtr) As Boolean
Public Delegate Function EnumWindowsProc(ByVal hwnd As IntPtr, ByVal lParam _
As Int32) As Boolean
Public Declare Function GetWindowText Lib "user32.dll" Alias _
"GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch _
As Int32) As Int32
Public Declare Function GetWindowTextLength Lib "user32.dll" Alias _
"GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Int32
Public Declare Function GetWindowLong Lib "user32.dll" Alias _
"GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Int32) As Int32
Public Declare Function GetParent Lib "user32.dll" (ByVal intptr As IntPtr) _
As IntPtr
Public Const GWL_HWNDPARENT As Int32 = -8
Private newwindowlist As List(Of String)
Private Function EnumWinProc(ByVal hwnd As IntPtr, ByVal lParam As Int32) _
As Boolean
If IsWindowVisible(hwnd) Then
If GetParent(hwnd) = IntPtr.Zero Then
If GetWindowLong(hwnd, GWL_HWNDPARENT) = 0 Then
Dim str As String = String.Empty.PadLeft( _
GetWindowTextLength(hwnd) + 1)
GetWindowText(hwnd, str, str.Length)
If Not String.IsNullOrEmpty(str.Substring(0, str.Length - _
1)) Then newwindowlist.Add(str.Substring(0, str.Length - _
1))
End If
End If
End If
EnumWinProc = True
End Function
Private Sub RefreshWindowList()
newwindowlist = New List(Of String)
EnumWindows(AddressOf EnumWinProc, CInt(True))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
RefreshWindowList()
ListBox1.Items.Clear()
ListBox1.Items.Add("Fenster, die mit ""Channel"" beginnen:")
For Each item As String In newwindowlist
If item.StartsWith("Channel") Then
ListBox1.Items.Add(item)
End If
Next
End Sub
End Class MfG GPM | |
Re: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: lord man | Datum: 19.02.07 17:50 |
| weiss denn das niemand? | |
Re: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: lord man | Datum: 21.02.07 12:12 |
| Hallo WmS!
Danke für deine hilfe !
ja ich will es über windows API machen aber mit den Befehlen :
FindWindowEx und GetWindow !
Ist der code dann anders?
LG Lordy | |
Re: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: lord man | Datum: 21.02.07 14:15 |
| Hi Lukas,
Weil ich noch ein VB anfänger bin : Kannst du mir bitte den Code hier reinschreiben ?
- Danke im vorraus
mfg Lordy | |
Re: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: WmS | Datum: 21.02.07 14:49 |
| ich habs ja schon geahnt dass ich doch nicht drumherum komme....
neue konsolenanwendung erstellen, allen code löschen und das einfügen, dann F5 drücken:
Module Module1
Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As _
EnumWindowsProc, ByVal lParam As Int32) As Int32
Public Declare Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As _
IntPtr) As Boolean
Public Delegate Function EnumWindowsProc(ByVal hwnd As IntPtr, ByVal lParam _
As Int32) As Boolean
Public Declare Function GetWindowText Lib "user32.dll" Alias _
"GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch _
As Int32) As Int32
Public Declare Function GetWindowTextLength Lib "user32.dll" Alias _
"GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Int32
Public Declare Function GetWindowLong Lib "user32.dll" Alias _
"GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Int32) As Int32
Public Declare Function GetParent Lib "user32.dll" (ByVal intptr As IntPtr) _
As IntPtr
Public Const GWL_HWNDPARENT As Int32 = -8
Private newwindowlist As List(Of String)
Private Function EnumWinProc(ByVal hwnd As IntPtr, ByVal lParam As Int32) _
As Boolean
If IsWindowVisible(hwnd) Then
If GetParent(hwnd) = IntPtr.Zero Then
If GetWindowLong(hwnd, GWL_HWNDPARENT) = 0 Then
Dim str As String = String.Empty.PadLeft( _
GetWindowTextLength(hwnd) + 1)
GetWindowText(hwnd, str, str.Length)
If Not String.IsNullOrEmpty(str.Substring(0, str.Length - _
1)) Then newwindowlist.Add(str.Substring(0, str.Length - _
1))
End If
End If
End If
EnumWinProc = True
End Function
Private Sub RefreshWindowList()
newwindowlist = New List(Of String)
EnumWindows(AddressOf EnumWinProc, CInt(True))
End Sub
Sub Main()
RefreshWindowList()
Console.WriteLine("Fenster, die mit ""Channel"" beginnen:")
For Each item As String In newwindowlist
If item.StartsWith("Channel") Then
Console.WriteLine(item)
End If
Next
Console.ReadLine()
End Sub
End Module ändern kannst du den fenstertitel mit der SetWindowText-API
cu, Lukas
#######
ICQ: 192-576-074
http://codinglukas.co.funpic.de/
Wer fragt ist ein Narr - f?r 5 Minuten.
Wer nicht fragt ist ein Narr - sein Leben lang.
Quarks&Co | |
Re: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: lord man | Datum: 21.02.07 14:55 |
| Danke Lukas !
Sobald ich wieder daheim bin werde ich es probieren !
Mfg lordy | |
Re: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: TobYBrain | Datum: 26.06.07 17:00 |
| Hallo,
auch wenn der Thread schon etwas älter ist, hätte ich dazu mal eine Frage: Und zwar, wo werden die geöffneten Fenster hingeschrieben. Wenn ich das richtig kapiert habe, werden die in "Console" geschrieben. Jedoch habe ich keinen blassen schimmer, wo sich diese Console befindet. Ich habe versucht, eine Listbox also Console zu deklarieren und diese dort einzusetzten, aber das hat nicht funktioniert. Also wo werden die geöffneten Fenster aufgelistet?
TobY | |
Re: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: GPM | Datum: 26.06.07 17:23 |
| Der Code ist für eine Konsolenanwendung und nicht für eine Windowsanwendung.
Datei / Neues Projekt... / Konsolenanwendung
MfG GPM | |
Re: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: TobYBrain | Datum: 26.06.07 20:33 |
| Danke, das schafft mal wieder mehr Klarheit
Ist es denn auch möglich, den Code so zu ändern, dass ich die Fensternamen in eine ListBox schreibe?
TobY | |
Re: Fenstertitel erkennen und in Listbox anzeigen | | | Autor: TobYBrain | Datum: 26.06.07 21:43 |
| Danke! Funktioneirt super! Ich bin begeistert
TobY | |
| Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
|
|
Neu! sevCommand 4.0
Professionelle Schaltflächen im modernen Design!
Mit nur wenigen Mausklicks statten auch Sie Ihre Anwendungen ab sofort mit grafischen Schaltflächen im modernen Look & Feel aus (WinXP, Office, Vista oder auch Windows 8), inkl. große Symbolbibliothek. Weitere InfosTipp des Monats TOP Entwickler-Paket
TOP-Preis!!
Mit der Developer CD erhalten Sie insgesamt 24 Entwickler- komponenten und Windows-DLLs. Die Einzelkomponenten haben einen Gesamtwert von 1605.50 EUR...
Jetzt nur 599,00 EURWeitere Infos
|