Jump to content

Exit do not Exit the script


Recommended Posts

; Lancia WordPad
Run("wordpad.exe")

; Definisci il titolo della finestra di WordPad
Local $windowTitle = "Documento - WordPad" ; Il titolo potrebbe variare in base alla versione di WordPad

; Attendi che la finestra di WordPad sia attiva
If Not WinWaitActive($windowTitle, "", 10) Then
    MsgBox(0, "Errore", "Impossibile attivare la finestra di WordPad.")
    sleep(10)
    Exit
EndIf

; Ottieni l'handle della finestra di WordPad
Local $windowHandle = WinGetHandle($windowTitle)

; Verifica se l'handle della finestra è valido
If @error Then
    MsgBox(0, "Errore", "Impossibile trovare la finestra: " & $windowTitle)
    sleep(10)
    Exit
EndIf

; Porta la finestra di WordPad in primo piano
WinActivate($windowHandle)

; Assicurati che la finestra di WordPad sia attiva
If Not WinWaitActive($windowHandle, 10) Then
    sleep(10)
    MsgBox(0, "Errore", "Impossibile attivare la finestra di WordPad.")
    Exit
EndIf

; Imposta il focus sull'area di testo di WordPad
; L'area di testo ha generalmente la classe "RICHEDIT50W" in WordPad
Local $textControlClass = "[CLASS:RICHEDIT50W; INSTANCE:1]"

; Ottieni l'handle dell'area di testo
Local $textControlHandle = ControlGetHandle($windowHandle, "", $textControlClass)

; Verifica se l'handle dell'area di testo è valido
If @error Then
    MsgBox(0, "Errore", "Impossibile trovare l'area di testo.")
    sleep(10)
    Exit
EndIf

; Imposta il focus sull'area di testo
ControlFocus($windowHandle, "", $textControlHandle)

; Messaggio di conferma
MsgBox(0, "Successo", "Il focus è stato impostato sull'area di testo di WordPad.")

THis is my program to run wordpad.exe but i have an infinite number of error messages like "impossibile attivare la finestra"

Link to comment
Share on other sites

45 minutes ago, Lorenzopier said:

THis is my program to run wordpad.exe but i have an infinite number of error messages like "impossibile attivare la finestra"

(??) should only return that message to you once.

however the "Run" command requires the complete path of the program to be executed.
You can try with "ShellExecute" instead of "Run"

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Posted (edited)
1 hour ago, Gianni said:

however the "Run" command requires the complete path of the program to be executed.

Not really. Run is a wrapper for the Windows API function >>CreateProcess<<.
If no full name is specified, this function searches for the file in the following order:

  1. The directory from which the application loaded.
  2. The current directory for the parent process.
  3. The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
  4. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
  5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  6. The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function.
Edited by AspirinJunkie
Link to comment
Share on other sites

Posted (edited)

you need program flow checkpoint

; Lancia WordPad
;~ Local $WP_PID = Run("wordpad.exe")
Local $WP_PID = ShellExecute('wordpad')
ConsoleWrite("$WP_PID=" & $WP_PID & @CRLF)

; Definisci il titolo della finestra di WordPad
Local $windowTitle = "[CLASS:WordPadClass]" ;"Documento - WordPad" ; Il titolo potrebbe variare in base alla versione di WordPad

; Attendi che la finestra di WordPad sia attiva
Local $windowHandle = WinWaitActive($windowTitle, "", 3)
If Not $windowHandle Then
    MsgBox(0, "Errore", "Impossibile attivare la finestra di WordPad.")
    sleep(10)
    Exit
EndIf
ConsoleWrite("$windowHandle=" & $windowHandle & @CRLF)

; Imposta il focus sull'area di testo di WordPad
; L'area di testo ha generalmente la classe "RICHEDIT50W" in WordPad
Local $textControlClass = "[CLASS:RICHEDIT50W; INSTANCE:1]"

; Ottieni l'handle dell'area di testo
Local $textControlHandle = ControlGetHandle($windowHandle, "", $textControlClass)
ConsoleWrite("$textControlHandle=" & $textControlHandle & @CRLF)

; Imposta il focus sull'area di testo
Local $Check = ControlFocus($windowHandle, "", $textControlHandle)
ConsoleWrite("ControlFocus=" & $Check & @CRLF)

 

Edit:

Testet in Win10 22H2

; https://www.autoitscript.com/forum/topic/211947-exit-do-not-exit-the-script/?do=findComment&comment=1534353

$hWnd = Wordpad()
ConsoleWrite("$hWnd=" & $hWnd & @CRLF)
ConsoleWrite("Title=" & WinGetTitle($hWnd) & @CRLF)
ConsoleWrite("" & @CRLF)

$hWnd = Wordpad(@ScriptFullPath)
ConsoleWrite("$hWnd=" & $hWnd & @CRLF)
ConsoleWrite("Title=" & WinGetTitle($hWnd) & @CRLF)


Func Wordpad($sFilePath = "@NewFile", $Show_flag = @SW_SHOW)
    Local $sWordpadPath = FileGetShortName(@ProgramFilesDir & "\Windows NT\Accessories\wordpad.exe")
    ConsoleWrite("$sWordpadPath=" & $sWordpadPath & @CRLF)

    Local $hWnd, $WP_PID

    If $sFilePath = "@NewFile" Then
        ConsoleWrite("@NewFile" & @CRLF)

        $WP_PID = Run($sWordpadPath, "", $Show_flag)
        ConsoleWrite("$WP_PID=" & $WP_PID & @CRLF)

;~      $hWnd = WinWait("[TITLE:Document - WordPad; CLASS:WordPadClass]", "", 5)
        $hWnd = WinWaitActive("[CLASS:WordPadClass]", "", 5)
    Else
        Local $sWP_FilePath = FileGetShortName($sFilePath)
        ConsoleWrite("$sWP_FilePath=" & $sWP_FilePath & @CRLF)

        Local $sWP_FileName = StringTrimLeft($sFilePath, StringInStr($sFilePath, "\", 0, -1))
        ConsoleWrite("$sWP_FileName=" & $sWP_FileName & @CRLF)

        $WP_PID = Run($sWordpadPath & " " & $sWP_FilePath, "", $Show_flag)
        ConsoleWrite("$WP_PID=" & $WP_PID & @CRLF)

        $hWnd = WinWait("[TITLE:" & $sWP_FileName & " - WordPad; CLASS:WordPadClass]", "", 5)
    EndIf
    
    If Not $hWnd Then Return SetError(1, 1, "")
    Return $hWnd

EndFunc   ;==>Wordpad

 

Edited by ioa747
corection

I know that I know nothing

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...