SendMessage and PostMessage not works on WPF Window

-1

I want to click a button from a wpf window from another wpf window ... But I have an issue , the click fires correctly but nothing happens!

here's my code :

 int click_x = 60;
    int click_y = 30;
    int click_point_x = Convert.ToInt32(working_area.Margin.Left) + click_x;
    int click_point_y = Convert.ToInt32(working_area.Margin.Top) + click_y;

    IntPtr windowHandle = new System.Windows.Interop.WindowInteropHelper(this).Handle;
    var w = (click_point_y << 16) | click_point_x;
    if (windowHandle != IntPtr.Zero)
    {
        HandleRef hWnd = new HandleRef(windowHandle, windowHandle);
        PostMessage(hWnd, 0x201, 0x00000001, w);
        await Task.Delay(500);
        PostMessage(hWnd, 0x202, 0x00000001, w);

    }

I added task.delay and tested this , after I calling postmessage on left mouse down , If I click at delay time , it works! but if I don't , nothing happens , only color of button changes like it's clicked but nothing happens!

How can I make it working ?

More Detail :

  • at x = 60 and y = 30 there's a WPF Button [button_1].
  • there's another button that calls PostMessage function [button_2].
  • I press button_2 and button_1 goes highlighted for 1 or 2 second but nothing happens , Button_1 function doesn't fire up.
  • Again I press button_2 and when button_1 goes highlighted , I click on mouse ... and Button_1 function fires up !
  • I think there's some issue with click function.

  • This is what happens : http://murder.is-best.net/what_happens.mp4

c#
wpf
asked on Stack Overflow Oct 18, 2018 by user9921837 • edited Oct 18, 2018 by user9921837

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0