自动刷新 IE 窗口在 VB.Net 中不起作用
我尝试编写一个简单的函数将 Internet Explorer 窗口带到前台,然后按 F5 使用 dll 函数刷新它:
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Integer) As Integer
然后稍后使用以下方法调用此函数:
SetForegroundWindow(processID.MainWindowHandle.ToInt32)
SendKeys.Send("{F5}")
但是,当我尝试调试代码时,setforeground 确实如此不工作。
我使用的是 Windows 2008(64 位),所以我认为应该使用 ToInt64。然而,这似乎也没有达到目的,当我调用 SetForegroundWindow 时,似乎没有任何结果。
还有其他推荐吗?我正在使用 VS 2008。
很多 thnaks!
I have tried to write a simple function to bring an Internet Explorer windows to the foreground and then press F5 to refresh it using the dll function:
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Integer) As Integer
and then later call this function using:
SetForegroundWindow(processID.MainWindowHandle.ToInt32)
SendKeys.Send("{F5}")
However, when I tried to debug the code, the setforeground does not work.
I am using a Windows 2008 (64 bit) so I thought I should use ToInt64 instead. However that did not seem to do the trick as well, when I called SetForegroundWindow, nothing seems to come up.
Is there any other recommendation? I am using VS 2008.
Many thnaks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
P/Invoke 签名 我可以发现建议参数应该是 IntPtr,而不是一个大小的整数(这是有道理的 - 您不需要为 32 位和 64 位编写单独的代码):
此外,焦点问题非常难以调试,因为调试器窗口往往需要始终重新获得焦点(例如,如果您单步执行,它可能会将焦点设置在其他地方,然后立即重新获得焦点以显示下一行代码)
P/Invoke signatures I can find suggest the parameter ought to be an IntPtr, not a sized integer (which kind of makes sense - you shouldn't be needing to write separate code for 32 and 64 bit):
Also, focus issues are notoriously difficult to debug, since the debugger window tends to want to regain focus all of the time (e.g. if you single step, it may set the focus elsewhere, then immediately regain the focus to show the next line of code)