Register for your free account! | Forgot your password?

You last visited: Today at 12:32

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


[Help] C# SendMessage()

Reply
 
Old   #1
 
elite*gold: 0
Join Date: May 2008
Posts: 1
Received Thanks: 0
[Help] C# SendMessage()

I'm currenty trying to use the SendMessage Function with CO. According to msdn I need to use this:
Code:
[DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
My question is: How do I find the hWnd? What are the wParam and lParam? And what can I use as wParam and lParam? Any help will be greatly appreciated.



edwin_j77 is offline  
Old 05/09/2010, 08:54   #2
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
hWnd is the handle, you need to get this, here's how you go about doing that, you can change the variable names obviously.
First you have to import FindWindow and SendMessage
Code:
 [DllImport("user32.dll")]
         public static extern int FindWindow(
         string lpClassName, // class name
         string lpWindowName // window name
         );
 [DllImport("user32.dll")]
         public static extern int SendMessage(
         int hWnd, // handle to destination window
         uint Msg, // message
         int wParam, // first message parameter
         int lParam // second message parameter
         );
then actually declaring your handle and implementing it, probably would be using an if statement if you're trying to accomplish an auto hunter or something like that.
Code:
 if (condition) {
 int coHandle = FindWindow(null,"[Conquer] Legends Return"); //It might not be legends return can't  remember off the top of my head lol
 int msgParam = 0; //Message to send, like the function
 int smParam1 = 0; //First parameter
 int smParam2 = 0; //Second parameter
 SendMessage(coHandle, msgParam, smParam1, smParam2);
}
Not sure what you're trying to accomplish exactly but that should answer your question.
and if you keep the smParam1/2 set to 0 it'll work fine as long as the msgParam performs everything needed.


Ian* is offline  
Old 05/10/2010, 00:52   #3
 
elite*gold: 0
Join Date: May 2010
Posts: 59
Received Thanks: 58
First of all thanks for replying. I'm edwin_j77(the one who created the thread), I was using my old computer and didn't realize my old account was logged in =p Anyways, as my signature says, I'm trying to do a skill leveler, so I need to send right clicks and some other keys.

For the handle I made a loop that searches processes for the string "Conquer" and puts them in a listbox so I can see them. Then I set the handle to whatever value is selected on the listbox. Your method might work too(I haven't tried it), however, if I have more than one Conquer open at once then I can't choose which one I'll send the message to.

As for the lParam and wParam, I saw on an example I found they used 0 too, however I also read on another page that you should never use int as lParam or wParam because that will cause the program to crash on 64-bit windows. It said to use IntPtr but 0 is an int so It won't let me use it. I don't use 64-bit windows so this isn't a big problem for now. The problem I have now is that I can't send the message. I'm currently using this:
Code:
 public const UInt32 VK_F10 = 0x79;
and using VK_F10 as the message. So far I haven't been successful Any ideas as to what I'm doing wrong?

EDIT: Found out I can use IntPtr.zero to set the lParam and wParam to 0.
SigmaD is offline  
Old 05/10/2010, 03:35   #4
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
Hm, it should work.

Are you positive that you're getting the correct handle?
Give my method a try


Ian* is offline  
Old 05/10/2010, 03:46   #5
 
elite*gold: 0
Join Date: May 2010
Posts: 59
Received Thanks: 58
Quote:
Originally Posted by Ian* View Post
Hm, it should work.

Are you positive that you're getting the correct handle?
Give my method a try
Well I tried your method and it didn't work either =\ also I sent the value of the handle using your method to a label and compared it to the value I got using my method and they were exactly the same so the handle isn't the problem.
This is what I'm using:
Code:
 [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

        public const UInt32 VK_F10 = 0x79; //0x79 is the value of the F10 key according to MSDN
Code:
SendMessage(coHandle, VK_F10, IntPtr.Zero, IntPtr.Zero);
SigmaD is offline  
Old 05/10/2010, 06:33   #6
 
elite*gold: 0
Join Date: Dec 2006
Posts: 1,039
Received Thanks: 1,268
Background keyboard clicks won't work in CO, get the coordinates of the F10 box and right click it instead
gabrola is offline  
Thanks
1 User
Old 05/10/2010, 06:41   #7
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
Or hook the f key function
Ian* is offline  
Old 05/10/2010, 16:25   #8
 
elite*gold: 0
Join Date: May 2010
Posts: 59
Received Thanks: 58
That would explain why it didn't work... lol so how do I choose what coordinates I want it to send the click? I tried using wParam and lParam as x and y but it didn't work.
I'm using these as the messages:
Code:
public const UInt32 WM_RBUTTONDOWN = 0x0204;
public const UInt32 WM_RBUTTONUP = 0x0205;
Also, should I use hex or decimal for the message values?
SigmaD is offline  
Old 05/10/2010, 17:42   #9
 
elite*gold: 0
Join Date: Nov 2009
Posts: 390
Received Thanks: 318
1- Hex or decimal doesn't matter, they are all numbers after all.
2- The messages that you included, use WPARAM as a virtual key included with click:
Code:
MK_CONTROL

    The CTRL key is down.

MK_LBUTTON

    The left mouse button is down.

MK_MBUTTON

    The middle mouse button is down.

MK_RBUTTON

    The SHIFT key is down.

MK_XBUTTON1

    The first X button is down.

MK_XBUTTON2

    The second X button is down.
3- LPARAM contains the x-coord and y-coord as low-order and high-order, where x is the low-order value and y is the high-order value.
Nullable is offline  
Thanks
1 User
Old 05/11/2010, 09:05   #10
 
elite*gold: 0
Join Date: May 2010
Posts: 59
Received Thanks: 58
How do I assign two values to a single parameter?
SigmaD is offline  
Old 05/11/2010, 09:25   #11
 
elite*gold: 0
Join Date: Apr 2007
Posts: 906
Received Thanks: 1,431
Quote:
Originally Posted by SigmaD View Post
How do I assign two values to a single parameter?
use a dictonary or a list or an array or a or a string with a seperator

but then ask urself, are u sure u want 2 values on a single parameter?
Warlax is offline  
Thanks
1 User
Old 05/11/2010, 13:02   #12
 
elite*gold: 0
Join Date: Jan 2010
Posts: 121
Received Thanks: 7
LOL I am trying to make a skill leveler too but I am using a different function SendInput I can make clicks and keystrokes but I can't specify a window.
shimo diaz is offline  
Old 05/11/2010, 14:36   #13
 
elite*gold: 0
Join Date: Nov 2009
Posts: 390
Received Thanks: 318
Quote:
Originally Posted by Warlax View Post
use a dictonary or a list or an array or a or a string with a seperator

but then ask urself, are u sure u want 2 values on a single parameter?
Lol, he meant how to set the hibyte and lobyte of the LPARAM.
Anyways, there is this macro
Quote:
#define MAKELONG(a, b) ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16))
Nullable is offline  
Thanks
1 User
Old 05/11/2010, 15:28   #14
 
elite*gold: 0
Join Date: Jan 2010
Posts: 121
Received Thanks: 7
@SigmaD
Try MSDN forums
Visual C# Language Forum
shimo diaz is offline  
Thanks
1 User
Old 05/11/2010, 15:59   #15
 
elite*gold: 0
Join Date: May 2010
Posts: 59
Received Thanks: 58
Quote:
Originally Posted by Nullable View Post
Lol, he meant how to set the hibyte and lobyte of the LPARAM.
Anyways, there is this macro
I have no idea how to use that lol but thanks anyways. I'll look for info on it =p
Quote:
Originally Posted by shimo diaz View Post
@SigmaD
Try MSDN forums
Visual C# Language Forum
I didn't know they had forums lol thanks


SigmaD is offline  
Reply



« Correct way to handle speedhack | [Request]Need Sirhooks old version source »

Similar Threads
C++ SendMEssage Problem
12/11/2010 - C/C++ - 53 Replies
Hey Comunity, bin C++ Anfänger und hab da ein Problem. Und zwar möchte ich Tastendrücke mithilfe meines Programms simulieren, da hab ich mir gedacht, dass ich SendMessage benutze. Mein Problem ist jetzt, dass ich nicht weiß, wo ich das Parameter...
C++ SendMessage Problem
08/02/2010 - C/C++ - 1 Replies
Also ich versuche gerade in C++ einen kleinen Spammer zu programmieren habe aber leider ein Problem. Mein Code: #include <iostream> #include <windows.h> #include <string> using namespace std;
delphi sendmessage
07/27/2010 - General Coding - 3 Replies
hallo leute ich hab mal eine frage ob mir jemand kurz erläutern könnte wie ich mit sendmessage eine mausbewegung in einem minimierten fenster ausgebe ich habe embarcadero rad studio 2010 hier ist der bisherige "source": uses Windows,...
sendmessage?
12/26/2008 - CO2 Programming - 0 Replies
just wondering how it works in C# tried few tutorials with notepad in it and it doesnt send the letters/close it even it finds the window this is how i got it so far (pretty much copypasted, just to see how it works...) private...
how do i sendmessage a password box
05/11/2007 - CO2 Main - Discussions / Questions - 11 Replies
HI, I&#39;m trying to sendmessage the password to the password box. It gives me the *** in the box but when i click the enter button it gives me the wrong password error. any help would be appreciated



All times are GMT +2. The time now is 12:32.


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

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