FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to Get hWnd from Process ID
Posts: 153
Joined: Tue Aug 05, 2014 09:48 AM
How to Get hWnd from Process ID
Posted: Mon Aug 11, 2014 06:27 PM

How to get Windows / running program handle from Process ID or Title Name

Regards, Greetings



Try FWH. You will enjoy it's simplicity and power.!
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: How to Get hWnd from Process ID
Posted: Mon Aug 11, 2014 08:24 PM
Try this (and thank Enrico if it works for you):

James

Code (fw): Select all Collapse
// Purpose: Find handle of window of running application
//          Else returns nil
// Author : Enrico Maria Giordano
// Date   : 1/10/2005


#include "Fivewin.ch"


#define GW_HWNDNEXT 2


FUNCTION MAIN()

    ? FINDWND( "Carrot" )

RETURN NIL


FUNCTION FINDWND( cTitle )

    LOCAL hWnd := GETFOREGROUNDWINDOW()

    WHILE hWnd != 0
        IF GETWINDOWTEXT( hWnd ) = cTitle
            RETURN hWnd
        ENDIF

        hWnd = GETWINDOW( hWnd, GW_HWNDNEXT )
    ENDDO

RETURN NIL


DLL32 FUNCTION GETFOREGROUNDWINDOW() AS LONG;
      PASCAL FROM "GetForegroundWindow" LIB "user32.dll"
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 153
Joined: Tue Aug 05, 2014 09:48 AM
Re: How to Get hWnd from Process ID
Posted: Tue Aug 12, 2014 04:07 AM
James Bott wrote:Try this (and thank Enrico if it works for you):
James

Excellent
Thank you, Sir
I am searching hWnd from PID, How to use Linked code can be in fwh
http://stackoverflow.com/questions/11711417/get-hwnd-by-process-id-c
Regards
Regards, Greetings



Try FWH. You will enjoy it's simplicity and power.!
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to Get hWnd from Process ID
Posted: Tue Aug 12, 2014 10:10 AM
Dave,

You can use:

FindWindow( 0, cApplication_Main_Window_Title ) --> hWnd

http://wiki.fivetechsoft.com/doku.php?id=fivewin_function_findwindow
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 153
Joined: Tue Aug 05, 2014 09:48 AM
Re: How to Get hWnd from Process ID
Posted: Tue Aug 12, 2014 10:32 AM

Sir,
I have to trap all the running program hWnd,

Regards, Greetings



Try FWH. You will enjoy it's simplicity and power.!
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to Get hWnd from Process ID
Posted: Tue Aug 12, 2014 10:40 AM
Dave,

From FWH errorsys we create this way the list of the running apps, not sure if this is what you need:

Code (fw): Select all Collapse
   aTasks = GetTasks()
   cErrorLog += "   Windows total applications running: " + ;
                AllTrim( Str( Len( aTasks ) ) ) + CRLF
   for n = 1 to Len( aTasks )
      cErrorLog += "    " + Str( n, 3 ) + " " + aTasks[ n ] + CRLF
   next
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion