Focus on process/.exe

Posts 1–9 of 9 · Page 1 of 1
Focus on process/.exe
Hey all.

I made a simple bot for maplestory, but the bot sometimes annoy me when I try other things like surfing on internet or if I want to go on MSN.

I already found the code for checking if the process is running.
Code:
If Process.GetProcessesByName("explorer").Length = 1 then

End if
But now I need to focus my program, and what program now is on focus.

I hope somebody can help me .
Compare the result of the "GetForegroundWindow" API call to the window handle of your process (i.e maplestory)

Example use (obviously not the most efficient solution)

API:
[highlight=vb.net]
Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
[/highlight]

Usage:
[highlight=vb.net]
Private Function isForeground(ByVal proc As Process) As Boolean
Return GetForegroundWindow() = proc.MainWindowHandle
End Function
[/highlight]
[highlight=vb.net]
MessageBox.Show(isForeground(Process.GetProcessesB yName("maplestory")(0)).ToString())
[/highlight]
I didn't make me clear enough.

What is the code for how to focus your program
for example :
Code:
Dim process As String = "maplestory.exe"
focus(process)
But thank you for this code, it's pretty handy .
Quote Originally Posted by maarten551 View Post
I didn't make me clear enough.

What is the code for how to focus your program
for example :
Code:
Dim process As String = "maplestory.exe"
focus(process)
But thank you for this code, it's pretty handy .
To focus an application, you can use Built-In function AppActivate:

[highlight=vbnet]AppActivate("Application Title")[/highlight]
Quote Originally Posted by Hassan View Post


To focus an application, you can use Built-In function AppActivate:

[highlight=vbnet]AppActivate("Application Title")[/highlight]
It works for NotePad but it doesn't work for Maplestory any other code ?
AppActivate(Process.GetProcessByName("MapleStory") (0).pID)

AppActivate is an overloaded sub which accepts either a process ID or a window name.
Quote Originally Posted by master131 View Post
AppActivate(Process.GetProcessByName("MapleStory") (0).pID)

AppActivate is an overloaded sub which accepts either a process ID or a window name.
When I try this I get an error :
Code:
'GetProcessByName' is not a member of 'System.Diagnostics.Process'.
How can I fix this?
Quote Originally Posted by maarten551 View Post
When I try this I get an error :
Code:
'GetProcessByName' is not a member of 'System.Diagnostics.Process'.
How can I fix this?
Change it to "GetProcessesByName"
Quote Originally Posted by Jason View Post


Change it to "GetProcessesByName"
It doesn't work...
the problem that it doesn't exist is fixed but I get many other errors.
First pID isn't a member of system.diagnostics.process.
Second if I change it to "ID" it doesn't work.

Soo I did some looking and found thise code.
Code:
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long

        Dim handle As Long
        handle = GetWindow(vbNullString, "MapleStory")
        SetForegroundWindow(handle)
It works, but I got a Pinvoke error, can someone help solving this...
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us