Public Enum PriorityEnum
NORMAL_PRIORITY_CLASS = &H20
IDLE_PRIORITY_CLASS = &H40
HIGH_PRIORITY_CLASS = &H80
End Enum
Public Enum WindowStyle
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum
Declare Function CreateProcessA Lib "kernel32" (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 Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Const INFINITE = -1&
Public Const STARTF_USESHOWWINDOW = &H1
Public 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
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
'**********************************************************
Public Function SystemExecute(ByRef CmdLine As String, Optional Show As WindowStyle = SW_NORMAL) As Long
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim Res As Long
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
start.dwFlags = STARTF_USESHOWWINDOW
start.wShowWindow = Show
' Start the shelled application:
Res = CreateProcessA(0&, CmdLine$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
Res = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, Res)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
SystemExecute = Res
End Function
Private Sub Command1_Click()
SystemExecute "Запускаемая прога" 'Например так SystemExecute "c:\program files\winrar\WinRAR.exe -a *.*"
MsgBox "CLOSE "
End Sub
В чём разница между именем файла и хендлом файла, не нужно объяснять?
Лучше не закладываться на одну-две секунды, а сделать последовательность из WaitForInputIdle+SendKeys+WaitForSingleObject
Dummiel писал(а):В чём разница между именем файла и хендлом файла, не нужно объяснять?
А в чем разница?
Dummiel писал(а):WaitForSingleObject требует (ByVal hHandle As Long, ByVal dwMilliseconds As Long). Как получить hHandle "чужого" *.exe?
И для чего dwMilliseconds, какое значение д.б., чтобы моя прога ждала "вечно"?
Glyckmen писал(а):Dummiel Да забыл предупредить, что этот способ напроч замораживает твою прогу (даже окна не перерисовываются, оператор DoEvents не помогает) но только до тех пор пока ты не закроешь вызванную программу. Что-бы не смущать пользователя что твоя прога зависла можно просто убрать форму (или формы) с экрана Form.Visible=False, после того как вызванная прога отработала и завершилась, снова выводишь форму (или формы) на экран Form.Visible=True
А лучше вывести сообщение об обработке инфы и убрать форму Думаю так будет лучше.
OpenProcess, блин. Он там, по-твоему, зачем был?
Лучше не закладываться на одну-две секунды, а сделать последовательность из WaitForInputIdle+SendKeys+WaitForSingleObject
PostMessage wndHandle, WM_KEYDOWN, 13, ByVal 0&
tyomitch писал(а):Kovu, SendKeys лучше оставить. Либо слать и WM_KEYUP тоже.
ПереAPIзм -- зло.
Kovu писал(а):tyomitch писал(а):Kovu, SendKeys лучше оставить. Либо слать и WM_KEYUP тоже.
ПереAPIзм -- зло.
Гы, протестируй пожалуйста на окне блокнота, там если ему шлешь ещё и KEYUP букву добавляет 2 раза
tyomitch писал(а): Значит, параметры не те передаёшь. Покажи свой код.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function SetFocus1 Lib "user32.dll" Alias "SetFocus" ( _
ByVal hwnd As Long) As Long
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_KEYUP As Long = &H101
Private Sub Command1_Click()
Dim lHandle As Long
lHandle = FindWindow("notepad", vbNullString)
SetForegroundWindow lHandle
lHandle = FindWindowEx(lHandle, ByVal 0&, "Edit", vbNullString)
SetFocus1 lHandle
PostMessage lHandle, WM_KEYDOWN, vbKeyS, ByVal 0&
PostMessage lHandle, WM_KEYUP, vbKeyS, ByVal 0&
End Sub
tyomitch писал(а):А теперь почитай в описании WM_KEYxxx, что должно быть вместо ByVal 0&.
tyomitch писал(а):Видишь ли, Kovu, там только в нижнем слове счётчик повтора. Там, кстати, стоит единица при разовом нажатии. А не 0.
Но дело не в этом: верхнее слово кто за тебя заполнять будет?
MSDN писал(а):lKeyData
Value of lParam. Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. Value Description
0–15 Specifies the repeat count for the current message. The value is the number of times the keystroke is auto-repeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as the right-hand alt and ctrl keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25–28 Reserved; do not use.
29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message.
Kovu писал(а):MSDN писал(а):lKeyData
Value of lParam. Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. Value Description
0–15 Specifies the repeat count for the current message. The value is the number of times the keystroke is auto-repeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
------------------------------------------------------------------------------
16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as the right-hand alt and ctrl keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25–28 Reserved; do not use.
29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message.
И где здесь написано, что lParam состоит из верхнего и нижнего слова?
0–15 Specifies the repeat count for the current message. The value is the number of times the keystroke is auto-repeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
Сейчас этот форум просматривают: AhrefsBot, Mail.ru [бот], Yandex-бот и гости: 19