remin Posted October 16, 2013 Posted October 16, 2013 (edited) How can I check if a window is on top or not? I thought WinGetState would do it but there is no value for on top window. any idea? Edited October 16, 2013 by remin
Moderators Melba23 Posted October 16, 2013 Moderators Posted October 16, 2013 remin,WinList returns the windows in z-order (topmost first). But you need to trim the list a bit to get sensible results: #include <Array.au3> ; Get a list of all windows $aList = WinList() ; Loop up through the array For $i = $aList[0][0] To 1 Step -1 ; If there is no title or the window is not visible If $aList[$i][0] = "" Or (Not BitAND(WinGetState($aList[$i][1]), 2)) Then ; Remove it _ArrayDelete($aList, $i) EndIf Next ; Results are in z-list order _ArrayDisplay($aList)All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
remin Posted October 16, 2013 Author Posted October 16, 2013 (edited) Oeps... Thank you for your reply Melba. I find this very difficult. On my list ($aList) I had 2 windows before the one I made "On top" using an .ahk script: ^SPACE:: Winset, Alwaysontop, , A What I want to do is to create a simple Always On Top toggle hotkey in autoit (like the one above) Edited October 16, 2013 by remin
Moderators Melba23 Posted October 16, 2013 Moderators Posted October 16, 2013 remin,Perhaps if you use the WinSetOnTop function when running the HotKey:#include <GUIConstantsEx.au3> HotKeySet("^t", "_SendToTop") $hGUI = GUICreate("Test", 500, 500) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _SendToTop() ; Send to top Winactivate($hGUI) ; And keep it there WinSetOnTop($hGUI, "", 1) EndFuncHow is that? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
remin Posted October 16, 2013 Author Posted October 16, 2013 Thank again for your nice reply This only set the "on top" status, isn't it? How can I remove this status when the window has already an "on top" status?
Moderators Melba23 Posted October 16, 2013 Moderators Posted October 16, 2013 remin,Have you discovered the excellent Help file yet? If not then I do recommend that you use it - it would tell you that you can use WinSetOnTop to change the ONTOP status:Determines whether the window should have the "TOPMOST" flag set. 1=set on top flag, 0 = remove on top flagSo all you need do is use the correct parameter and Robert is your mother's brother. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
remin Posted October 16, 2013 Author Posted October 16, 2013 (edited) Oh yes I started to read the excellent help file. True, it is done very well. But I couldn't find out how to toggle the On Top status and detect the status of a window. Still don't understand it, sorry. I started to be an autohotkey user. Then I found out that I prefer the autoit code. Easier and more like Basic and even more important, Autoit scripts seems to create less problems (in my case). (Maybe because an .au3 file seems to be active even in non-active mode (it always has an 0,05 % cpu usage), unlike an .ahk file which seems to go in sleep mode and doesn't react always as it has to do). But I noted that a few things are more difficult to obtain in autoit p.e. Toggle on top mode (is only 1 line code in AHK) and a few more things. Maybe I have to stop trying to convert all my AHK scripts to Autoit and use the best Script language for every need I have. Both can run together isn't it? BTW.. thank you for your time you've dedicated to my question. Edited October 16, 2013 by remin
Moderators Melba23 Posted October 16, 2013 Moderators Posted October 16, 2013 remin,If this a GUI you are creating then I suggest you use a flag of some sort to indicate the current status of the GUI - then the HotKey can adjust its action. I use a label in this snippet:#include <GUIConstantsEx.au3> HotKeySet("^t", "_SendToTop") $hGUI = GUICreate("Test", 100, 100) $cLabel = GUICtrlCreateLabel("Not on Top", 10, 10, 80, 80) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _SendToTop() ; Check status of GUI If GUICtrlRead($cLabel) = "On Top" Then ; Remove OnTop attribute WinSetOnTop($hGUI, "", 0) ; Change label GUICtrlSetData($cLabel, "Not on Top") Else ; Send to top Winactivate($hGUI) ; And keep it there WinSetOnTop($hGUI, "", 1) ; Change label GUICtrlSetData($cLabel, "On Top") EndIf EndFuncHow does that work for you? Please ask if you have any questions. I noted that a few things are more difficult to obtainAlways the case when comparing languages - something simple in one is ofter more complicated in the other. I am sure we could find examples where AutoIt is much simpler than AHK - but then as this is not a competition, I am not really bothered. M23 rsn 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
remin Posted October 16, 2013 Author Posted October 16, 2013 remin, If this a GUI you are creating then I suggest you use a flag of some sort to indicate the current status of the GUI - then the HotKey can adjust its action. I use a label in this snippet: How does that work for you? Please ask if you have any questions. Thank you again for your kind answer and sorry for the fact that I'm not clear enough. Yes that works fine. Very nice. I would like to use the code not for my own GUI but for all windows that I occasionally want to set "on top" Would that be possible? Always the case when comparing languages - something simple in one is ofter more complicated in the other. I am sure we could find examples where AutoIt is much simpler than AHK - but then as this is not a competition, I am not really bothered. M23 Yes, sure, you're right. I already found a few things which can be done easier in autoit. I like your comment saying that it is not a competition. It seems to me the right approach
Moderators Solution Melba23 Posted October 16, 2013 Moderators Solution Posted October 16, 2013 remin,,The same basic process will work on third party GUIs as well, all you need to do is create a suitable flag. This script works on the SciTE editor: HotKeySet("^t", "_SendToTop") ; Get handle of SciTe GUI $hSciTE = WinGetHandle("[CLASS:SciTEWindow]") ; Create flag to follow state $fSciTEOnTop = False ; Keep script alive While 1 Sleep(10) WEnd Func _SendToTop() ; Check status of SciTE If $fSciTEOnTop Then ; Remove OnTop attribute WinSetOnTop($hSciTE, "", 0) ; Clear flag $fSciTEOnTop = False Else ; Send to top Winactivate($hSciTE) ; And keep it there WinSetOnTop($hSciTE, "", 1) ; Set flag $fSciTEOnTop = True EndIf EndFuncM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
remin Posted October 16, 2013 Author Posted October 16, 2013 Thanks I changed $hSciTE = WinGetHandle("[CLASS:SciTEWindow]") to $hSciTE = WinGetHandle("[ACTIVE]") and now it works also for a third party GUI. But it seems to me that we must add to the script the code to update the Active window, isn't it? Because every time I use the shortcut on whatever active window, it puts the previous active window at top (the 1st one I used the shortcut on).
Moderators Melba23 Posted October 16, 2013 Moderators Posted October 16, 2013 remin,I would add another HotKey to the script which identifies the active GUI and then you can use that handle as the one to action from then on. Give it a go yourself and see what you can come up with - you know where I am if you get stuck. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
remin Posted October 16, 2013 Author Posted October 16, 2013 remin, I would add another HotKey to the script which identifies the active GUI and then you can use that handle as the one to action from then on. Give it a go yourself and see what you can come up with - you know where I am if you get stuck. M23 I haven't fully understand what you mean with this. I will not profit of you knowledge of autoit, so will try to create the code myself, but please tell me a little bit more what you mean with this. One hotkey to check which GUI is the current active GUI (I'll do a search on the net to find it out) and another one to use above code, is that what you mean? Or can it be integrated in one function? BTW are all people on this forum so nice and helpful as you are? Thanks for everything.
Moderators Melba23 Posted October 16, 2013 Moderators Posted October 16, 2013 remin,Everything is in the one script. Use one HotKey to identify the current active window and store its handle. Then another HotKey will use that handle to either set or remove the ONTOP attribute. You just need to separate the 2 parts of the function you already have. are all people on this forum so nice and helpful as you are?I would like to think that we are a helpful community to those who try to help themselves and who stick to the Forum rules - you have read them I hope. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
guinness Posted October 16, 2013 Posted October 16, 2013 This might be useful to you too... #include <Constants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Example() Func Example() Local $hGUI = GUICreate('') GUISetState(@SW_SHOW, $hGUI) ; Set the GUI as being on top using the handle returned by GUICreate. WinSetOnTop($hGUI, '', 1) MsgBox($MB_SYSTEMMODAL, '', 'Is the GUI on top: ' & _IsOnTop($hGUI) & ', this should be True') GUIDelete($hGUI) EndFunc ;==>Example ; Check if a window is on top. Func _IsOnTop($sTitle, $sText = '') Return BitAND(_WinAPI_GetWindowLong(WinGetHandle($sTitle, $sText), $GWL_EXSTYLE), $WS_EX_TOPMOST) = $WS_EX_TOPMOST EndFunc ;==>_IsOnTop argumentum 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
remin Posted October 16, 2013 Author Posted October 16, 2013 (edited) Yes it seems to work! This is my final code: #include <GUIConstantsEx.au3> HotKeySet("^h", "_WhichActive") HotKeySet("^t", "_SendToTop") ; Keep script alive While 1 Sleep(10) WEnd Func _WhichActive() ; Get handle of Active GUI global $hActivE = WinGetHandle("[ACTIVE]") ; Create flag to follow state global $fActivEOnTop = False Endfunc Func _SendToTop() ; Check status of Active GUI If $fActivEOnTop Then ; Remove OnTop attribute WinSetOnTop($hActivE, "", 0) ; Clear flag $fActivEOnTop = False Else ; Send to top Winactivate($hActivE) ; And keep it there WinSetOnTop($hActivE, "", 1) ; Set flag $fActivEOnTop = True EndIf EndFunc Thanks Melba Thanks guinness too for your reply. I'll look into it. Edited October 16, 2013 by remin
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now