0
Reply

PostMessage in other process problem.

Orjol

Orjol

Apr 10 2009 4:45 PM
7.5k
Hello

sendPost doesnt work anymore.

I have 3 days exp. in C#.

And dont know how to fix that.

What I need, it find my process (I have it)

Click on X,Y coordinate in this programm and write a message there.

What I have

Code for send message

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("User32.Dll", EntryPoint = "PostMessageA")]
        static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);

        [DllImport("user32.dll")]
        static extern byte VkKeyScan(char ch);

        const uint WM_KEYDOWN = 0x100;

            Process[] pisja = Process.GetProcesses();

            foreach (Process proc in pisja)
            {

                if (proc.MainWindowTitle == "Geo")
                {

                    IntPtr hWnd = FindWindowEx(proc.MainWindowHandle, IntPtr.Zero, "edit", null);
                   
                    string s = "hello";
                    for (int i = 0; i < s.Length; i++)
                    {
                        PostMessage(hWnd, WM_KEYDOWN, VkKeyScan(s[i]), 0);
                    }
                    break;
                }
            }

Code for mouse click (i think, or maybe it onlye move):

const uint WM_MOUSEMOVE = 0x0200;

PostMessage(hWnd, WM_MOUSEMOVE, 0, 138 * 0x10000 + 187);

(coorginates in pixels)

Where is problem?
I know that in my head, but where in code?