AutoHotkey Community

It is currently May 27th, 2012, 11:28 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: August 28th, 2009, 9:59 am 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
Hi Guys,

What I am trying to do seems very simple, but I cannot work out what part of the code I am doing wrong.

This code, so far, is basically showing and refresing a GUI if a specific window is active. (In this instance SAP_FRONTEND_SESSION)

The GUI needs to always be on top of the active window, but not active itself.

I have tried a few option but nothing has worked. Sometimes it flashes on and off, but now it just shows on top but it does not activate the %ActiveWin%.

Code:
AppWindow = SAP_FRONTEND_SESSION

SetTimer, UpdateGUI, 500

UpdateGUI:
IfWinActive, ahk_class %AppWindow%
{
   WinGetActiveStats, ActiveWin, AWinWidth, AWinHeight, AWinX, AWinY
   GUI, Show, W500 H25 X500 Y600
   GUI, +AlwaysOnTop
   WinActivate, %ActiveWin%
}
   Else
{
   GUI, -AlwaysOnTop
}
Return


Thoughts?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 11:03 am 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
Why do you refresh your Gui via Gui, show instead via Guicontrol the changed elements?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 11:05 am 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
I had the same problem a while ago. I used to solve it like this:
Code:
....
Settimer,anzeigen,300

anzeigen:
IfWinActive,Verkaufs Center -
{
   If (angezeigt=0)
   {
      Gui, 1: Show
      angezeigt=1
      WinActivate,Verkaufs Center -
   }
}
Else
{
   IfWinActive,PLZ-Erfassung ahk_class AutohotkeyGUI
   {
      WinGet,bottom,IDLast,A
      WinGetTitle,Titel,ahk_id %bottom%
      WinGetClass,Klasse, ahk_id %bottom%
      If ("Verkaufs Center -" not in Titel)
      {
         angezeigt=0
           Gui, 1: Hide
      }
   
   }
   Else
   {
      WinGet,bottom,IDLast,A
      WinGetTitle,Titel,ahk_id %bottom%
      WinGetClass,Klasse, ahk_id %bottom%
      If ( Klasse != "AutohotkeyGUI" and Titel != "PLZ-Erfassung" )
      {
         angezeigt=0
         Gui, 1: Hide   
      }
   }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 11:43 am 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
I'm still confused... :? :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 11:49 am 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
I changed it to this, and now it is working, but it is flashing between the two windows.

Code:
AppWindow = SAP_FRONTEND_SESSION

SetTimer, UpdateGUI, 500

UpdateGUI:
IfWinActive, ahk_class %AppWindow%
{
   WinGetActiveStats, ActiveWin, AWinWidth, AWinHeight, AWinX, AWinY
   GUI, Show, W500 H25 X500 Y600
   GUI, +AlwaysOnTop
   WinActivate, %ActiveWin%
}
   Else
{
   GUI, -AlwaysOnTop
}
Return


Does anyone have a concept that will correct this?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 12:13 pm 
Offline

Joined: November 24th, 2005, 8:16 am
Posts: 851
doyle,

What are you trying to do?
When you say "Change the GUI" what do you mean?
Judging by your code, it looks to me like you are trying to make a GUI on top when there is a certain window active.

If thats the case, try something like this:
Code:
#SingleInstance Force
SetTitleMatchMode 2
AppWindow = Firefox

Gui Add, text,,Tada
Gui Show

SetTimer, UpdateGUI, 100

Return

UpdateGUI:
   If( WinActive( AppWindow ) ) {
      tooltip here
      Gui, +AlwaysOnTop
   }
   Else {
      tooltip there
      Gui, -AlwaysOnTop
   }
Return

ESC::ExitApp


Other than this, I can only suggest that you put some tooltips here and there to help you with debugging, so you know where in the script you have a problem.

_________________
Sector-Seven - Freeware tools built with AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 12:31 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
Give my script a try! Just change the window-names for you.

doyle wrote:
I changed it to this, and now it is working, but it is flashing between the two windows.

Code:
AppWindow = SAP_FRONTEND_SESSION

SetTimer, UpdateGUI, 500

UpdateGUI:
IfWinActive, ahk_class %AppWindow%
{
   WinGetActiveStats, ActiveWin, AWinWidth, AWinHeight, AWinX, AWinY
   GUI, Show, W500 H25 X500 Y600
   GUI, +AlwaysOnTop
   WinActivate, %ActiveWin%
}
   Else
{
   GUI, -AlwaysOnTop
}
Return


Does anyone have a concept that will correct this?


Code:

....
Settimer,anzeigen,300

anzeigen:
IfWinActive,Verkaufs Center -
{
   If (angezeigt=0)
   {
      Gui, 1: Show
      angezeigt=1
      WinActivate,Verkaufs Center -
   }
}
Else
{
   IfWinActive,PLZ-Erfassung ahk_class AutohotkeyGUI
   {
      WinGet,bottom,IDLast,A
      WinGetTitle,Titel,ahk_id %bottom%
      WinGetClass,Klasse, ahk_id %bottom%
      If ("Verkaufs Center -" not in Titel)
      {
         angezeigt=0
           Gui, 1: Hide
      }
   
   }
   Else
   {
      WinGet,bottom,IDLast,A
      WinGetTitle,Titel,ahk_id %bottom%
      WinGetClass,Klasse, ahk_id %bottom%
      If ( Klasse != "AutohotkeyGUI" and Titel != "PLZ-Erfassung" )
      {
         angezeigt=0
         Gui, 1: Hide   
      }
   }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 1:20 pm 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
Icarus wrote:
doyle,

What are you trying to do?
When you say "Change the GUI" what do you mean?
Judging by your code, it looks to me like you are trying to make a GUI on top when there is a certain window active.



Thanks! This worked.

I am trying to get a GUI to appear on top when a certain window is active.

But also it will move with the window. So if the window moved, when the GUI updated it would move to the new location.

That is why I had the GetWinActiveStats line in there.

What is the best way of doing this?

Having a seperate timer for moving the GUI without activating it?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 1:36 pm 
Offline

Joined: November 24th, 2005, 8:16 am
Posts: 851
You dont need a separate timer.
Also, unless you really need the window to stay available even when your app is not active, I would suggest using Hide and Show instead of AlwaysOnTop

Like this:
Code:
#SingleInstance Force
SetTitleMatchMode 2
AppWindow = Notepad2

Gui Add, text,,Tada
Gui +AlwaysOnTop
Gui Show, w100 NA
SetTimer, UpdateGUI, 10

Return


UpdateGUI:
  If( WinActive( AppWindow ) ) {
    WinGetPos X,Y,,,A
    Gui Show, x%X% y%Y% NA
  }
  Else
    Gui Hide
Return

; Another Version, with always on top instead
/*
UpdateGUI:
  If( WinActive( AppWindow ) ) {
    WinGetPos X,Y,,,A
    Gui +AlwaysOnTop
    Gui Show, x%X% y%Y% NA
  }
  Else {
    Gui -AlwaysOnTop
  }
Return
*/

ESC::ExitApp

_________________
Sector-Seven - Freeware tools built with AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 1:41 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
I think he needs a timer for that. With your code, Icarus, the ahk-window is always active, not the window behind it where the ahk-window shall be docked at.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 1:43 pm 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
You guys rock!

Currently I have gone with this....

Code:
AppWindow = ahk_class SAP_FRONTEND_SESSION
ProgramName = SAP Navigator

[code]Gui, Font, s8
Gui Add, text,,%ProgramName%
Gui, -Caption
Gui Show, W500 H25,%ProgramName%

SetTimer, UpdateGUI, 100

Return

UpdateGUI:
   If( WinActive( AppWindow ) )
   {
   WinGetActiveStats, Title, WinW, WinH, WinX, WinY
      Gui, +AlwaysOnTop
     GuiX:= WinX + 300
     GuiY:= WinY + 20
     WinMove, %ProgramName%,, %WinX%, %WinY%
   }
   Else
   {
      tooltip there
      Gui, -AlwaysOnTop
   }
Return

ESC::ExitApp [/code]


Works like a charm.

Is there anything im fundamentally overlooking though?

I'd like to become a proficient coder, and realise that my way of doing things could not be the most efficient way.

Thanks again!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 1:51 pm 
Offline

Joined: November 24th, 2005, 8:16 am
Posts: 851
Just that you are assigning GuiX / GuiY and never use them... :)
doyle wrote:
Is there anything im fundamentally overlooking though?

_________________
Sector-Seven - Freeware tools built with AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 1:58 pm 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
Icarus wrote:
Just that you are assigning GuiX / GuiY and never use them... :)
doyle wrote:
Is there anything im fundamentally overlooking though?


