vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Brandneu! sevEingabe v3.0 - Das Eingabecontrol der Superlative!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB & Windows API
Re: Bestimmtes Fenster im Hintergrund aktivieren 
Autor: mikeb69
Datum: 08.07.07 20:29

hallo zimmwarrior,

schau dir mal das an
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
    Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As _
    IntPtr, ByRef lpRect As RECT) As Boolean
 
    Public Const GWL_HWNDPARENT As Int32 = -8
    Private newwindowlist As List(Of String)
    Private newhandlelist As List(Of IntPtr)
 
    Private Structure RECT
        Public left As Integer
        Public top As Integer
        Public right As Integer
        Public bottom As Integer
        ' constructor
        Public Sub New(ByVal _left As Integer, ByVal _top As Integer, ByVal _
          _right As Integer, ByVal _bottom As Integer)
            left = _left
            top = _top
            right = _right
            bottom = _bottom
        End Sub
    End Structure
 
    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))
                        newhandlelist.Add(hwnd)
                    End If
                End If
            End If
        End If
        EnumWinProc = True
    End Function
 
    Private Sub RefreshWindowList()
        newwindowlist = New List(Of String)
        newhandlelist = New List(Of IntPtr)
        EnumWindows(AddressOf EnumWinProc, CInt(True))
    End Sub
 
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As _
      System.EventArgs) Handles Button1.Click
        RefreshWindowList()
        ListBox1.Items.Clear()
        Dim count As Integer = 0
        For Each item As String In newwindowlist
            ListBox1.Items.Add(newhandlelist(count).ToString & " " & item)
            count += 1
        Next
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
      System.EventArgs) Handles Button2.Click
        'lastForeGroundWindow = foregroundWindow
        'alle prozesse mit fensternamen durchlaufen und richtigen finden
        'log.Add("Searching for Windows with MainWindowTitle", "")
        ListBox2.Items.Clear()
        For Each p As Process In Process.GetProcesses
            If IsWindowVisible(p.MainWindowHandle) Then 'AndAlso 
            ' p.MainWindowTitle <> String.Empty Then 'AndAlso p.ProcessName _
            <> "explorer" Then
                'If p.MainWindowHandle = foregroundWindow Then
                ListBox2.Items.Add(p.MainWindowHandle.ToString & " " & _
                  p.ProcessName)
            End If
        Next
 
    End Sub
 
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e _
      As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim index As Integer = ListBox1.SelectedIndex
        Dim windowrect As RECT
        GetWindowRect(newhandlelist(index), windowrect)
        Stop
    End Sub
End Class
sicher nicht perfekt - aber das war ja nur für mich zum testen was der unterschied zwischen process und enumwindows ist.

gruss

mikeb69
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Bestimmtes Fenster im Hintergrund aktivieren2.223zimmwarrior30.06.07 13:34
Re: Bestimmtes Fenster im Hintergrund aktivieren1.314ModeratorMartoeng04.07.07 23:01
Re: Bestimmtes Fenster im Hintergrund aktivieren1.225zimmwarrior05.07.07 07:28
Re: Bestimmtes Fenster im Hintergrund aktivieren1.467mikeb6908.07.07 19:57
Re: Bestimmtes Fenster im Hintergrund aktivieren1.205zimmwarrior08.07.07 19:59
Re: Bestimmtes Fenster im Hintergrund aktivieren1.718mikeb6908.07.07 20:29
Re: Bestimmtes Fenster im Hintergrund aktivieren1.138zimmwarrior08.07.07 20:35
Re: Bestimmtes Fenster im Hintergrund aktivieren1.212mikeb6908.07.07 20:45

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

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel