VB6.0用掲示板の過去のログ(No.1)−VBレスキュー(花ちゃん)
[記事リスト] [新規投稿] [新着記事] [ワード検索] [過去ログ] [管理用]

投稿日: 2004/02/27(Fri) 11:32
投稿者ak
Eメール
URL
タイトルRe: 処理待ち状態について

入力可能状態になるまで待つにはAPI関数「WaitForInputIdle」を使います。

サンプルを記述しておきますので参考にしてください。

'(*.bas)
Option Explicit

Private Type PROCESS_INFORMATION
    hProcess    As Long
    hThread     As Long
    dwProcessId As Long
    dwThreadId  As Long
End Type

Private Type STARTUPINFO
    cb              As Long
    lpReserved      As String
    lpDesktop       As String
    lpTitle         As String
    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 Const STARTF_USESHOWWINDOW = &H1
Private Const NORMAL_PRIORITY_CLASS = &H20&

Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" _
                                       (ByVal lpApplicationName As String, _
                                        ByVal lpCommandLine As String, _
                                        lpProcessAttributes As Any, _
                                        lpThreadAttributes As Any, _
                                        ByVal bInheritHandles As Long, _
                                        ByVal dwCreationFlags As Long, _
                                        lpEnvironment As Any, _
                                        ByVal lpCurrentDriectory As String, _
                                        lpStartupInfo As STARTUPINFO, _
                                        lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function WaitForInputIdle Lib "USER32" _
                                       (ByVal hProcess As Long, _
                                        ByVal dwMilliseconds As Long) As Long
                                        
'--------------------------------------------------------------------------------------
'概要      :EXE起動(拡張)
'パラメータ:変数名        ,IO ,型             ,説明
'          :sPath         ,I  ,String         ,パス
'          :[sParam]      ,I   ,String        ,パラメータ(任意)
'          :戻り値        ,O  ,Boolean        ,True:成功 False:失敗
'説明      :指定されたアプリを指定されたパラメータで起動し入力可能状態になるまで待機
'--------------------------------------------------------------------------------------
Public Function ShellEx(ByVal sPath As String, Optional ByVal sParam As String = "") As Boolean
    Dim tStInfo As STARTUPINFO
    Dim tPrInfo As PROCESS_INFORMATION

On Local Error GoTo Error_Handler
    
    ShellEx = False
    
    With tStInfo
        .cb = LenB(tStInfo)
        .dwFlags = STARTF_USESHOWWINDOW
        .wShowWindow = 6
    End With
    
    'アプリケーションを起動しプロセス作成する
    If CreateProcess(vbNullString, sPath & " " & sParam, ByVal 0&, _
                     ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, _
                     vbNullString, tStInfo, tPrInfo) = 0 Then GoTo Error_Handler

    Do
        If WaitForInputIdle(tPrInfo.hProcess, 100) = 0 Then Exit Do
    Loop
    
    ShellEx = True
    
    Exit Function
'====== エラー処理 ====================================================================
Error_Handler:
    MsgBox "エラーNo:" & Err.Number & vbCrLf & "エラー内容:" & Err.Description, vbCritical
    Err.Clear
End Function


- 関連一覧ツリー (★ をクリックするとツリー全体を一括表示します)

- 返信フォーム (この記事に返信する場合は下記フォームから投稿して下さい)

- Web Forum -