sendmessage?

12/26/2008 22:51 zarut#1
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...)
Code:
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr FindWindow(string winClass, string WinName);
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

        private const uint WM_ACTIVATEAPP = 0x001C;
        private const uint WM_KEYDOWN = 0x0100;
        private const uint WM_KEYUP = 0x0101;
        private const uint WM_SETFOCUS = 0x0007;

        static void Main(string[] args)
        {
            IntPtr WinHandle = IntPtr.Zero;
            WinHandle = FindWindow(null, "Nimetön - Muistio");

            if (WinHandle != IntPtr.Zero)
            {
                Console.WriteLine(WinHandle.ToString());
                SendMessage(WinHandle, WM_ACTIVATEAPP, (IntPtr)1, IntPtr.Zero);
                SendMessage(WinHandle, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
                SendMessage(WinHandle, WM_KEYDOWN, (IntPtr)0x31, (IntPtr)1);
                SendMessage(WinHandle, WM_KEYUP, (IntPtr)0x31, (IntPtr)1);
            }
so could someone clear me out abit?