提问人:IanJF 提问时间:7/16/2018 更新时间:7/17/2018 访问量:826
Visual Basic 和 MoveWindow 将外部应用窗口发送到屏幕外
Visual Basic & MoveWindow sending external app window way off screen
问:
我正在尝试从我的应用程序中放置几个外部窗口,但最终要么在左上角附近的屏幕上只剩下标题栏的一部分,要么窗口向右走得很远,最终达到 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
答:
0赞
IanJF
7/17/2018
#1
我安装了 PInvoke.net Visual Studio 扩展扩展,并得到了以下代码,这些代码最终对我有用:
<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
评论