Jump to content
Sign in to follow this  
remin

How to check if window is on top?

Recommended Posts

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 by remin

Share this post


Link to post
Share on other sites

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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 by remin

Share this post


Link to post
Share on other sites

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)
EndFunc
How is that? :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

remin,

Have you discovered the excellent Help file yet? :huh:

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 flag
So all you need do is use the correct parameter and Robert is your mother's brother. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 by remin

Share this post


Link to post
Share on other sites

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
EndFunc
How does that work for you? Please ask if you have any questions. :)

 

I noted that a few things are more difficult to obtain

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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 ;)

Share this post


Link to post
Share on other sites

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
EndFunc
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks :D

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).

Share this post


Link to post
Share on other sites

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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

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 by remin

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kingjacob90
      Hi
      So I am trying to click the green button, this button is not always in the same place. So fare I am trying to click it by finding the color but there is also something else with the same color on the screen (circled in yellow) that is causing issues. Is there a way to use the Title and Class of the window (can't be just the window as there are more than one with the same name).
      How does AutoIt Info get this information?

    • By nacerbaaziz
      question about _WinAPI_CreateWindowEx
      good morning
      welcome autoit team
      please i need your help
      i've searched a lot about how to use the _WinAPI_CreateWindowEx
      finally i found an example
      but i found some problem i hope you can help me
      firstly, i want to set the controls focussable with the keyboard input
      i already used the ws_tabStop but it did not work with me.
      secondly, i want to set some access keys linked with the window
      such as control+o enable the open button and control+f4 exit the app
      note: i need a local access keys and not a global hotkeys
      such as GUISetAccelerators
      finaly, before i will put the code here i must clarify a few things.
      1. you will ask me why you don't use the GUICreate function
      here i'll tell you that it as dialog and It is a little heavy in motion with screen readers.
      the screen readers for blind has some function that work with dialogs and others work with full windows style
      2. you will ask me why you didn't search the net for that?
      i will tell you that all examples that i found in the internet with pdfs and Picture books.
      i found some examples in microsoft but it with cpp.
      ok here is the code
      i hope you can help me to do what i want
      thank you in advance
       
      ; Small AutoIt Application that uses Windows API ; Written by Yuraj #NoTrayIcon #include <_RegisterClassEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <FontConstants.au3> AutoItSetOption("MustDeclareVars", 1) ; Window definitions Const $WinWidth = 370 Const $WinHeight = 350 Const $WinXPos = (@DesktopWidth / 2) - ($WinWidth / 2) Const $WinYPos = (@DesktopHeight / 2) - ($WinHeight / 2) Const $WinTitle = "Win32 Application - Text reader" Const $WinClass = "mainapp" Const $WinIcon = _WinAPI_LoadIcon(_WinAPI_GetModuleHandle("shell32.dll"), 13) ; Windows handles Global $hwnd, $edit1, $btn1, $btn2 ; Fonts Global $fnt1 ; Register class, Create the window Local $retVal = __WinAPI_RegisterClassEx($WinClass, "WindowCallback", $WinIcon, 0, _WinAPI_GetSysColor($COLOR_BTNFACE), BitOR($CS_DEFAULTSTYLE, $CS_DROPSHADOW)) ; If $retVal == 0 Then ; If registerclass fails MsgBox(16, "Error", "Error while registering window class!") Exit EndIf ; Create windows/controls $hwnd = _WinAPI_CreateWindowEx($WS_EX_STATICEDGE, $WinClass, $WinTitle, BitOR($WS_OVERLAPPED,$WS_SYSMENU, $WS_MINIMIZEBOX, $WS_GROUP, $WS_DLGFRAME), $WinXPos, $WinYPos, $WinWidth, $WinHeight, 0) $btn1 = _WinAPI_CreateWindowEx(0, "button", "Open file ...", BitOR($WS_VISIBLE, $WS_CHILD, $WS_TABSTOP, $WS_CLIPCHILDREN), 25, 270, 100, 30,$hwnd) $btn2 = _WinAPI_CreateWindowEx(0, "Button", "Exit", BitOR($WS_VISIBLE, $WS_CHILD, $WS_TABSTOP, $WS_CLIPCHILDREN), 235, 270, 100, 30, $hwnd) $edit1 = _WinAPI_CreateWindowEx(0, "edit", "text", BitOR($WS_VISIBLE, $WS_CHILD, $WS_VSCROLL, $ES_AUTOVSCROLL, $es_readOnly, $WS_TABSTOP), 5, 5, $WinWidth - 15, $WinHeight - 100, $hwnd) ; Set controls identifiers _WinAPI_SetWindowLong($btn1,$GWL_ID,150) _WinAPI_SetWindowLong($btn2,$GWL_ID,160) ; Set (controls) fonts $fnt1 = _CreateFont("MS Sans Serif", 15) _WinAPI_SetFont($btn1, $fnt1) _WinAPI_SetFont($btn2, $fnt1) _WinAPI_SetFont($edit1, $fnt1) ; Set focus to edit _WinAPI_SetFocus($edit1) ; Show window _WinAPI_ShowWindow($hwnd) _WinAPI_UpdateWindow($hwnd) ; Main loop that keep application opened While 1 Sleep(100) WEnd ;=================================================================; ; WINDOW CALLBACK ... ;=================================================================; Func WindowCallback($_hwnd, $iMsg, $wParam, $lParam) Local $iNC, $iID Switch $iMsg ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Case $WM_CLOSE ; Show message on closing If MsgBox(48 + 4, $WinTitle, "Do you want really exit?", 0, $hwnd) <> 6 Then Return 0 ; Call destructor and then exit main thread FinalizeApp() Exit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Case $WM_COMMAND $iNC = _WinAPI_HiWord($wParam) $iID = _WinAPI_LoWord($lParam) Switch $iNC Case $BN_CLICKED ; When is control clicked Switch _WinAPI_GetDlgCtrlID($iID) Case _WinAPI_GetDlgCtrlID($btn1) BtnOpenFileClick() Case _WinAPI_GetDlgCtrlID($btn2) BtnExitClick() EndSwitch EndSwitch ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EndSwitch Return _WinAPI_DefWindowProc($_hwnd, $iMsg, $wParam, $lParam) EndFunc ;==>WindowCallback Func FinalizeApp() _WinAPI_DeleteObject($fnt1) _WinAPI_DestroyWindow($hwnd) __WinAPI_UnregisterClass($WinClass) EndFunc ;==>FinalizeApp Func _CreateFont($fontName, $height = 16, $style = $FW_NORMAL, $italic = False, $underline = False, $strikeout = False) Local $hFont = _WinAPI_CreateFont($height, 0, 0, 0, $style, $italic, $underline, $strikeout, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, $fontName) Return $hFont EndFunc ;==>_CreateFont ;=================================================================; ; WINDOW EVENTS ;=================================================================; Func BtnOpenFileClick() Local $ret = _WinAPI_GetOpenFileName("", "Text files (*.txt)|All files (*.*)", ".", "", "", 1, 0, 0, $hwnd) If ($ret[0] > 0) Then Local $path = $ret[1] & "\" & $ret[2] Local $file = _WinAPI_CreateFile($path, 2, 2) Local $buf = DllStructCreate("byte[" & _WinAPI_GetFileSizeEx($file) & "]") Local $i = 0 _WinAPI_ReadFile($file, DllStructGetPtr($buf), _WinAPI_GetFileSizeEx($file), $i) ; Close file handle _WinAPI_CloseHandle($file) _WinAPI_SetWindowText($edit1, BinaryToString(DllStructGetData($buf, 1))) EndIf EndFunc ;==>BtnOpenFileClick Func BtnExitClick() FinalizeApp() Exit EndFunc ;==>BtnExitClick  
      _RegisterClassEx.au3
    • By edpoguatemala
      Hello Everyone, 
      So I'm using auto it to automate the download of pictures in woocommerce orders. Once images are downloaded, I need to change the status of the order from in process to completed. This is how my code looks like: 
      Download()
      Func Download()
          ; Save the downloaded file to the temporary folder.
          Local $sFilePath = @DesktopDir&"\TestAutomatizacion\"&@YEAR &"_"& @MON &"_"& @MDAY & "_picpic_orders.zip"
          ; Download the file in the background with the selected option of 'force a reload from the remote site.'
          Local $hDownload = InetGet("https://hellopicpic.com/get_pic_orders.php?token=ygtV2bMh23uJ7f6s&type=pic", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
          ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True.
          Do
              Sleep(250)
          Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
          ; Retrieve the number of total bytes received and the filesize.
          Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD)
          Local $iFileSize = FileGetSize($sFilePath)
          ; Close the handle returned by InetGet.
          InetClose($hDownload)
      EndFunc   ;==>Download
       
      Thanks for any help you can give. 
    • By nacerbaaziz
      hello sirs, please i created a tool witch get the focused control in a window and play a audio file linked with this controls
      e.g buttons, checkBoxes, radios, comboboxes, and others
      i know that their is a function that give us the control focus but it return the classNN
      i want to get the class name to use it with a switch and
      because their are more than class e.g button tbutton timagebutton tnewButton...
      please can any one help me to get the class name not the classnn
      thanks in advance
    • By ThePoro
      Hi everyone.
      I want to ask about this : 
      I want it runs from 1 to 100 and It opens 10 firefox profiles then access youtube. After I close a firefox window, the loop runs and wait for another window close until loop ends
      I have a loop like this.
      Func launch() Local $from = Int(GUICtrlRead($input1)) Local $to = Int(GUICtrlRead($input2)) If $to <> "" Then While $from <= $to Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") $to=$to+1 WEnd Else Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") EndIf EndFunc Is there any solution?
      Thank you!
×
×
  • Create New...