fork download
  1. 'Win32 API Programing NyuMon AI Shuppan Atsushi Omura 2002 'Aug 14, 2019 Programmable on Excel 2016
  2.  
  3. Type SECURITY_ATTRIBUTES
  4. nLength As Long
  5. lpSecurityDescriptor As Long
  6. bInheritHandle As Long
  7. End Type
  8. 'ハンドルが子プロセスによって継承されるかどうかを指定する構造体
  9. Type PROCESS_INFORMATION
  10. hProcess As Long
  11. hThread As Long
  12. dwProcessId As Long
  13. dwThreadId As Long
  14. End Type
  15. Type STARTUPINFO
  16. cb As Long
  17. lpReserved As String
  18. lpDesktop As String
  19. lpTitle As String
  20. dwX As Long
  21. dwY As Long
  22. dwXSize As Long
  23. dwYSize As Long
  24. dwXCountChars As Long
  25. dwYCountChars As Long
  26. dwFillAttribute As Long
  27. dwFlags As Long
  28. wShowWindow As Integer
  29. cbReserved2 As Integer
  30. lpReserved2 As Byte
  31. hStdInput As Long
  32. hStdOutput As Long
  33. hStdError As Long
  34. End Type
  35.  
  36. Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
  37.  
  38. Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
  39. Public Const STATUS_WAIT_0 = &H0&
  40. Public Const WAIT_OBJECT_0 = ((STATUS_WAIT_0) + 0)
  41. '可能な限りのすべてのアクセスを指定する
  42. Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
  43.  
  44.  
  45. Sub WaitForInputIdle_Sample()
  46. Dim strApplicationName As String '実行モジュール名
  47. Dim udtProcessAttributes As SECURITY_ATTRIBUTES
  48. Dim udtThreadAttributes As SECURITY_ATTRIBUTES
  49. Dim udtStartupInfo As STARTUPINFO
  50. Dim udtProcessInfomation As PROCESS_INFORMATION
  51. Dim lngMilliseconds As Long 'タイムアウト時間
  52. Dim rc As Long
  53.  
  54. MsgBox "Wordを起動してユーザーが入力できる状態になるまで待機します" & Chr(13) & "待機結果はイミディエイトウィンドウで確認してください"
  55.  
  56. '実行モジュール名
  57. '<使用しているOfficeのバージョンに応じて絶対パスを変更してください>
  58. strApplicationName = "C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE"
  59.  
  60. '構造体のバイト数を指定
  61. udtProcessAttributes.nLength = Len(udtProcessAttributes)
  62. udtThreadAttributes.nLength = Len(udtThreadAttributes)
  63.  
  64. '構造体のバイト数を指定
  65. udtStartupInfo.cb = Len(udtStartupInfo)
  66.  
  67. '新しいプロセスを作成
  68. rc = CreateProcess(strApplicationName, vbNullString, udtProcessAttributes, udtThreadAttributes, False, 0, ByVal vbNullString, vbNullString, udtStartupInfo, udtProcessInfomation)
  69.  
  70. '待機するタイムアウト時間を無制限にする
  71. lngMilliseconds = INFINITE
  72.  
  73. '新しいプロセスがユーザーの入力を受け付ける状態になるまで待機する
  74. rc = WaitForInputIdle(udtProcessInfomation.hProcess, lngMilliseconds)
  75.  
  76. '待機結果を表示
  77. Select Case rc
  78. Case 0&
  79. Debug.Print "入力を開始できます"
  80. Case WAIT_TIMEOUT
  81. Debug.Print "指定した時間が経過しました"
  82. Case -1&
  83. Debug.Print "関数の呼び出しに失敗しました"
  84. End Select
  85. End Sub
  86.  
  87.  
  88.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty