Free Games Forum
Free Games Games Forums Music Forums TV Forums

  Free Games Forum Home FORUM
HOME
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN
Rules & FAQ RULES / FAQ
REPORT SPAM

Free Games Forum: Game Technology: Visual Basic / VB:
Easy World Switching

 

 


scare crow
Member


Nov 3, 2005, 4:50 PM

Post #1 of 12 (901 views)
Shortcut
Easy World Switching Can't Post

Ok, in this tutorial, i will be telling you how to make a really easy, and fast world switcher.

For this, you will need

Two Textboxes
One Command Button
And a Webbroswer


1.Start off by making a Standard EXE.

2.Press Ctrl T, and go down to Microsoft Internet Controls, and then click ok. Now you will see a new icon on the left toolbar, double click it, and enlarge it.

3.Make a two text boxes, and name them each

Textbox1
Textbox2

4.Now make a command button, and name it

Go

5.Change text box 2 visibility to False.

6.Add the following code to your command button


Code
 Private Sub Go_Click() 

If Text1.Text = "1" Then
Text2.Text = "ul2"
End If

If Text1.Text = "2" Then
Text2.Text = "ul4"
End If

If Text1.Text = "3" Then
Text2.Text = "po3"
End If

If Text1.Text = "4" Then
Text2.Text = "po4"
End If

If Text1.Text = "5" Then
Text2.Text = "po5"
End If

If Text1.Text = "6" Then
Text2.Text = "po6"
End If

If Text1.Text = "7" Then
Text2.Text = "above2"
End If

If Text1.Text = "8" Then
Text2.Text = "above3"
End If

If Text1.Text = "9" Then
Text2.Text = "above4"
End If

If Text1.Text = "10" Then
Text2.Text = "jolt7"
End If

If Text1.Text = "11" Then
Text2.Text = "jolt8"
End If

If Text1.Text = "12" Then
Text2.Text = "jolt9"
End If

If Text1.Text = "13" Then
Text2.Text = "nl3"
End If

If Text1.Text = "14" Then
Text2.Text = "nl4"
End If

If Text1.Text = "15" Then
Text2.Text = "uk2"
End If

If Text1.Text = "16" Then
Text2.Text = "uk3"
End If

If Text1.Text = "17" Then
Text2.Text = "tor1"
End If

If Text1.Text = "18" Then
Text2.Text = "tor2"
End If

If Text1.Text = "19" Then
Text2.Text = "cet1"
End If

If Text1.Text = "20" Then
Text2.Text = "cet2"
End If

If Text1.Text = "21" Then
Text2.Text = "cet5"
End If

If Text1.Text = "22" Then
Text2.Text = "nl1"
End If

If Text1.Text = "23" Then
Text2.Text = "uk4"
End If

If Text1.Text = "24" Then
Text2.Text = "uk5"
End If

If Text1.Text = "25" Then
Text2.Text = "cet6"
End If

If Text1.Text = "26" Then
Text2.Text = "ul5"
End If

If Text1.Text = "27" Then
Text2.Text = "nl5"
End If

If Text1.Text = "28" Then
Text2.Text = "nl6"
End If

If Text1.Text = "29" Then
Text2.Text = "ul6"
End If

If Text1.Text = "30" Then
Text2.Text = "po7"
End If

If Text1.Text = "31" Then
Text2.Text = "po8"
End If

If Text1.Text = "32" Then
Text2.Text = "ul1"
End If

If Text1.Text = "33" Then
Text2.Text = "at1"
End If

If Text1.Text = "34" Then
Text2.Text = "at2"
End If

If Text1.Text = "35" Then
Text2.Text = "at3"
End If

If Text1.Text = "36" Then
Text2.Text = "at4"
End If

If Text1.Text = "37" Then
Text2.Text = "tor2"
End If

If Text1.Text = "38" Then
Text2.Text = "planet1"
End If

If Text1.Text = "39" Then
Text2.Text = "planet2"
End If

If Text1.Text = "40" Then
Text2.Text = "planet3"
End If

If Text1.Text = "41" Then
Text2.Text = "planet4"
End If

If Text1.Text = "42" Then
Text2.Text = "po2"
End If

If Text1.Text = "43" Then
Text2.Text = "sl11"
End If

If Text1.Text = "44" Then
Text2.Text = "at6"
End If

If Text1.Text = "45" Then
Text2.Text = "planet5"
End If

