Always on Top gui with a button in it to set windows always on top problem Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
OCP
Posts: 98
Joined: 28 Mar 2018, 19:28

Always on Top gui with a button in it to set windows always on top problem

28 Apr 2018, 12:55

hello

i made a gui with all my hotkeys the gui is always on top

i want to add a button that sets the window that was active before i hit the knob always on top to always on top is this possible?

any help is appreciated thank you
Last edited by OCP on 26 Jul 2018, 22:38, edited 1 time in total.
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Always on Top gui with a button in it to set windows always on top problem

28 Apr 2018, 13:33

try this

Code: Select all

Gui, +AlwaysOnTop
Gui, Add, Button, x72 y50 w100 h30 gSwitch, Button
; Generated using SmartGUI Creator for SciTE
Gui, Show, w258 h142, My Gui Title
return

GuiClose:
ExitApp
return

Switch:
Gui, -AlwaysOnTop
WinMinimize, My Gui Title
;~ Send, !{Tab}
AlwaysOnTop_ = 0
return

#If !AlwaysOnTop_

~LButton::
KeyWait, LButton, U
IfWinActive, My Gui Title
{
	Gui, +AlwaysOnTop
	AlwaysOnTop_ = 1
}
return
:wave: There is always more than one way to solve a problem. ;)
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Always on Top gui with a button in it to set windows always on top problem

28 Apr 2018, 16:23

YoucefHam wrote:... There is always more than one way to solve a problem.
Wow. Outstanding solving skills. :lol: :lol:
Einfach nur ein toller Typ. :mrgreen:
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Always on Top gui with a button in it to set windows always on top problem

28 Apr 2018, 17:10

OCP wrote:hello

i made a gui with all my hotkeys the gui is always on top

i want to add a button that sets the window that was active before i hit the knob always on top to always on top is this possible?

any help is appreciated thank you
While what you are looking to do is not imposable, I would think that it is impractical, and probably not the best approach to setting your windows to AlwaysOnTop.

The simpler method would be to hit your button and then have the next window you activate set to alwaysOnTop, but I have to assume that you are aware of that and still want it the way you have described.

Before I begin, understand that there could be a more direct method of doing this, but because I don't know what that is I have to invent one to make progress.

That said, I think the way that I would approach this problem would be to use 3 variables to hold the names (or maybe better, the process Id) of your windows.

One var would be something like Old_window, another one would be Last_window and the last one would be Current_window.
I would start by checking to see if the current_window is the same as Last_window, if they are the same I would do nothing, however if they are different I would set the value of Old_window to be the value in Last_window, and then set Last_window to be the value of current_window.

That handles setting it up so that the window you will be setting as AlwaysOnTop is the window in the variable Old_window.
Ok, the next thing to work out is how are you going to actually be getting the names/Id of the different windows? I think I would look to see what "OnMessage" gets triggered when you select a window. I have not had too much need to use windows messages so I can't say the one that would fit this, but I'll have a look and see if I can find one that does what I am talking about. Perhaps in the mean time, you can try looking over the list and testing, or someone that knows a better approach or the right message to use will come along.

With the assumption that it would be a message that is looking to see when a window is activated, or any other message for that matter. In it, you would use wingettitle, or wingetId, or w/e to get the value to put into your Current_window variable. Then you do the check as described above.

So, now you have a var with the last window set into the var Old_window, when you hit your button you will use your winset, AlwayOnTop on that window.

Well, without knowing any better, that is the approach I would take.

Alternative, I would just use a timer set for every 300 ms or so that does all that stuff. It would be simpler for me to get to my goal and make progress, so if I didn't find a message to do this within a few mins of testing I am pretty sure I would go that route, but that's just me, and I don't give two $%!&$ if it is the "BEST WAY". Progress is progress, and I can pick up new things tomorrow :)
OCP
Posts: 98
Joined: 28 Mar 2018, 19:28

Re: Always on Top gui with a button in it to set windows always on top problem

28 Apr 2018, 18:02

Try This
have to say that code is pretty clever and its giving me some cool other ideas like perhaps a way to make my next left click the location to execute a series of events that way i could make buttons to add plugins in my audio projects on desired slots

i think what you posted will work in some form it would cause my gui to disappear for a bit i suspect (perhaps a nice visual clue to that it happened dunno have to see what i like and also i probably need to tab backwards) i got some testing to do tomorrow first some sleep :) thnx for that code its a keeper
The simpler method would be to hit your button and then have the next window you activate set to alwaysOnTop, but I have to assume that you are aware of that and still want it the way you have described.
very true but the situation i use this in involves 2 screens filled with stuff i need to see, the moment i open something extra to see and i click somewhere it moves to background

