0

I used this code in the server side

    void Window_Loaded(object sender, RoutedEventArgs e)
    {

        HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
        source.AddHook(new HwndSourceHook(WndProc));

    }
    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        // Handle messages...

            var htLocation = DefWindowProc(hwnd, msg, wParam, lParam).ToInt32();

            if (msg == 1)
            {
            MessageBox.Show("" + msg);
            }


        return new IntPtr(1);
    }

And I send the message from the client side like this

SendMessage(m_Process.MainWindowHandle, 1, (IntPtr)(-1), (IntPtr)(-1));

The problem is that the server side cannot receive this message, why?

6
  • 1
    Side note: Why do you have this: "" + msg and not something clearer like msg.ToString()? Commented Dec 14, 2016 at 12:32
  • thanks for this note Commented Dec 14, 2016 at 13:00
  • Are you sure you are sending to the correct window? I had issues where the WPF process had multiple window handles. Try: msdn.microsoft.com/en-us/library/ms633497(VS.85).aspx Commented Dec 14, 2016 at 13:09
  • yes i have two wpf applications, one start the other (client one start the server one), client now has pointer of the server & should send message correctly to the server Commented Dec 14, 2016 at 13:22
  • Check this out. Commented Dec 14, 2016 at 14:23

1 Answer 1

1

I found the mistake

the message id I sent must be 0x0112 not 1 this is for windows command

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.