If Text1.Text = "46" Then
Text2.Text = "planet6"
End If

If Text1.Text = "47" Then
Text2.Text = "above5"
End If

If Text1.Text = "48" Then
Text2.Text = "above6"
End If

If Text1.Text = "49" Then
Text2.Text = "ams1"
End If

If Text1.Text = "50" Then
Text2.Text = "ams2"
End If

If Text1.Text = "51" Then
Text2.Text = "ams3"
End If

If Text1.Text = "52" Then
Text2.Text = "ams4"
End If

If Text1.Text = "53" Then
Text2.Text = "ams5"
End If

If Text1.Text = "54" Then
Text2.Text = "ams6"
End If

If Text1.Text = "55" Then
Text2.Text = "ch1"
End If

If Text1.Text = "56" Then
Text2.Text = "cet4"
End If

If Text1.Text = "57" Then
Text2.Text = "ch3"
End If

If Text1.Text = "58" Then
Text2.Text = "ch4"
End If

If Text1.Text = "59" Then
Text2.Text = "ch5"
End If

If Text1.Text = "61" Then
Text2.Text = "se1"
End If

If Text1.Text = "62" Then
Text2.Text = "se2"
End If

If Text1.Text = "63" Then
Text2.Text = "se3"
End If

If Text1.Text = "64" Then
Text2.Text = "se4"
End If

If Text1.Text = "66" Then
Text2.Text = "se6"
End If

If Text1.Text = "67" Then
Text2.Text = "jolt10"
End If

If Text1.Text = "68" Then
Text2.Text = "jolt11"
End If

If Text1.Text = "69" Then
Text2.Text = "jolt12"
End If

If Text1.Text = "70" Then
Text2.Text = "sl10"
End If

If Text1.Text = "71" Then
Text2.Text = "uk7"
End If

If Text1.Text = "72" Then
Text2.Text = "sl1"
End If

If Text1.Text = "73" Then
Text2.Text = "sl2"
End If

If Text1.Text = "74" Then
Text2.Text = "sl3"
End If

If Text1.Text = "75" Then
Text2.Text = "sl4"
End If

If Text1.Text = "76" Then
Text2.Text = "sl5"
End If

If Text1.Text = "77" Then
Text2.Text = "sl6"
End If

If Text1.Text = "78" Then
Text2.Text = "sl7"
End If

If Text1.Text = "79" Then
Text2.Text = "sl8"
End If

If Text1.Text = "80" Then
Text2.Text = "jolt1"
End If

If Text1.Text = "81" Then
Text2.Text = "jolt2"
End If

If Text1.Text = "82" Then
Text2.Text = "jolt3"
End If

If Text1.Text = "83" Then
Text2.Text = "jolt4"
End If

If Text1.Text = "84" Then
Text2.Text = "jolt5"
End If

WebBrowser1.Navigate "http://" + Text2.Text + ".runescape.com/rs2.cgi?plugin=0&lowmem=0"
End Sub


And there you have it...

Here are some other things you might need.

Prevent Runescape Redirection


Code
 Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean) 
On Error Resume Next
If URL = "http://www.runescape.com/" Then Cancel = True
End Sub


Steal Rs

Add the following code into a module


Code
Public Const SWP_NOSIZE = &H1 
Public Const HWND_TOP = 0
Public Const SWP_NOOWNERZORDER = &H200
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
Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Sub StealRS(Frm As Form)
On Error Resume Next
thunderformdc& = Frm.hWnd
shellembedding& = FindWindowEx(thunderformdc&, 0&, "shell embedding", vbNullString)
shelldocobjectview& = FindWindowEx(shellembedding&, 0&, "shell docobject view", vbNullString)
internetexplorerserver& = FindWindowEx(shelldocobjectview&, 0&, "internet explorer_server", vbNullString)
microsoftvmforjavatmhostwindowclass& = FindWindowEx(internetexplorerserver&, 0&, "microsoft vm for java(tm) host window class", vbNullString)
RSHwnd& = FindWindowEx(microsoftvmforjavatmhostwindowclass&, 0&, "msawt_comp_class", vbNullString)
SetParent RSHwnd, Frm.hWnd
DoEvents
RSHwnd& = FindWindowEx(Frm.hWnd, 0&, "msawt_comp_class", vbNullString)
If RSHwnd = 0 Then Exit Sub

