簡體   English   中英

ShowWindow不會設置焦點或最大化

[英]ShowWindow won't set focus or maximize

以下代碼不會將焦點設置在我需要的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

已更改(VB6)

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

至(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

感謝Hans Passant的評論

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM