Tıkladığım pencere ismini nasıl bulurum?

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Uzman Üye
Katılım
11 Şub 2018
Mesajlar
205
Tepki puanı
20
8 HİZMET YILI
Merhaba. Örneğin abc.exe isimli uygulamanın penceresine 1 kez sol tık ile tıkladım o tıkladığım pencereye yani hangisine tıkladıysam bu bencerenin görev yöneticisindeki exe ismini yani process namesini textbox1 e yazmasını istiyorum. Bunu nasıl yapabilirim? Teşekkürler..
 
aka panic.rs
Kurucu
Katılım
18 Haz 2015
Mesajlar
3,379
Çözümler
50
Tepki puanı
13,156
Ödüller
22
Sosyal
10 HİZMET YILI
C++ için GetForegroundwindow - GetActivewindow Winapileri mevcut
bunları vb.net üzerinde pinvoke yardımı ile kullanabilirsin.
 
aka panic.rs
Kurucu
Katılım
18 Haz 2015
Mesajlar
3,379
Çözümler
50
Tepki puanı
13,156
Ödüller
22
Sosyal
10 HİZMET YILI
VB.Net Örnek hazırladım bu vb.neti pek bilmesemde kendi işimi görebiliyorum
fGHugw.jpg



VB.Net:
Imports System.Runtime.InteropServices

Public Class Form1
    <DllImport("user32.dll", SetLastError:=True)>
    Private Shared Function GetForegroundWindow() As IntPtr
    End Function
    <DllImport("user32.dll", EntryPoint:="GetWindowThreadProcessId")>
    Private Shared Function GetWindowThreadProcessId(<InAttribute()> ByVal hWnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer
    End Function
    <DllImport("user32.dll")>
    Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) As Short
    End Function
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        '' Code By LeftSpace
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If GetAsyncKeyState(Keys.LButton) <> 0 Then '' Sol Mouse tuşu basılıysa
            Dim aPencere As IntPtr = GetForegroundWindow() '' aktif pencereyi alıyoruz
            Dim aProcOut As Integer = Nothing  '' processid değişkenimiz
            GetWindowThreadProcessId(aPencere, aProcOut) '' burada pencere hwnd ile processid öğreniyoruz

            If aProcOut Then '' processid var ise textbox texte aktarıyoruz
                TextBox1.Text = aProcOut.ToString()
                '' olası hata yakalama
                Try
                    '' veya direk GetProcessById İlede olabilir
                    For Each tmp As Process In Process.GetProcesses()
                        If tmp.Id = aProcOut Then
                            TextBox2.Text = tmp.ProcessName
                        End If
                    Next
                    '' GetProcessByID örneği

                    TextBox2.Text = Process.GetProcessById(aProcOut).ProcessName
                Catch ex As Exception

                End Try
            End If
        End If
    End Sub
End Class
 
Son düzenleme:
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst