A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

[C#][Help]Postmessage Api

1.5k views · started by Bman ·
#1
[C#][Help]Postmessage Api
        private void button1_Click(object sender, EventArgs e)
{

const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;

Form1 Frm = new Form1();

//IntPtr notepad = FindWindow("Form1", null);

IntPtr editx = FindWindowEx(this.Handle, IntPtr.Zero, "textbox", null);

PostMessage(editx, WM_KEYDOWN, (int)Keys.A, 0);
PostMessage(editx, WM_KEYUP, (int)Keys.A, 0);


}


Im not quite sure why this wont work.

Im trying to send the Key "A" to a textbox on the form that the button is pressed on.
Also, where the code is commented, What would I lock onto? Form1? Form 1's text?

Thanks in advance :P
#2
What. Please specify more. Are you trying to access another control on a different form? If so you need to make that control a public static or have a functions you can call from the other form thats a public void or something that will put the text in the designated area.

Let's say this is frmSettings that you want to send the data to. You would have a public void like this that will put the text in the text box.

public void EditText(String Data)
{
txtWhatEver.Text = Data;
}


And the button on frmMain sending the data to the text box.

private void btnWhatEver_Click or w/e(what ever goes here)
{
frmSettings Settings = new frmSettings();
Settings.EditText(Data you want the text box to have);
}


The other method I mentioned you need to go into the forms settings and find the textbox and make it a public static.
#3
looks hard
#4
Chad wrote:
What. Please specify more. Are you trying to access another control on a different form? If so you need to make that control a public static or have a functions you can call from the other form thats a public void or something that will put the text in the designated area.

Let's say this is frmSettings that you want to send the data to. You would have a public void like this that will put the text in the text box.

public void EditText(String Data)
{
txtWhatEver.Text = Data;
}


And the button on frmMain sending the data to the text box.

private void btnWhatEver_Click or w/e(what ever goes here)
{
frmSettings Settings = new frmSettings();
Settings.EditText(Data you want the text box to have);
}


The other method I mentioned you need to go into the forms settings and find the textbox and make it a public static.


Ohh no its not that :(

Postmessage sends a command to a hwnd or specific control, in this case I want to send the command of A key down, and up, without taking over the keyboard.
I looked all through google and couldnt find anything for C#, over Vb.

Its kindalike a silent sendkeys.
#5
You can just use SendKeys

SendKey.Send(Key.A);
#6
I dont want to use SendKeys. Because it takes over the keyboard, and the form must be focused.

Post message is the complete opposite of that.
#7
C# Post Message Api

The first two worked for me.
#8
Thanks.

Ill mess around with it abit.

Oh shi-

It works. I love you chad. :)