PID (ProcessID) ile Handle(HWND) almak

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Jire
Üye
Mesajlar: 167
Kayıt: 07 Eki 2007 01:20

PID (ProcessID) ile Handle(HWND) almak

Mesaj gönderen Jire »

Merhaba.
Elimde bu kod var.
Amacımı kısaca anlatayım belki başka bir kod biliyorsanız verebilirsiniz.
Amacım, (ProcessID'yi biliyorum) PID'den Pencerenin Handle'ını almak.
Ve bu aynen bu dediğimi yapıyor ancak fazla VB bilgim olmadığı için çeviremedim.
Bilen arkadaş varsa çevirebilirmi çevirirse sonsuz teşekkür.

Kod: Tümünü seç

' Return the window handle for an instance handle.
Private Function InstanceToWnd(ByVal target_pid As Long) As _
    Long
Dim test_hwnd As Long
Dim test_pid As Long
Dim test_thread_id As Long

    ' Get the first window handle.
    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)

    ' Loop until we find the target or we run out
    ' of windows.
    Do While test_hwnd <> 0
        ' See if this window has a parent. If not,
        ' it is a top-level window.
        If GetParent(test_hwnd) = 0 Then
            ' This is a top-level window. See if
            ' it has the target instance handle.
            test_thread_id = _
                GetWindowThreadProcessId(test_hwnd, _
                test_pid)

            If test_pid = target_pid Then
                ' This is the target.
                InstanceToWnd = test_hwnd
                Exit Do
            End If
        End If

        ' Examine the next window.
        test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
    Loop
End Function
Dün akşam biraz uğraştım yaptım fonksiyonu sanırsam ama çalıştığından emin değilim.

Kod: Tümünü seç

function InstanceToWnd(target_pid: Pointer):Integer;
var
test_hwnd: HWND;
test_pid: Pointer;
test_thread_id: Integer;
begin

    test_hwnd := FindWindow('Knight OnLine Client', 'Knight OnLine Client');

    While test_hwnd <> 0 do
    begin

    if GetParent(test_hwnd) = 0 then
    begin
    test_thread_id := GetWindowThreadProcessId(test_hwnd, @test_pid);

    if test_pid = target_pid then
    begin
    InstanceToWnd := test_hwnd;
    end;
    end;

    test_hwnd := GetWindow(test_hwnd, GW_HWNDNEXT);
    end;
end;
Cevapla