• Log in or sign up for an account here: https://www.sythe.org/login

Two extremely usefull RuneScape functions.

Covey

Creator of EliteSwitch

Retired Sectional Moderator
Visual Basic Programmers
Joined
Sep 9, 2005
Sythe Gold
9
Messages
4,510
Location
Fuckin' BAM!
Discord Unique ID
807246764155338833
Discord Username
Covey#1816
I've used these for sometime now to get the RuneScape handle and set focus to the RuneScape applet etc.
and i remember one of the JD's asking how i got the RuneScape handles without making the user drag their mouse to the window.

Anyway this is how: (add this to a module)
Code:
Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As Rect) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long

Private Type Rect
	Left As Long
	Top As Long
	Right As Long
	Bottom As Long
End Type

Public RuneFound As Boolean
Public RuneTop As Long
Public RuneLeft As Long
Public RuneHwnd As Long

Public Function RuneScapeHasFocus(Optional ByRef Handle As Long = 0) As Boolean
	Dim Window As Rect, i As Long
	RuneScapeHasFocus = False
	If Not RuneFound Then
		FindRunescape
	End If
	If Not RuneFound Then
		Exit Function
	End If
	i = RuneHwnd
	Do While i <> 0
		If i = GetForegroundWindow Then
			Exit Do
		End If
		i = GetParent(i)
	Loop
	If i <> 0 Then
		RuneScapeHasFocus = True
	End If
End Function

Public Function FindRunescape() As Boolean
	Dim WindowHandle(0 To 200) As Long, Depth As Long, i As Long, l As Long, H As Long, WindowRect As Rect, Class As String
	Depth = 0
	WindowHandle(0) = 0
	i = 0
	RuneFound = False
	While Depth >= 0
		Do
			H = FindWindowEx(WindowHandle(Depth), WindowHandle(Depth + 1), vbNullString, vbNullString)
			If H > 0 Then
				Depth = Depth + 1
				WindowHandle(Depth) = H
				If Depth = UBound(WindowHandle) Then
					Stop
				End If
			Else
				WindowHandle(Depth + 1) = 0
			End If
		Loop Until H = 0
		GetWindowRect WindowHandle(Depth), WindowRect
		If WindowRect.Right - WindowRect.Left = 765 And WindowRect.Bottom - WindowRect.Top = 503 Then
			l = 100
			Class = Space$(50)
			l = GetClassName(WindowHandle(Depth), Class, 50)
			Class = Left$(Class, l)
			If LCase$(Class) = "msawt_comp_class" Or LCase$(Class) = "sunawtcanvas" Then
				FindRunescape = True
				RuneFound = True
				RuneTop = WindowRect.Top
				RuneLeft = WindowRect.Left
				RuneHwnd = WindowHandle(Depth)
				Exit Function
			End If
		End If
		i = i + 1
		Depth = Depth - 1
	Wend
	RuneFound = False
End Function

I copied and pasted this directly from my project, thus having to trim out other bits and peices i didn't want to yet share. So i may have forgotten to include an API or Variable.

To set focus to the RuneScape window you will need to use the PutFocus / SetFocus API or SetForegroundWindow API (i prefer SetForegroundWindow).

Enjoy ;)
 
duelarena.gg
Back
Top