Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2007
    Messaggi
    119

    [VB6] Sendkeys ad applicazione controllata da una function

    Scusate per il titolo ma non sapevo come inquadrare bene il problema in una riga.

    Vado a spiegare
    Devo aspettare la chiusura di varie applicazioni, lo faccio così..

    Contenuto del modulo
    codice:
    Option Explicit
    
    Private Type STARTUPINFO
        cb As Long
        lpReserved As Long
        lpDesktop As Long
        lpTitle As Long
        dwX As Long
        dwY As Long
        dwXSize As Long
        dwYSize As Long
        dwXCountChars As Long
        dwYCountChars As Long
        dwFillAttribute As Long
        dwFlags As Long
        wShowWindow As Integer
        cbReserved2 As Integer
        lpReserved2 As Long
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
    End Type
    
    Private Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessId As Long
        dwThreadId As Long
    End Type
    
    Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    
    Public Const WAIT_TIMEOUT As Long = 258&
    Private Const WAIT_FAILED As Long = &HFFFFFFFF
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const STARTF_USESHOWWINDOW As Long = &H1
    Private Const STARTF_USESIZE As Long = &H2
    Private Const STARTF_USEPOSITION As Long = &H4
    Private Const STARTF_USECOUNTCHARS As Long = &H8
    Private Const STARTF_USEFILLATTRIBUTE As Long = &H10
    Private Const STARTF_RUNFULLSCREEN As Long = &H20
    Private Const STARTF_FORCEONFEEDBACK As Long = &H40
    Private Const STARTF_FORCEOFFFEEDBACK As Long = &H80
    Private Const STARTF_USESTDHANDLES As Long = &H100
    Private Const STARTF_USEHOTKEY As Long = &H200
    
    Public Function ShellSospensiva(ByVal CommandLine As String, ByVal Directory As String, ByVal WindowStyle As VbAppWinStyle, ByVal WaitTime As Long) As Long
        Dim proc As PROCESS_INFORMATION
        Dim Start As STARTUPINFO
        With Start
            .dwFlags = STARTF_USESHOWWINDOW
            .wShowWindow = WindowStyle
            .cb = Len(Start)
        End With
        Call CreateProcess(0, CommandLine, 0, 0, 0, NORMAL_PRIORITY_CLASS, 0, Directory, Start, proc)
        If proc.hProcess <> 0 Then
            ShellSospensiva = WaitForSingleObject(proc.hProcess, WaitTime)
            Call CloseHandle(proc.hProcess)
        Else
            ShellSospensiva = WAIT_FAILED
        End If
    End Function
    il codice per una applicazione il cui percorso è in txtProcess.Text è ad esempio questa:
    codice:
    Private Sub cmdAvvia_Click()
    Select Case ShellSospensiva(txtProcesso.Text, CurDir$, vbNormalFocus, CLng(txtAttesa.Text))
            Case 0: MsgBox "Esecuzione completata con esito positivo", vbInformation
            Case WAIT_TIMEOUT: MsgBox "Supero del tempo massimo di attesa", vbExclamation
            Case Else: MsgBox "Si è verificato un errore", vbCritical
        End Select
    Il mio problema è: come faccio ad utilizzare sendkeys per inviare tasti a queste applicazioni?

    Grazie

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2007
    Messaggi
    119
    Faccio una precisazione.

    Il mio scopo è quello di effettuare un operazione che prevede l'utilizzo di due applicazioni, VirtualDub e BeSweet, per editing video.

    Vorrei automatizzare la procedura, per cui mi serve aprire in sequenza le applicazioni ed eseguire dei comandi.

    SendKeys in generale funziona, ma a parte il problema di non riuscirlo ad utilizzare con la function che ho trovato in rete e che ho postato sopra, ho anche la difficoltà di non sapere come lasciare ad ogni comando di essere eseguito:

    Ad esempio, se devo estrarre un file wav da un file Avi (VirtualDub), devo lasciare il tempo necessario (che non conosco a priori se non con molta incertezza) prima di eseguire l'operazione successiva.
    Non vorrei dire fesserie ma mi servirebbe quello che in .NET fa Sendwait..

    Se riuscissi a controllare sendkeys in questo modo non si porrebbe il problema di utilizzare il modulo che ho postato, perchè una volta eseguiti tutti i comandi necessari potrei chiudere a comando l'applicazione attiva.

    Come fareste voi?
    Scusate se mi sono dilungato, ma spero che il problema sia più chiaro.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.