Useful AutoIt3 window manipulation code for GTA2

robotanarchy edited this page May 1, 2015 · 2 revisions

Sqozz from bytewerk wrote this, and I'll keep a copy here until the code is integrated in the tree :+1:

#include <SendMessage.au3>
#include <array.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

; Exact winmatch mode. Revert it afterwards if not needed
Opt("WinTitleMatchMode", 3)

; Bing - got achievment: "start gta2 hidden"
$gtaPid = Run("C:\GTA2\gta2.exe", "C:\GTA2", @SW_HIDE )
WinWait( "GTA2" )
$gtaHandle = _GetHwndFromPID($gtaPid)
ConsoleWrite( "GTA2 hwnd is: " & $gtaHandle & @CRLF)

; Bing - got achievement: "play sound when gta2 is in background"
_SendMessage ( $gtaPid, 0x0007 )
ConsoleWrite( "Faking active for: " & $gtaPid & @CRLF )

; Bing - got achievement: "change window title permanent"
_WinAPI_SetWindowText ( $gtaPid, "GTA2 Hacker's Remix - Player 1" )

Sleep( 5000 )

; Bing - got achievment: "show a hidden gta2 window"
WinSetState( $gtaHandle, "", @SW_SHOW )

Func _GetHwndFromPID($PID)
	$hWnd = 0
	$winlist = WinList()
	Do
		For $i = 1 To $winlist[0][0]
			If $winlist[$i][0] <> "" Then
				$iPID2 = WinGetProcess($winlist[$i][1])
				If $iPID2 = $PID Then
					$hWnd = $winlist[$i][1]
					ExitLoop
				EndIf
			EndIf
		Next
	Until $hWnd <> 0
	Return $hWnd
EndFunc;==>_GetHwndFromPID
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.