Call SetWindowPos(RSHwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER Or SWP_NOSIZE)
End Sub


Now, add the following code to your form.


Code
 Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long) 
On Error Resume Next
StealRS Me
End Sub



Ok, i hope i didnt miss anything, if i did, please tell me!!!



LamasLikeToast
Newbie

Dec 18, 2005, 10:32 AM

Post #2 of 12 (734 views)
Shortcut
Re: [scare crow] Easy World Switching [In reply to] Can't Post

it doesnt work...


LamasLikeToast
Newbie

Dec 18, 2005, 10:55 AM

Post #3 of 12 (732 views)
Shortcut
Re: [LamasLikeToast] Easy World Switching [In reply to] Can't Post

can you just post the code exacly how it would look if you just viewd it all at once when ur done?


scare crow
Member


Dec 19, 2005, 7:36 AM

Post #4 of 12 (729 views)
Shortcut
Re: [LamasLikeToast] Easy World Switching [In reply to] Can't Post

ok, here...

add the following to a module!


Code
'The constants we are going to use 
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOP = 0
Public Const SWP_NOOWNERZORDER = &H200
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
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
Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Sub StealRS(Frm As Form) 'Finds the rs hwnd and then sets it to be on the form
On Error Resume Next
thunderformdc& = Frm.hWnd 'This is the start point (this form)
ShellEmbedding& = FindWindowEx(thunderformdc&, 0&, "shell embedding", vbNullString)
ShellDocObjectView& = FindWindowEx(ShellEmbedding&, 0&, "shell docobject view", vbNullString) 'These are the steps to the rs hwnd
InternetExplorerServer& = FindWindowEx(ShellDocObjectView&, 0&, "internet explorer_server", vbNullString)
MicrosoftVMForJavaTMHostWindowClass& = FindWindowEx(InternetExplorerServer&, 0&, "microsoft vm for java(tm) host window class", vbNullString)
'This one is Poonscape
RSHwnd& = FindWindowEx(MicrosoftVMForJavaTMHostWindowClass&, 0&, "msawt_comp_class", vbNullString)
'Sets the parent of the Poonscape applet to be the form
SetParent RSHwnd, Frm.hWnd
'Pause until the has finished
DoEvents
'Try to find the new rs window
RSHwnd& = FindWindowEx(Frm.hWnd, 0&, "msawt_comp_class", vbNullString)
'If not found exit
If RSHwnd = 0 Then Exit Sub
'Window found so set it to be where we want it to be.
'In this case i set it to be the top left of the form.

'SWP_NOOWNERZORDER Or SWP_NOSIZE means we want it to ignore the resizeing
'and not to affect the order
Call SetWindowPos(RSHwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER Or SWP_NOSIZE)
End Sub


then add this to the regular form


Code
Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long) 
On Error Resume Next
StealRS Me
End Sub


there, that should work fine!


Cruel__Machine
Senior Member


Dec 19, 2005, 1:18 PM

Post #5 of 12 (725 views)
Shortcut
Re: [scare crow] Easy World Switching [In reply to] Can't Post

Alright. Lesson #1 on clean/compact code.
Do not generate multiple if-statments checking the same value.

Example. Change this:


Code
If Text1.Text = "1" Then  
Text2.Text = "ul2"
End If

If Text1.Text = "2" Then
Text2.Text = "ul4"
End If

If Text1.Text = "3" Then
Text2.Text = "po3"
End If

If Text1.Text = "4" Then
Text2.Text = "po4"
End If

If Text1.Text = "5" Then
Text2.Text = "po5"
End If



To this:


Code
Select Case Text1.Text 
Case "1": Text2.Text = "ul2"
Case "2": Text2.Text = "ul4"
Case "3": Text2.Text = "po3"
Case "4": Text2.Text = "po4"
Case "5": Text2.Text = "po5"
End Select



Or even this if you wished:


Code
If Text1.Text = "1" Then Text2.Text = "ul2" 
If Text1.Text = "2" Then Text2.Text = "ul4"
If Text1.Text = "3" Then Text2.Text = "po3"
If Text1.Text = "4" Then Text2.Text = "po4"
If Text1.Text = "5" Then Text2.Text = "po5"



You'll thank me when you start making 50k line projects. ;)


EOP
___________________________
"If evolution were true, I'd have a self-lubricating hand."

Programmers: http://Cruels.net


Cruel__Machine
Senior Member


