简体   繁体   English

ShowWindow不会设置焦点或最大化

[英]ShowWindow won't set focus or maximize

The following code will not set focus to the IE window that I need, nor will it maximize it like it's supposed to. 以下代码不会将焦点设置在我需要的IE窗口上,也不会像预期的那样最大化它。

Option Explicit On
Public Class Form1
    Public Declare Auto Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Sub automateIE()
        Dim shellWindows = New SHDocVw.ShellWindowsClass()
        For Each ie As SHDocVw.InternetExplorer In shellWindows
            Dim isIE As Boolean = True
            Try
                Dim ie2 As mshtml.IHTMLDocument = ie.Document
            Catch ex As Exception
                isIE = False
            End Try
            If isIE Then
                If ie.LocationURL.Contains("url") Then
                    ShowWindow(ie.HWND, 3)
                    Exit For
                End If
            End If
        Next
    End Sub
End Class

Changed (VB6) 已更改(VB6)

Public Declare Auto Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

To (VB.NET) 至(VB.NET)

Imports System.Runtime.InteropServices
...
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As ShowWindowCommands) As Boolean
End Function
Enum ShowWindowCommands As Integer
    SW_MAXIMIZE = 3
    ...
End Enum

Thanks to Hans Passant's comment 感谢Hans Passant的评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM