Two extremely usefull RuneScape functions.

Discussion in 'Programming General' started by Covey, Jan 28, 2008.

Two extremely usefull RuneScape functions.
  1. Unread #1 - Jan 28, 2008 at 10:08 AM
  2. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Two extremely usefull RuneScape functions.

    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 ;)
     
  3. Unread #2 - Jan 28, 2008 at 11:49 AM
  4. Terrankiller
    Joined:
    May 7, 2005
    Posts:
    1,286
    Referrals:
    1
    Sythe Gold:
    1

    Terrankiller Ex-Administrator
    Retired Administrator Visual Basic Programmers

    Two extremely usefull RuneScape functions.

    Does the RS Applet always have a fixed size?
     
  5. Unread #3 - Jan 28, 2008 at 11:53 AM
  6. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Two extremely usefull RuneScape functions.

    Ummm, to my knowledge. Yes
     
  7. Unread #4 - Apr 2, 2008 at 3:17 PM
  8. Trainer311
    Referrals:
    0

    Trainer311 Guest

    Two extremely usefull RuneScape functions.

    do i save it as a .exe or what?
     
  9. Unread #5 - Apr 5, 2008 at 1:30 PM
  10. Cruel__Machine
    Referrals:
    100

    Cruel__Machine Guest

    Two extremely usefull RuneScape functions.

    I lol'd.
     
  11. Unread #6 - Apr 6, 2008 at 1:13 AM
  12. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    Two extremely usefull RuneScape functions.

    One 'L' in useful. Thanks for these although I don't know if I'll use them anyway. I just get the applet coords when the user picks certain colors. :p
    Yes.
    You need the compiler from http://www.microsoft.com/vb6/free_IDE first.
    Why are you laughing? That guy is quite serious.
     
  13. Unread #7 - Apr 6, 2008 at 2:15 AM
  14. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Two extremely usefull RuneScape functions.

    Not where i come from :D
     
< Need Help with Java (im new to programming) | [help] Text File >

Users viewing this thread
1 guest


 
 
Adblock breaks this site