Yeh, that was a mistake on my part. :)

I was meant to use them in the WinMove command.

Code:
AppWindow = ahk_class SAP_FRONTEND_SESSION
ProgramName = SAP-Nav
LocX = 400
LocY = 70

Gui, Color, 95B2C3
Gui, Font, s6, Verdana
Gui, Font, s8, Calibri
Gui Add, text,,%ProgramName%
Gui, -Caption
Gui Show, W500 H25,%ProgramName%

SetTimer, UpdateGUI, 100

Return

UpdateGUI:
   If( WinActive( AppWindow ) )
   {
   WinGetActiveStats, Title, WinW, WinH, WinX, WinY
      Gui, +AlwaysOnTop
     GuiX:= WinX + LocX
     GuiY:= WinY + LocY
     WinMove, %ProgramName%,, %GuiX%, %GuiY%
   }
   Else
   {
   Gui, -AlwaysOnTop    
   }
Return

ESC::ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject: SAPGui auto refresh
PostPosted: November 18th, 2009, 7:08 pm 
I have used the below script sucesfully for a lot of SAP transactions - just follow the following steps:

1. Logon to SAP
2. start transaction e.g. SM66 "Global Work Process Overview"
3. execute AHK script
- enter the refresh time in msec - e.g. 5000 for 5 sec
- enter the name of the Windows e.g. Global
- enter the Key for refresh - e.g. F8