what you suggest for the next window could work if i can also select stuff that is currently active in the taskbar so i can just click there on the active icon to make it always on top

the rest you said, i have to get some sleep first :)
And I don't give two $%!&$ if it is the "BEST WAY". Progress is progress
I agree

thnx once again
Last edited by OCP on 26 Jul 2018, 22:39, edited 1 time in total.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Always on Top gui with a button in it to set windows always on top problem  Topic is solved

28 Apr 2018, 19:59

Image

Code: Select all

#SingleInstance,Force
Gui,+AlwaysOnTop -Caption +Border
Gui,Color,Black
Gui,1:Font,s10 Q4, Segoe UI Black
Gui,Add,Progress,x0 y0 w240 h2 BackgroundYellow 
Gui,Add,Progress,x0 y123 w240 h2 BackgroundYellow 
Gui,Add,Progress,x0 y0 w2 h125 BackgroundYellow 
Gui,Add,Progress,x238 y0 w2 h125 BackgroundYellow 
Gui,Add,Text,cAqua x5 y2 w30 h20 Border Center gTag,HB
Gui,1:Font,s10 Underline Q4, Segoe UI Black
Gui,Add,Text,cYellow x60 y2 w120 h20 Border Center gMove_window,Move Window
Gui,1:Font,
Gui,1:Font,s10 Q4, Segoe UI Black
Gui,Add,Text,cRed x+16 y2 w20 h20 Border Center gMin_window,-
Gui,Add,Text,cRed x+0 y2 w20 h20 Border Center gGuiClose,x
Gui,Add,Checkbox,cLime x10 y+7 Checked vAlways gAOT,AlwaysOnTop
Gui,Add,Button,x10 y+7 w220 gSet_Next_On_Top -Theme,Set Next Win On Top
Gui,Add,Button,x10 y+7 w220 gSet_Last_On_Top -Theme,Set Last Win On Top
Gui,Show,w240 h125,Random Gui
Gui,Submit,NoHide
SetTimer,Update_Window,100
return

GuiClose:
	ExitApp
	
Min_Window:
	Gui,Minimize
	return
	
Move_Window:
	PostMessage,0xA1,2
	return
	
Tag:
	TrayTip,,Hellbent Was Here!,3
	return

AOT:
	if(Always:=!Always)
		Gui,+AlwaysOnTop
	else
		Gui,-AlwaysOnTop
	return

Set_Next_On_Top:
	While(!GetKeyState("ctrl"))
		Tooltip, Activate the window to set on top and then press "ctrl"
	Tooltip,
	Winset,AlwaysOnTop,Toggle,A
	return

Set_Last_On_Top:
	WinSet,AlwaysOnTop,Toggle,ahk_id %Old_Window%
	return

Update_Window:
	;~ DetectHiddenWindows, On                                   ; https://autohotkey.com/docs/commands/DetectHiddenWindows.htm
	;~ SetTitleMatchMode,                                        ; https://autohotkey.com/docs/commands/SetTitleMatchMode.htm
	WinGet, Current_Window,ID,A                                  ; https://autohotkey.com/docs/commands/WinGet.htm
	;~ WinGet, Current_Window,ProcessName,A                      ; https://autohotkey.com/docs/commands/WinGet.htm
	;~ WinGet, Current_Window,PID,A                              ; https://autohotkey.com/docs/commands/WinGet.htm
	;~ WinGetClass,Current_Window,A                              ; https://autohotkey.com/docs/commands/WinGetClass.htm
	;~ WinGetText,Current_Window,A                               ; https://autohotkey.com/docs/commands/WinGetText.htm
	;~ WinGetTitle,Current_Window,A                              ; https://autohotkey.com/docs/commands/WinGetTitle.htm
	;~ ToolTip,% Current_Window "`n" Last_Window "`n" Old_Window
	if(Current_Window!=Last_Window)
		Old_Window:=Last_Window,Last_Window:=Current_Window
	return


*^ESC::ExitApp
This has the ability to make the last window to toggle AlwaysOnTop, and it has the ability to set whatever window you want set as AlwaysOnTop.
It also has a example of making your gui toggle between the states.
Just pick the method that suits your needs and bam, Bob's your uncle ;)
OCP
Posts: 98
Joined: 28 Mar 2018, 19:28

Re: Always on Top gui with a button in it to set windows always on top problem

29 Apr 2018, 04:18

thnx Hellbent that is just what i wanted i like bolt options but i am gonna use set last window on top for my situation

bob likes it :) he will have to buy you some coffee on his next payday

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Ineedhelplz and 324 guests