// Returns an array with the names of all the active Tasks running in Windows
//----------------------------------------------------------------------------//
function GetTasks()
local hWnd := GetWindow( GetActiveWindow(), GHW_HWNDFIRST )
local aTasks := {}
local cTask,oLdGetTasks:=.T.,hLib32:=0,RetByte:=0,BufTask
// Verify if the API exist if not it's Windows 95 or Less
// or Windows NT with SP2 or less so we will use the old technique
if ABS(hLib32:=Loadlib32("USER32.DLL")) > 32 // Can be Windows 3.11 or Lower
if substr(Getproc32(hLib32,"GetWindowModuleFileNameA",.T.,LONG,),1,4)<> CHR(0)+CHR(0)+CHR(0)+CHR(0)
oLdGetTasks:=.f.
BufTask:=space(200)
endif
Freelib32(hLib32)
endif
while hWnd != 0
if oLdGetTasks
#ifdef __CLIPPER__
cTask = GetModuleFileName( GetWindowWord( hWnd, GWW_HINSTANCE ) )
#else
// cTask = GetModuleFileName( GetWindowLong( hWnd, GWW_HINSTANCE ) )
cTask = GetWindowText( hWnd ) // The above does now work :-(
#endif
else
Retbyte:=GetWModFileName( hWnd, BufTask, 200 )
cTask:=left(BufTask,Retbyte)
endif
if ! Empty(cTask)
if AScan( aTasks, cTask ) == 0
AAdd( aTasks, cTask )
endif
endif
hWnd = GetWindow( hWnd, GHW_HWNDNEXT )
end
return aTasks
//----------------------------------------------------------------------------//
DLL32 FUNCTION GetWModFileName( hWnd AS LONG, cBuf AS LPSTR, nLong AS LONG ) ;
AS LONG PASCAL FROM "GetWindowModuleFileNameA" LIB "USER32.DLL"
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
#ifdef __GNUC__
WINBASEAPI DWORD WINAPI GetWindowModuleFileName( HWND, LPTSTR, DWORD );
#endif
HB_FUNC( GETWINDOWMODULEFILENAME )
{
#ifndef _WIN64
HWND hWnd = ( HWND ) hb_parnl( 1 );
#else
HWND hWnd = ( HWND ) hb_parnll( 1 );
#endif
DWORD dwLength = 0;
char buffer[ 1024 ];
dwLength = GetWindowModuleFileName( hWnd, buffer, dwLength );
hb_retclen( buffer, dwLength );
}
#pragma ENDDUMP
#include "FiveWin.ch"
static aTasks
//----------------------------------------------------------------------------//
function GetTasks()
local aTask
aTasks = {}
EnumChildWindows( GetDesktopWindow(), { | hWnd | AddTask( hWnd ) } )
for each aTask in aTasks
aTask = aTask[ 1 ] + ", " + aTask[ 2 ]
next
return ASort( aTasks )
//----------------------------------------------------------------------------//
static function AddTask( hWnd )
local cTaskName := Space( 100 )
GetWindowModuleFileName( hWnd, cTaskName, 100 )
if AScan( aTasks, { | aTask | aTask[ 2 ] == cTaskName } ) == 0
AAdd( aTasks, { GetWindowText( hWnd ), cTaskName } )
endif
return nil
//----------------------------------------------------------------------------//
DLL FUNCTION GetWindowModuleFileName( hWnd AS LONG, cName AS LPSTR, nLen AS LONG ) ;
AS LONG PASCAL FROM "GetWindowModuleFileNameA" LIB "user32.dll"
Return to WhatsNew / Novedades
Users browsing this forum: No registered users and 20 guests