Getting the current active window handle

Getting the current active window handle

Postby Marco Turco » 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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Getting the current active window handle

Postby karinha » Tue Dec 09, 2014 1:44 pm

Code: Select all  Expand view

#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
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Getting the current active window handle

Postby Marco Turco » Tue Dec 09, 2014 3:19 pm

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

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Getting the current active window handle

Postby karinha » Tue Dec 09, 2014 4:08 pm

What should return?

Regards,
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Getting the current active window handle

Postby Marco Turco » Tue Dec 09, 2014 4: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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Getting the current active window handle

Postby karinha » Tue Dec 09, 2014 4:37 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Getting the current active window handle

Postby Marco Turco » Tue Dec 09, 2014 4:41 pm

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

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Getting the current active window handle

Postby karinha » Tue Dec 09, 2014 4:51 pm

Code: Select all  Expand view

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
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Getting the current active window handle

Postby Marco Turco » Tue Dec 09, 2014 5: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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Getting the current active window handle

Postby hmpaquito » Tue Dec 09, 2014 5: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.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Getting the current active window handle

Postby karinha » Tue Dec 09, 2014 5:51 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Getting the current active window handle

Postby Marco Turco » Wed Dec 10, 2014 8: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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 77 guests