Register for your free account! | Forgot your password?

You last visited: Today at 17:49

  • Please register to post and access all features, it's quick, easy and FREE!

 

Help in C#

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jul 2012
Posts: 147
Received Thanks: 196
Help in C#

Hello, all...
I've been working on a few tools, as some of the available tools either don't fit my needs or are outdated. (Just to clarify, I am in no way denoting anyone's work or making accusations of inadequacy. I simply needed something tailored a bit more to my needs and something that works a bit better with the 7.4 files.) Currently I am working on a gm tool and ran into a bit of an issue. I know there are a few very talented C# programmers in this community who have achieved this in the past and thought I might give it a shot. (please don't flame... I am at least trying which is more than you can say for most of the help threads in this forum.) Here is my issue:

The GM-Tool passes strings to Herlock using "sendmessage", as seen here:
Code:
Process[] herlock = Process.GetProcessesByName("CaptainHerlockServer");
if (herlock.Length == 0) return;
if (herlock[0] != null)
{
    IntPtr child = FindWindowEx(herlock[0].MainWindowHandle, new IntPtr(0), "Edit", null);
    SendMessage(child, 0x000C, 0, "#warp(" + xPosition.Text + ", " + yPosition.Text + ", \""+listBox1.Text+"\")");
}
This works fine, however, I tried using "sendkeys" to pass the enter keystroke which, as you know, will only effect the active window.
Code:
SendKeys.Send("{ENTER}");
Someone suggested looking into spy++ and using "WM_KEYDOWN". Unfortunately I cannot afford a legit version of Visual studio and was wondering if anyone would be willing to share their insights or methods used in the past.

I will, of course, share everything once I am finished. Thanks in advance.



TheChinStrap is offline  
Old   #2
 
elite*gold: 0
Join Date: Nov 2011
Posts: 980
Received Thanks: 1,007
Code:
[DllImport("user32.dll")]
        public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("User32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("User32.dll")]
        public static extern IntPtr GetForegroundWindow();
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);
        public const uint WM_SETTEXT = 0x000C;