have fun

Code:
DelayTime = 0
While DelayTime < 1000
{
  InputBox, DelayTime, Delay Time, Please enter delay Time in msec, , 300, 150, , , , 10000, 5000
  if DelayTime < 1000
  {
    MsgBox, Please Enter a Value of 1000 or more
  }
}

LOOP
{
   InputBox, WindowTitle, SAP Windows Title, Specify Window Title, , 300, 150, , , , , e.g. SAP Easy Access
  IfWinExist, %WindowTitle%
  {
    WinGet, VarID, ID, %WindowTitle%
    break
  }
}

InputBox, RefreshKey, Refresh Command Key, Specify Refresh Command Key - eg. F8, , 300, 150, , , , , F8

wtime := 1 / 10
wtime := wtime * DelayTime / 100
 
DEFsleep = 200
LNGSleep = 1000

SetTitleMatchMode, 1

LOOP
{
   ActiveWin := WinExist("A")
  IfWinExist, "ahk_id %VarID%"
  {

    WinWait, "ahk_id %VarID%",
    IfWinNotActive, "ahk_id %VarID%", , WinActivate, "ahk_id %VarID%",
    WinWaitActive, "ahk_id %VarID%",
    Send, ^/
    WinWait, "ahk_id %VarID%",
    Sleep, 100
    IfWinNotActive, "ahk_id %VarID%", , WinActivate, "ahk_id %VarID%",
    WinWaitActive, "ahk_id %VarID%",
    Send, {%RefreshKey%}
  }
  WinActivate "ahk_id %ActiveWin%"

;   *********** Pause / Continue / Cancel ***********
    stime := A_TickCount
    LOOP
    {
       If vBreak = True 
       {
          vBreak = False
          SoundPlay *16
          Break
       }     
       etime := A_TickCount
      dtime := ( etime - stime ) / 1000
       if ( dtime > wtime )
       {   
          SoundPlay *64
          Sleep, %DEFSleep%
          SoundPlay *64
          break
       }
    }
 
}

#Pause::
vBreak = True
Pause
return   


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2009, 8:37 pm 
Offline

Joined: August 10th, 2009, 8:31 pm
Posts: 20
The script posted by Doyle is exactly what I was looking for. I have attempted to change it so that a small gui window follows and sticks to the window which is set to always-on-top (Exstyle WS_EX_TOPMOST). Basically, I'm trying to get a visual marker for windows which are set to always-on-top, because sometimes it can be confusing not knowing which ones are set to topmost. The problem I'm having is that I'm not sure how to change two key parts of the script:

AppWindow = ahk_class SAP_FRONTEND_SESSION
ProgramName = SAP-Nav

I would need both the AppWindow and ProgramName values to represent the window which currently has the WS_EX_TOPMOST style. I tried using WinGet ExStyle but I just can't get it to work. If anyone has any ideas, please share :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group