Must be easy to set window on top. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Must be easy to set window on top.

21 Oct 2021, 05:01

All I want, when I run calc.exe set its windows on top of all windows. But I could not do it. Can you please send me a sample?
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Must be easy to set window on top.

21 Oct 2021, 05:30

Code: Select all

#SingleInstance Force
Try Menu, Tray, Icon, %A_WinDir%\System32\calc.exe
SoundBeep, 1700
Loop {
 WinWait, Calculator ahk_exe ApplicationFrameHost.exe
 WinSet, AlwaysOnTop, On
 SoundBeep, 1500
 WinWaitClose
 SoundBeep, 1000
}
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Must be easy to set window on top.

21 Oct 2021, 06:20

Exactly what happened when you ran the script, and then ran calc.exe?

What version of Windows do you have?

If you run Window Spy and then activate Calc, what is the complete WinTitle shown there? You can post a screenshot of Window Spy.
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Must be easy to set window on top.

21 Oct 2021, 06:46

Nothing happened.

My calc path is: C:\Windows\System32\calc1.exe
ahk_class CalcFrame
ahk_exe calc1.exe
Version 1.1.33.02

Actually what I need is simple, no tray so sound is needed. When I manually run calc.exe with mouse click, then it should automaticly stay on top.
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Must be easy to set window on top.  Topic is solved

21 Oct 2021, 07:17

Code: Select all

#SingleInstance Force
Try Menu, Tray, Icon, %A_WinDir%\System32\calc1.exe
SoundBeep, 1700
Loop {
 WinWait, ahk_exe calc1.exe
 WinSet, AlwaysOnTop, On
 SoundBeep, 1500
 WinWaitClose
 SoundBeep, 1000
}
If you click on the commands in the posted script, you can learn more about how they work. After you get the script working, you can delete the sound commands.
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Must be easy to set window on top.

21 Oct 2021, 07:35

One more thing, I also have some other command in script file. If I put this in middle of script, it does not work, but when at top of script file, It runs fine. So what must I consider of when managing multible commands?
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Must be easy to set window on top.

21 Oct 2021, 07:44

When I put this code at top of script file that also has some other command then it work but when at bottom or middle of file it does not work. So what must I watch for when using many commands at single script file?
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Must be easy to set window on top.

21 Oct 2021, 07:45

Also how can I add second app to this loop?
RussF
Posts: 1242
Joined: 05 Aug 2021, 06:36

Re: Must be easy to set window on top.

21 Oct 2021, 08:17

How do you have two or more apps always on top? Which one wins?
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Must be easy to set window on top.

21 Oct 2021, 08:22

RussF wrote:
21 Oct 2021, 08:17
How do you have two or more apps always on top? Which one wins?
Not at same time. Might be notepad.exe, Calc.exe whichever runs.
fenchai
Posts: 292
Joined: 28 Mar 2016, 07:57

Re: Must be easy to set window on top.

21 Oct 2021, 08:32

RussF wrote:
21 Oct 2021, 08:17
How do you have two or more apps always on top? Which one wins?
they get a special layer, separated from the other windows which are not on "always on top", they fight for whichever has the current focus from your mouse.
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Must be easy to set window on top.

21 Oct 2021, 08:38

This section goes at the top.

Explained: Auto-execute
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Must be easy to set window on top.

21 Oct 2021, 09:09

I think which one runs at last will be on top. But my request it not about it. I need to add more app to loop and if it is running, should be on top.
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Must be easy to set window on top.

21 Oct 2021, 09:14

You may want to use a shell hook to determine when a specific window appears. https://autohotkey.com/board/topic/32628-tool-shellhook-messages/
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Must be easy to set window on top.

21 Oct 2021, 09:19

Can not I simply add more loop like:

Code: Select all

Loop {
WinWait, ahk_exe calc1.exe
WinSet, AlwaysOnTop, On
}

Loop {
WinWait, ahk_exe notepad.exe
WinSet, AlwaysOnTop, On
}
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Must be easy to set window on top.

21 Oct 2021, 10:18

What happened when you tried it?
ozgurerdogan
Posts: 47
Joined: 27 Apr 2017, 02:32
Contact:

Re: Must be easy to set window on top.

21 Oct 2021, 10:23

notepad.exe does not come to on top but calc1.exe
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Must be easy to set window on top.

21 Oct 2021, 10:31

The first loop is infinite, so the second loop is never reached. To understand it, follow the script line by line, one line at a time. When the first closing brace is reached, the first loop repeats itself instead of proceeding to the next line.

Code: Select all

DllCall("RegisterShellHookWindow", "UInt", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "onTop")
Return

onTop(wParam, lParam) {
 If (wParam > 2)
  Return
 WinGet, pname, ProcessName, % wTitle := "ahk_id " lParam
 SplitPath, pname,,,, fnBare
 If fnBare not in calc1,calc,notepad,Calculator
  Return
 If (wParam = 1 && fnBare = "Calculator")
  Return
 SoundBeep, 1700
 WinSet, AlwaysOnTop, On, % fnBare = "Calculator" ? "Calc ahk_exe ApplicationFrameHost.exe" : wTitle
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], marypoppins_1 and 137 guests