Dec 19, 2005, 1:23 PM

Post #6 of 12 (724 views)
Shortcut
Re: [Cruel__Machine] Easy World Switching [In reply to] Can't Post

Also, here's my edited version of StealRS.
More efficient in variable usage and also works with Sun Java and more just MS Java.


Code
Public Function StealRS2(Frm As Form)  
On Error Resume Next

Dim RSHwnd As Long
Dim RSSunJava As Long

DoEvents
RSHwnd = FindWindowEx(Frm.hwnd, 0, "shell embedding", vbNullString)
RSHwnd = FindWindowEx(RSHwnd, 0, "shell docobject view", vbNullString)
RSHwnd = FindWindowEx(RSHwnd, 0, "internet explorer_server", vbNullString)
RSSunJava = FindWindowEx(RSHwnd, 0, "Java Plug-in Control Window", vbNullString)
RSSunJava = FindWindowEx(RSSunJava, 0, "sun.plugin.viewer.frame.IExplorerEmbeddedFrame", vbNullString)
'RSSunJava = FindWindowEx(RSSunJava, 0, "SunAwtCanvas", vbNullString)
'RSSunJava = FindWindowEx(RSSunJava, 0, "SunAwtCanvas", vbNullString)
RSHwnd = FindWindowEx(RSHwnd, 0, "microsoft vm for java(tm) host window class", vbNullString)
RSHwnd = FindWindowEx(RSHwnd, 0, "msawt_comp_class", vbNullString)
If RSHwnd = 0 Then RSHwnd = RSSunJava
If RSHwnd = 0 Then Exit Function
SetParent RSHwnd, Frm.hwnd
End Function



This will work if you are just using it for the SetParent() to get rid of the ads.
But if you are trying to detect the window for other reasons (like getting color of the applet or autoing and such) then you'll need to get the actual window handle. In that case you need to edit the sub a bit. You can see the two lines I commented out. You need to uncomment those to get the true window handle.
The reason I have to comment those out id because if you try to use SetParent on that window handle of the Sun Java applet, it causes errors and terminates the app in most cases...
One of the many reasons I dislike Sun Java. (other being that it is harder to auto on ;))


EOP
___________________________
"If evolution were true, I'd have a self-lubricating hand."

Programmers: http://Cruels.net


scare crow
Member


Dec 19, 2005, 1:41 PM

Post #7 of 12 (722 views)
Shortcut
Re: [Cruel__Machine] Easy World Switching [In reply to] Can't Post

yeah, i posted this a long while ago before i knew how to code better, my code is a little better then yours

my new code that is

but yours is still great... and both versions of steal rs still work, i dont notice a difference


Cruel__Machine
Senior Member


Dec 19, 2005, 3:25 PM

Post #8 of 12 (720 views)
Shortcut
Re: [scare crow] Easy World Switching [In reply to] Can't Post

The StealRS you posted doesn't work for Sun Java.
Other than that, there is no noticible difference.


EOP
___________________________
"If evolution were true, I'd have a self-lubricating hand."

Programmers: http://Cruels.net


scare crow
Member


Dec 19, 2005, 5:55 PM

Post #9 of 12 (717 views)
Shortcut
Re: [Cruel__Machine] Easy World Switching [In reply to] Can't Post

oh...i didnt know...lol... thanks

does your stealrs work for both sun java and just the regular, or do i need to put both?


Cruel__Machine
Senior Member


Dec 20, 2005, 3:33 PM

Post #10 of 12 (714 views)
Shortcut
Re: [scare crow] Easy World Switching [In reply to] Can't Post

Mine works for both MS and Sun Java.
So you just need that one.


EOP
___________________________
"If evolution were true, I'd have a self-lubricating hand."

Programmers: http://Cruels.net


scare crow
Member


Dec 21, 2005, 1:09 PM

Post #11 of 12 (707 views)
Shortcut
Re: [Cruel__Machine] Easy World Switching [In reply to] Can't Post

ok, thanks!


vlademel
Member


Dec 22, 2005, 8:56 PM

Post #12 of 12 (698 views)
Shortcut
Re: [scare crow] Easy World Switching [In reply to] Can't Post

this works but where did you learn this from?


..............................................
Take no prisoners i guess.....

i got nothing to type :(

 
 
 


Search for (options) Web Design by Web Ideas - Page loaded in: 0.17 s on (CGI/1.1)