0

I'm trying to send BM_CLICK to a window in another process.

When the target button get clicked, the target window pops up a modal dialog, then my calling thread never return even I send the timeout to 1 second.

SendMessageTimeout(handle, BM_CLICK, 0, 0, SMTO_ABORTIFHUNG | SMTO_NORMAL, 1000, NULL);

What's the reason of this? Is there any idea I can prevent this?

There are some potential solutions:

  1. Use PostMessage with WM_LBUTTONDOWN and WM_LBUTTONUP to simulate the click
  2. If I remember correctly, PostMessage doesn't support BM_CLICK, isn't it?
user1633272
  • 2,007
  • 5
  • 25
  • 48
  • Any one down vote this can give a reason? – user1633272 Sep 13 '17 at 16:22
  • 2
    `SMTO_ABORTIFHUNG` means to abort if the other side is hung, ie is not processing messages in a timely manner. Displaying a modal dialog is not a hang, since the modal loop processes messages. You can't combine `SMTO_NORMAL` with other flags since `SMTO_NORMAL` is 0. – Remy Lebeau Sep 13 '17 at 17:01
  • In any case, don't simulate `WM_LBUTTON...` manually. That is exactly what `BM_CLICK` already does for you: "*This message causes the button to receive the `WM_LBUTTONDOWN` and `WM_LBUTTONUP` messages, and the button's parent window to receive a `BN_CLICKED` notification code*". And yes, you can use `BM_CLICK` with `PostMessage()` (I tested it, it works fine), as `BM_CLICK` does not have a return value, so no need to wait for one. – Remy Lebeau Sep 13 '17 at 17:03
  • As Remy wrote, `BM_CLICK` doesn't have a return value so there is no point at all in using `SendMessageTimeout()`. Just use `PostMessage()` and be done with it. – zett42 Sep 13 '17 at 17:06
  • Modal dialog is not hung, that the tricky thing, is there anyway to make SendMessageTime returns after some time ignoring the modal dialog? I will try PostMessage anyway. – user1633272 Sep 13 '17 at 17:10
  • @RemyLebeau and zett42 You guys are awesome! PostMessage works. (My memory is not reliable) – user1633272 Sep 13 '17 at 17:16
  • 2
    Why not UI Automation? – David Heffernan Sep 13 '17 at 19:49
  • @DavidHeffernan Last time I gave up UI Automation is may because of lack of operations on non-expanded sub items in tree view. Seems that UI Automation doesn't handle invisible components very well. Correct me if I'm wrong. – user1633272 Sep 14 '17 at 03:13

0 Answers0