foreach (Process pProc in Process.GetProcessesByName("CaptainHerlockServer))
                    {
                        string text = "#your_text_here";
                        IntPtr p = Marshal.StringToHGlobalAuto(text);
                        IntPtr tmp = FindWindowEx(pProc.MainWindowHandle, IntPtr.Zero, "Edit", null);
                        SendMessage(tmp, WM_SETTEXT, 0, p);
                        SendMessage(tmp, 258, 13, IntPtr.Zero);
                        Application.DoEvents();
                    }
This Code will send the message to each Gameserver wich is running in Backround/Foreground.


TheOnlyOneRaskim is offline  
Thanks
1 User
Old   #3


 
elite*gold: 30
Join Date: May 2011
Posts: 4,795
Received Thanks: 3,179
Quote:
Originally Posted by TheOnlyOneRaskim View Post
Code:
[DllImport("user32.dll")]
        public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("User32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("User32.dll")]
        public static extern IntPtr GetForegroundWindow();
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);
        public const uint WM_SETTEXT = 0x000C;




foreach (Process pProc in Process.GetProcessesByName("CaptainHerlockServer))
                    {
                        string text = "#your_text_here";
                        IntPtr p = Marshal.StringToHGlobalAuto(text);
                        IntPtr tmp = FindWindowEx(pProc.MainWindowHandle, IntPtr.Zero, "Edit", null);
                        SendMessage(tmp, WM_SETTEXT, 0, p);
                        SendMessage(tmp, 258, 13, IntPtr.Zero);
                    }
This Code will send the message to each Gameserver wich is running in Backround/Foreground.
If you remove the Application.DoEvent():
THATS MY CODE <.< xD
Xijezu is offline  
Old   #4
 
elite*gold: 0
Join Date: Jul 2012
Posts: 147
Received Thanks: 196
Quote:
Originally Posted by TheOnlyOneRaskim View Post
Code:
[DllImport("user32.dll")]
        public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("User32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("User32.dll")]
        public static extern IntPtr GetForegroundWindow();
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);
        public const uint WM_SETTEXT = 0x000C;




foreach (Process pProc in Process.GetProcessesByName("CaptainHerlockServer))
                    {
                        string text = "#your_text_here";
                        IntPtr p = Marshal.StringToHGlobalAuto(text);
                        IntPtr tmp = FindWindowEx(pProc.MainWindowHandle, IntPtr.Zero, "Edit", null);
                        SendMessage(tmp, WM_SETTEXT, 0, p);
                        SendMessage(tmp, 258, 13, IntPtr.Zero);
                        Application.DoEvents();
                    }
This Code will send the message to each Gameserver wich is running in Backround/Foreground.
Worked perfectly... Thanks a ton, Raskim. In the end I don't think i will use "foreach", as I may use an xml file to define the process, so that people with more than one server can simply customize the xml file and use the tool independently for each server. Thanks again for your help and quick reply!
I'll be sure to include your name in the credits when I release my work.

Also, for anyone else that may have been looking for this solution, you will also need the following:
Code:
using System.Runtime.InteropServices;

PS:
@ Raskim and Xijezu
You're both brilliant. My GM tool's layout is based on your's, Xijezu. Not trying to copy you or "jock your style", but it was layed out brilliantly. Hope you don't mind but if you do shoot me a pm.

___________________________

Raskim Rocks


TheChinStrap is offline  
Old   #5
 
elite*gold: 0
Join Date: Jul 2011
Posts: 264
Received Thanks: 233
Quote:
Originally Posted by TheOnlyOneRaskim View Post
Code:
[DllImport("user32.dll")]
        public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("User32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("User32.dll")]
        public static extern IntPtr GetForegroundWindow();
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);
        public const uint WM_SETTEXT = 0x000C;




foreach (Process pProc in Process.GetProcessesByName("CaptainHerlockServer))
                    {
                        string text = "#your_text_here";
                        IntPtr p = Marshal.StringToHGlobalAuto(text);
                        IntPtr tmp = FindWindowEx(pProc.MainWindowHandle, IntPtr.Zero, "Edit", null);
                        SendMessage(tmp, WM_SETTEXT, 0, p);
                        SendMessage(tmp, 258, 13, IntPtr.Zero);
                        Application.DoEvents();
                    }
This Code will send the message to each Gameserver wich is running in Backround/Foreground.
it's like my code but I am using vb
M>M is offline  
Old   #6
 
elite*gold: 0
Join Date: Jul 2012
Posts: 147
Received Thanks: 196
Quote:
Originally Posted by M>M View Post
it's like my code but I am using vb
Careful... Xijezu will tear your ***** off for mentioning vb. XD

Edit: Ha ha ha! I can't believe he hit thanks for that one...
TheChinStrap is offline  
Thanks
1 User
Old   #7
 
elite*gold: 0
Join Date: Jul 2011
Posts: 264
Received Thanks: 233
Quote:
Originally Posted by TheChinStrap View Post
Careful... Xijezu will tear your ***** off for mentioning vb. XD

Edit: Ha ha ha! I can't believe he hit thanks for that one...
alahm any saam

no one can say that vb is a noob programming language even Xijezu because it's not !

but yes i am with Xijezu that vb i not like C# or C++ but it's still it's a great programming language to me
M>M is offline  
Old   #8
 
elite*gold: 0
Join Date: Jun 2011
Posts: 304
Received Thanks: 177
Yes it is. It's in the name. Visual Basic.
SilentBill is offline  
Thanks
2 Users
Old   #9
 
elite*gold: 0
Join Date: Jul 2012
Posts: 147
Received Thanks: 196
I have to agree. Atleast in comparison to c#, vb falls a bit short. Easier to learn but limited as far as how extensible. It's not a bad language, but doesn't compare with C#
TheChinStrap is offline  
Old   #10


 
elite*gold: 30
Join Date: May 2011
Posts: 4,795
Received Thanks: 3,179
Well, for some reason I'm always discussing about C# and vb... xD

Err, basically VB & C# is the same, they just have a different syntax.
Both of them need the .NET Framework, which has, orly?, the same content in vb aswell in c#.
The only difference is at a standard-"include": Microsoft.CSharp & Microsoft.VisualBasic.
For sure you can add both into your project, but usually just the necessary one is included.

Why I hate vb? Because this is not a good "Syntax" <.<
Xijezu is offline  
Old   #11
 
elite*gold: 0
Join Date: Jun 2011
Posts: 304
Received Thanks: 177
I wouldn't say they're the same. VB has some pretty severe limitations and while technically you can do the same with VB what you can do with C#, it will take jumping through some hoops to get some functionality in VB that you can get from C# out of the box.
Also, VB will let you code "wrong" and not worry about it, which is why novice and beginner types flock to it.
And yes, I do dislike VB for its syntax too.
SilentBill is offline  
Old   #12
 
elite*gold: 0
Join Date: Jul 2012
Posts: 147
Received Thanks: 196
Quote:
Originally Posted by SilentBill View Post
I wouldn't say they're the same. VB has some pretty severe limitations and while technically you can do the same with VB what you can do with C#, it will take jumping through some hoops to get some functionality in VB that you can get from C# out of the box.
Also, VB will let you code "wrong" and not worry about it, which is why novice and beginner types flock to it.
And yes, I do dislike VB for its syntax too.
Yeah... You have to reinvent the wheel to get anything worthwhile working. C# is definitely worth the little extra time to learn... Though I'm probably not a great example. XD


TheChinStrap is offline  
Reply



« Previous Thread | Next Thread »



All times are GMT +2. The time now is 17:49.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy
Copyright ©2017 elitepvpers All Rights Reserved.