Advertisement
Guest User

Untitled

a guest
May 16th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.30 KB | None | 0 0
  1.  
  2. Run("notepad.exe")
  3. Sleep(1000) ; chờ notepad bật
  4.  
  5. $pid = ProcessExists("notepad.exe") ; lấy process id
  6. $hwnd = _ProcessGetWinEx($pid) ; lấy win handle từ process
  7.  
  8. MsgBox(0, "", WinGetTitle($hwnd)) ; title
  9.  
  10. Func _ProcessGetWinEx($ivPid, $svClass = "", $svTitle = "", $svText = "", $ivReturnOnlyFirstMatch = True)
  11.  
  12.     $ivPid = ProcessExists($ivPid)
  13.     If Not $ivPid Then Return(SetError(1, 0, 0))
  14.  
  15.     Local $avwArray = WinList()
  16.     Local $avRet[1] = [0]
  17.  
  18.     For $i = 1 To $avwArray[0][0]
  19.         $avClass = DllCall("User32.dll", "int", "GetClassName", "hwnd", $avwArray[$i][1], "str", "", "int", 4096)
  20.         If WinGetProcess($avwArray[$i][1]) = $ivPid Then
  21.             If $svClass = "" Or (IsArray($avClass) And $avClass[2] = $svClass) Then
  22.                 If ($svTitle = "" Or StringInStr($avwArray[$i][0], $svTitle)) And ($svText = "" Or StringInStr(WinGetText($avwArray[$i][1]), $svText)) Then
  23.                     $avRet[0] += 1
  24.                     ReDim $avRet[$avRet[0]+1]
  25.                     $avRet[$avRet[0]] = $avwArray[$i][1]
  26.                     If $ivReturnOnlyFirstMatch Then
  27.                         $avRet = $avret[1]
  28.                         ExitLoop
  29.                     EndIf
  30.                 EndIf
  31.             EndIf
  32.         EndIf
  33.     Next
  34.  
  35.     Return $avRet
  36.  
  37. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement