Jump to content

Set on top a GUI


Recommended Posts

Good morning community! :)
I was working on a script which read the content of a .ini file to retrieve the file that has to open, and, based on the value of a second key stored in the .ini file, set the window on top, minimized or maximized...
I did something like this, but seems to not work properly...
Could anyone please tell me what I'm doing wrong?
Thank you :) 
 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=prova.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
;#include <WinAPIEx.au3>
#include <Array.au3>

Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini"

If(FileExists($sFileConfigurazione)) Then
    Local $aSezioneIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE")
    If @error Then
        MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error)
    Else
        ; Lancio dell'applicativo indicato nel file di configurazione
        Local $iPID = ShellExecute($aSezioneIni[1][1])
        Local $hWnd
        If($iPID <> 0) Then
            Local $aWinList = WinList()
            For $i = 1 To $aWinList[0][0]
                If(WinGetProcess($aWinList[$i][1] = $iPID)) Then
                    $hWnd = $aWinList[$i][1]
                EndIf
            Next
            Switch($aSezioneIni[2][1])
                Case $aSezioneIni[2][1] = "MIN"
                    ToolTip("MIN", 0, 0)
                    WinSetState($hWnd, WinGetTitle($hWnd), @SW_MINIMIZE)
                Case $aSezioneIni[2][1] = "MAX"
                    ToolTip("MAX", 0, 0)
                    WinSetState($hWnd, WinGetTitle($hWnd), @SW_MAXIMIZE)
                Case $aSezioneIni[2][1] = "TOP"
                    ToolTip("TOP", 0, 0)
                    WinSetOnTop($hWnd, WinGetTitle($hWnd), $WINDOWS_ONTOP)
            EndSwitch
        EndIf
    EndIf
EndIf

And the .ini file is like this:
 

[CONFIGURAZIONE_EXE]
PercorsoExe=Here goes the path and the .exe to execute
ModalitaAperturaExe=Here goes one of the value below
/* TOP Shows the windows on top */
/* MIN Shows the window minimized */
/* MAX Shows the window maximized */

 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • Moderators

FrancescoDiMuro,

This works for me. I have highlighted the changes (<<<<<<<<):

#include <Array.au3>
#include <AutoItConstants.au3>

$iPID = ShellExecute("text.txt")

; Use placeholder as flag for success <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Local $hWnd = 9999

Do
    ; List GUIs
    $aWinList = WinList()
    ; Check if PID found and if GUI is visible <<<<<<<<<<<<<<<<
    For $i = 1 To $aWinList[0][0]
        If WinGetProcess($aWinList[$i][1]) = $iPID And BitAND(WinGetState($aWinList[$i][1]), 2) Then
            ; Store handle
            $hWnd = $aWinList[$i][1]
            ; Stop searching <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ExitLoop
        EndIf
    Next
    ; Save CPU
    Sleep(10)

Until $hWnd <> 9999 ; Keep looking until GUI appears <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$iMode = InputBox("Mode", "1, 2, 3")

Switch $iMode
    Case 1 ; Use correct syntax for Switch - you were using Select syntax <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        ToolTip("MIN", 0, 0)
        WinSetState($hWnd, "", @SW_MINIMIZE)
    Case 2
        ToolTip("MAX", 0, 0)
        WinSetState($hWnd, "", @SW_MAXIMIZE)
    Case 2
        ToolTip("TOP", 0, 0)
        WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)

EndSwitch

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

 

Link to comment
Share on other sites

@Melba23
Thank you for you corrections :)
I'll try your code asap :)
 

2 hours ago, Melba23 said:

you were using Select syntax <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Sorry for the mistake... Better if I change the Switch...Case to the Select...Case, in order to tell the script what I mean! :)
Again, thank you, and have a wonderful day :)

EDIT:

Bizzarre things here!
If I use this code, and try to run Notepad, I can't click anymore on anything on the first screen ( I have 2 screens )...
I have added everything you suggested to me LESS the control over the visible of the GUI...
What the?!

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=prova.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
;#include <WinAPIEx.au3>
#include <Array.au3>

Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini"

Local $aWinList

If(FileExists($sFileConfigurazione)) Then
    Local $aSezioneIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE")
    If @error Then
        MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error)
    Else
        ; Lancio dell'applicativo indicato nel file di configurazione
        Local $iPID = ShellExecute($aSezioneIni[1][1])
        Local $hWnd = 9999 ; Placeholder for success
        If($iPID <> 0) Then
            Do
                $aWinList = WinList()
                For $i = 1 To $aWinList[0][0]
                    If(WinGetProcess($aWinList[$i][1] = $iPID)) Then
                        $hWnd = $aWinList[$i][1]
                        ExitLoop
                    EndIf
                Next
                Sleep(10) ; Save CPU
            Until $hWnd <> 9999
            Select
                Case $aSezioneIni[2][1] = "MIN"
                    ToolTip("MIN", 0, 0)
                    WinSetState($hWnd, WinGetTitle($hWnd), @SW_MINIMIZE)
                Case $aSezioneIni[2][1] = "MAX"
                    ToolTip("MAX", 0, 0)
                    WinSetState($hWnd, WinGetTitle($hWnd), @SW_MAXIMIZE)
                Case $aSezioneIni[2][1] = "TOP"
                    ToolTip("TOP", 0, 0)
                    WinSetOnTop($hWnd, WinGetTitle($hWnd), $WINDOWS_ONTOP)
            EndSelect
        EndIf
    EndIf
EndIf

EDIT 2:

Even If I copy-pasted your code, it doesn't work for me, launching Notepad...
I don't know why...

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • Moderators

FrancescoDiMuro,

Change

If(WinGetProcess($aWinList[$i][1] = $iPID)) Then

to read

If WinGetProcess($aWinList[$i][1]) = $iPID Then

and it will work.

Might I suggest NOT placing parentheses around the arguments for If comparisons - they are only really necessary when using Not to make sure you apply the logical operator to only the required part of the expression.

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

 

Link to comment
Share on other sites

Good morning @Melba23:)
Thank you for your suggestion... I applied it too, but, unfortunately, it still doesn't work properly...
I tried to launch Notepad.exe...

I don't know why it doesn't work... The window appears in the left-bottom side ( outside the screen ) of the screen...
This is the code:
 

#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>

Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini"

Local $aWinList

If(FileExists($sFileConfigurazione)) Then
    Local $aSezioneIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE")
    If @error Then
        MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error)
    Else
        ; Lancio dell'applicativo indicato nel file di configurazione
        Local $iPID = ShellExecute($aSezioneIni[1][1])
        Local $hWnd = 9999 ; Placeholder for success
        Do
            $aWinList = WinList()
            For $i = 1 To $aWinList[0][0]
                If WinGetProcess($aWinList[$i][1] = $iPID) And BitAND(WinGetState($aWinList[$i][1]), 2) Then
                    $hWnd = $aWinList[$i][1]
                    ExitLoop
                EndIf
            Next
            Sleep(10) ; Save CPU
        Until $hWnd <> 9999

        Select
            Case $aSezioneIni[2][1] = "MIN"
                WinSetState($hWnd, "", @SW_MINIMIZE)
            Case $aSezioneIni[2][1] = "MAX"
                WinSetState($hWnd, WinGetTitle($hWnd), @SW_MAXIMIZE)
            Case $aSezioneIni[2][1] = "TOP"
                WinSetOnTop($hWnd, WinGetTitle($hWnd), $WINDOWS_ONTOP)
        EndSelect
    EndIf
EndIf

If anyone would help me, I'd be very happy :)
Thanks again and sorry for my requests...

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • Moderators

FrancescoDiMuro,

Quote

I applied it too, but, unfortunately, it still doesn't work properly...

That is because you have NOT applied it. You still have:

If WinGetProcess($aWinList[$i][1] = $iPID)

when what you should have is:

If WinGetProcess($aWinList[$i][1]) = $iPID

which is exactly the same error as I corrected above.

Quote

If anyone would help me, I'd be very happy

If you actually read the help you were given, so would we.

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

 

Link to comment
Share on other sites

@Melba23
I'm so sorry for not noticing that little change!
I wasn''t payin' enough attention at the code... Sorry for that!

Now it works like a charm :)
Thank you for your time and your patience, and have a wonderful day :)

Francesco 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
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
 Share

×
×
  • Create New...