单击外部对话框按钮(使用SendMessage函数?)对话框、单击、函数、按钮

2023-09-04 04:51:21 作者:清歌挽丶欲与离

基础知识:我有一个嵌入式的WebBrowser控件在Windows .NET窗体应用程序。这是触发这将打开另存下载对话框下载。我想在保存按钮,点击自动的。

Basics: I have a Windows .NET Form application with an embedded WebBrowser control. It is triggering a download which opens the "Save Download" dialog. I would like to click on the "Save" button automagically.

我发现这个其他的StackOverflow问题:http://stackoverflow.com/questions/3000102/$p$pss-save-button-of-file-download-dialog-of-internet-explorer-via-c但它没有真正的答案。

I found this other StackOverflow question: http://stackoverflow.com/questions/3000102/press-save-button-of-file-download-dialog-of-internet-explorer-via-c but it has no real answers.

在code我到目前为止在部署到实际的工作站不能可靠地工作。在调试运行它/从Visual Studio,它工作正常。在实际的工作站,有时保存按钮亮点,或去presses像它的点击,但没有真正发生。

The code I have so far doesn't reliably work when deployed to the actual workstation. Running it in debug/from Visual Studio, it works fine. On actual workstations, sometimes the Save button "highlights" or depresses like it's clicked, but nothing actually happens.

下面是code:

Dim dialogHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32770", "File Download")
Dim buttonTitle = "&Save"
Dim dialogButtonHandle = FindWindowEx(dialogHandle, IntPtr.Zero, "Button", buttonTitle)

SendMessage(dialogButtonHandle, BM_SETSTATE, 0, 0)
SendMessage(dialogButton, BM_CLICK, 1, 0)
SendMessage(dialogButtonHandle, BM_SETSTATE, 1, 0)

我不知道这是否是即使点击其他窗口按钮的完全100%正确的方式,但它似乎有点工作。也许我送SendMessage函数的太快了?太慢?我应该使用SendMessage函数与BM_CLICK等,或其他一些动作?我觉得我90%的存在方式..任何帮助将是AP preciated。

I have no idea if this is even the totally 100% correct way of clicking buttons in other windows, but it seems to somewhat work. Maybe I'm sending SendMessage's too fast? Too slow? Should I be using SendMessage with BM_CLICK, etc. or some other actions? I feel like I'm 90% of the way there.. any help would be appreciated.

推荐答案

在BM_SETSTATE消息只是使按钮看起来像它的pssed与否,我猜你不特别在意的$ P $,只是希望$ P $的pssing出现按钮的实际行动。

The BM_SETSTATE message simply makes the button look like its pressed or not, I'm guessing you don't particularly care about that and just want the actual action of pressing the button to occur.

试着改变

SendMessage(dialogButtonHandle, BM_SETSTATE, 0, 0)
SendMessage(dialogButton, BM_CLICK, 1, 0)
SendMessage(dialogButtonHandle, BM_SETSTATE, 1, 0)

要只

SendMessage(dialogButtonHandle, BM_CLICK, 1, 0)

请注意换到dialogBu​​ttonHandle为BM_CLICK消息。

Note the change to dialogButtonHandle for the BM_CLICK message.