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.
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.
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
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?
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.
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.
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
für die "zu drückende" Taste hinschreiben soll bzw. in welcher Form;
als Hex oder VK_KEY_? . Der Bot soll einfach nur ununterbrochen
"w" drücken, jedoch krig ich es einfach nicht hin.
Bei Google hab ich nix gefunden, MSDN hab ich nicht...
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, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
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 static extern IntPtr FindWindow(string winClass, string WinName);
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private static extern IntPtr PostMessage(IntPtr hWnd,...
how do i sendmessage a password box 05/11/2007 - Conquer Online 2 - 11 Replies HI,
I'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