FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Getting the current active window handle
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Getting the current active window handle
Posted: Tue Dec 09, 2014 11:59 AM

Hi all,
I'm trying to get the handle of the current active window but without success.
I made this self-contained sample that show the problem. It runs in background without a Windows active and check every 20 seconds which is the current active window (es. I'm on Skype so it should return the Skype handle) but it Always return 0. Any ideas ? Thank you.


include "FiveWin.ch"

function Main()

local n,hwnd
n:=Seconds()

do while .t.
sysrefresh()
if seconds()>n+20
hWnd:=GetActiveWindow()
if msgyesNo("Active Window handle is "+str(hWnd,10)+" Finish test ?")
exit
endif
n:=Seconds()
endif
enddo


Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 01:44 PM
Code (fw): Select all Collapse
#include "FiveWin.ch"

STATIC oWnd

function Main()

   local n,hwnd

   n:=Seconds()

   do while .t.

      sysrefresh()

      if seconds()>n+20

         //hWnd:=GetActiveWindow()
         
         hWnd := ShellExecute( GetActiveWindow() )

         if msgyesNo("Active Window handle is "+str(hWnd,10)+" Finish test ?")

            exit

         endif

         n:=Seconds()

      endif

   enddo

Return nil


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 03:19 PM

Hi, thank you,
I tried, also as Shellexecute(0,GetActiveWindow()) but always return 42

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 04:08 PM

What should return?

Regards,

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 04:25 PM

Hi,
due the sample hasn't a window,
I think if I'm working on Skype it should report the Skype handle,
if I'm on OpenOffice it should return the OpenOffice handle,
...
that's what I'm looking for.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 04:37 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 04:41 PM

Essentially I need to know which window (software) has the focus.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 04:51 PM
Code (fw): Select all Collapse
STATIC FUNCTION test_in(Arg1)

   SysWait(10)

   IF( GetActiveWindow()==0 )
      ? "I am in... "
   ELSE
       ? "Do not exit the program"
   ENDIF

RETURN(.T.)
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 05:16 PM

The problem is that if I execute the sample and then I go to Skype, or any other Windows app, GetActiveWindos always return 0 instead of the handle of Skype or the app with the focus.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 05:34 PM

You should to use a similar function to fivewin GetTask(), using window caption so "SKYPE" $ GetWindowText()

Look at GetTask() function on fwh.

Too can to use GetForegroundWindow() for active window.

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Getting the current active window handle
Posted: Tue Dec 09, 2014 05:51 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Getting the current active window handle
Posted: Wed Dec 10, 2014 08:30 AM

Nothing to do. There are still a lot of problems reactivating the original window.
I have bypassed the problem in 4 rows using AutoHotKey Scripting Language.

WinGetActiveTitle, Title
WinActivate, Connect
Send {Right}
WinActivate, %Title%

Thank you for your kind support.

Best Regards,



Marco Turco

SOFTWARE XP LLP

Continue the discussion