谢谢各位朋友的回复。代码一会测一下。
今天又找了一个这样的自定义函数,在我的程序已经运行的情况下跑起来正常。
供大家学习参考
Func Processpath($iPID)
;通过API获取指定PID的进程路径
;官方牛人制作
Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
If $aProc[0] = 0 Then Return SetError(1, 0, '')
Local $vStruct = DllStructCreate('int[1024]')
DllCall('psapi.dll','int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
Return $aReturn[3]
EndFunc
$var = WinList("[CLASS:HSORGANCLIENT]")
For $i = 1 To $var[0][0]
Local $pid1 = WinGetProcess($var[$i][1])
;MsgBox(64,"进程信息","进程路径是:"&Processpath($PID1))
If Processpath($PID1)="C:\HsOrganClient.exe" Then ;8999
Local $handle = $var[$i][1]
MsgBox(0,0,$handle)
;WinSetState($handle, "",@SW_MAXIMIZE)
WinActivate($handle)
If WinActive($handle, "") Then
Send("!4")
Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}")
WinWaitActive($handle)
ControlClick($handle, "", "TPageControl1", "left", 1, 27, 9)
EndIf
endif
If Processpath($PID1)="C:\test\HsOrganClient.exe" Then
Local $handle = $var[$i][1]
MsgBox(0,0,$handle)
;WinSetState($handle, "",@SW_MAXIMIZE)
WinActivate($handle)
If WinActive($handle, "") Then
Send("!4")
Send("{ENTER}")
WinWaitActive($handle)
ControlClick($handle, "", "TPageControl1", "left", 1, 75, 10)
EndIf
endif
Next |