0

我正在尝试从我的应用程序中定位几个外部窗口,但要么最终在屏幕左上角附近仅显示一段标题栏,要么窗口向右远并最终位于 x = 32767

函数声明位于模块中,Move_Notepad Sub 是表单的一部分。

    Option Explicit On

    Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Declare Function MoveWindow Lib "user32.dll" Alias "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long


    Public Sub Move_Notepad()
         'Move NotePad to 1,1 and set its Width and height to 800,720 (pixels)
         Dim GoWindow As Long
         hWinHand = FindWindow(vbNullString, "Untitled - Notepad")
         GoWindow = MoveWindow(hWinHand, 1, 1, 800, 720, 1)
    End Sub

    Private Sub bMove_Notepad_Click(sender As Object, e As EventArgs) Handles bMove_Notepad.Click
        Move_Notepad()
    End Sub
4

1 回答 1

0

我安装了 PInvoke.net Visual Studio Extension 扩展并得到了以下代码,它最终对我有用:

    <DllImport("user32.dll")>
    Public Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
    End Function
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    Public Function FindWindow(
    ByVal lpClassName As String,
    ByVal lpWindowName As String) As IntPtr
    End Function
于 2018-07-17T13:08:45.853 回答