Jump to content
FrancescoDiMuro

Set on top a GUI

Recommended Posts

FrancescoDiMuro

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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites
FrancescoDiMuro

BUMP :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
FrancescoDiMuro

@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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites
FrancescoDiMuro

BUMP :) 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
FrancescoDiMuro

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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
FrancescoDiMuro

@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

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

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

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      First, I want to apologize with you for the title not very clear, but I thought a little bit on which title to set at the thread, and this is the one that came in mind.
      Now, let me explain what I'm trying to understand.

      I am making an application ( with n clients ), with an SQLite Database, which has a Main form, and n sub-forms... 
      Since these sub-forms are called several times, because they are used to add or update records to the Database, I put the code that generates the GUI of these sub-forms in Functions.
      There are two sub-forms which are "treated" as two main forms, since even them have n sub-forms, which perform various tasks.
      Where am I stucked?

      For the Main form I created a Status Bar, in order to display messages ( add/delete/update/search results ), and it works perfectly with all the forms which don't have other sub-forms.
      For the two forms, which indeed have n sub-forms, I created two separated Status Bars, which are (re)created everytime I call the function that then displays the form.
      Practically, I can't set icons to these two Status Bars, and I don't know why.
      I'm really sorry that I don't feel clear enough, so, here you are an example of what I am saying.
      I recreated exactly what my script does:
      #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $frmSubForm, _ $txtSubFormField, _ $sbSubFormStatusBar, _ $objSB_IconError = _WinAPI_LoadShell32Icon(109), _ $objSB_IconInformation = _WinAPI_LoadShell32Icon(277) #Region ### START Koda GUI section ### Form= $frmMainForm = GUICreate("Main Form", 300, 300, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") $sbMainStatusBar = _GUICtrlStatusBar_Create($frmMainForm) $btnCreateSubForm = GUICtrlCreateButton("Create Sub Form", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "GenerateSubForm") GUICtrlSetFont(-1, 10, 400, 0, "Arial") _GUICtrlStatusBar_SetSimple($sbMainStatusBar) _GUICtrlStatusBar_SetText($sbMainStatusBar, "") GUISetState(@SW_SHOW, $frmMainForm) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func GenerateSubForm() #Region ### START Koda GUI section ### Form= $frmSubForm = GUICreate("Sub-Form", 300, 300, -1, -1, -1, -1, $frmMainForm) GUISetOnEvent($GUI_EVENT_CLOSE, "DeleteSubForm") $txtSubFormField = GUICtrlCreateInput("", 0, 0, 100, 20) $btnCheckSubFormField = GUICtrlCreateButton("Check Field", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "CheckSubFormField") GUICtrlSetFont(-1, 10, 400, 0, "Arial") $sbSubFormStatusBar = _GUICtrlStatusBar_Create($frmSubForm) _GUICtrlStatusBar_SetSimple($sbSubFormStatusBar) _GUICtrlStatusBar_SetText($sbSubFormStatusBar, "") GUISetState(@SW_SHOW, $frmSubForm) GUISetState(@SW_DISABLE, $frmMainForm) #EndRegion ### END Koda GUI section ### EndFunc Func DeleteSubForm() ; Declared Globally => $frmSubForm GUIDelete($frmSubForm) GUISetState(@SW_ENABLE, $frmMainForm) EndFunc Func WriteToStatusBar($sbStatusBar, $objSB_Icon, $strText) _GUICtrlStatusBar_SetIcon($sbStatusBar, 0, $objSB_Icon) _GUICtrlStatusBar_SetText($sbStatusBar, $strText) ConsoleWrite("Icon Handle: " & $objSB_Icon & @CRLF) EndFunc Func CheckSubFormField() ; Declared Globally => $txtSubFormField If GUICtrlRead($txtSubFormField) = "" Then ; Declared Globally => $sbStatusBar WriteToStatusBar($sbSubFormStatusBar, $objSB_IconError, "Field NOK.") Else WriteToStatusBar($sbSubFormStatusBar, $objSB_IconInformation, "Field OK.") EndIf EndFunc The text is set, but icon is not.
      Could someone please tell me why?
      Thanks everyone in advance  

      Best Regards.
    • Reziskonh
      By Reziskonh
      Hi, everybody
      I look for GUI whose behavior similar to the message of an email client or antivirus
      In other words:
          Any PC screen able to calculate the size
          To consider the Task bar size
          To find the lower corner on the right/below and to nestle on it

      Notes:
      In GUI the GUICtrlCreateEdit field (as option) - that can be received and displayed through variable information
      Thanks a lot
      PS
      I use the translator, excuse if something is not clear
       

    • Pike
      By Pike
      Hello Everyone,
      New Guy here. This is a two-part question, hopefully easy enough though. I know it's ugly coding, this is because I have only a couple hours worth of coding experience and could really use some help.
      1) When I single click the button I want one action (like playing a sound clip) and when I double click the button I want a different action (such as opening dialogue box to ask for soundclip directory address). At the bottom of the script I made a comment which one I would like single click versus double click.
      2) I can not get the FileOpenDialogue to save the file address to the config.ini file at the 'One' position on the .ini.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <AutoItConstants.au3> #include <Sound.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $OneID _Main() Func _Main() GUICreate("Form1", 156, 86, 281, 276) $OneID = GUICtrlCreateButton("Button", 15, 17, 122, 37) GUICtrlSetOnEvent($OneID, "OnOne") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 While 1 Sleep(1000) WEnd WEnd EndFunc ;---------------Functions------------- While 1 Sleep(100) WEnd Func OnOne() ; ******************Single Click for this action**************** $OneID = IniRead("config.ini", "Config", "One", $OneID) If $OneID = True Then SoundPlay($OneID, @HotKeyPressed) Else ; *******Double Click for this action*****And Help Saving File Address to config.ini 'One'*********** $OneID = FileOpenDialog("Select file", @WorkingDir, "All (*.*)") IniWrite("config.ini", "Config", "One", $OneID) $OneID = InputBox("Enter Information", "Short Name for File?", "") IniWrite("config.ini", "Config", "NameOne", $OneID) EndIf EndFunc Any help would be greatly appreciated, and if you need anymore clarity as to what exactly I'm trying to do, please do not hesitate to ask. Thanks so much!
      Pike
    • VollachR
      By VollachR
      Hi,
      I'd like to show a progress bar for an operation performed by an external program my script is running silently, I want to show it in a GUI I created using the GUICtrlCreateProgress but I have no idea how to do it.
      The important thing to point out is that there's no way of knowing how long the external program will run, as it is a file splitter and it depends on the size of file it splits and the split parts size.
      Can someone point me in the right direction or give me an example how to do so?
      This is my RunWait command:
      RunWait($MYFILES1 & '\fsplit.exe -split ' & $Size & ' mb ' & $File & " -f " & $File & "." & $extension) It uses multiple variables declared and set earlier in the script, how will I got about having the progress of that command shown using GUICtrlCreateProgress ? Is it possible?
      Thank you.
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
×