补充一下:a.exe 虽然没有标题栏,但它的窗口类名已知且类名在当前所有打开的窗口的类名中是唯一的。另外,b.exe 最好能有这样的功能: 命令行运行 b.exe x y 即可将a.exe的窗口位置移动到屏幕坐标(100,100)处。
要用到API,下面是源码。 天狼工作室 http://www.j2soft.cn/ Option ExplicitPrivate Type RECT Left As Long Top As Long Right As Long Bottom As Long End TypePrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function MoveWindow Lib "user32" (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 Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As LongPrivate Sub MoveForm(aStrTitle As String, x As Long, y As Long) Dim hWndFind As Long Dim rt As RECT
hWndFind = FindWindow(vbNullString, aStrTitle) GetWindowRect hWndFind, rt MoveWindow hWndFind, x, y, rt.Right - rt.Left, rt.Bottom - rt.Top, True End Sub Private Sub Command1_Click() MoveForm "位置测试窗口", 100, 200 End SubPrivate Sub Form_Load() Dim arrPos As Variant arrPos = Split(Command, " ") If UBound(arrPos) < 1 Then Exit Sub MoveForm "位置测试窗口", CLng(arrPos(0)), CLng(arrPos(1)) End Sub 天狼工作室 http://www.j2soft.cn/
天狼工作室
http://www.j2soft.cn/
Option ExplicitPrivate Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function MoveWindow Lib "user32" (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
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As LongPrivate Sub MoveForm(aStrTitle As String, x As Long, y As Long)
Dim hWndFind As Long
Dim rt As RECT
hWndFind = FindWindow(vbNullString, aStrTitle)
GetWindowRect hWndFind, rt
MoveWindow hWndFind, x, y, rt.Right - rt.Left, rt.Bottom - rt.Top, True
End Sub
Private Sub Command1_Click()
MoveForm "位置测试窗口", 100, 200
End SubPrivate Sub Form_Load()
Dim arrPos As Variant arrPos = Split(Command, " ") If UBound(arrPos) < 1 Then Exit Sub MoveForm "位置测试窗口", CLng(arrPos(0)), CLng(arrPos(1))
End Sub
天狼工作室
http://www.j2soft.cn/
http://www.j2soft.cn/
后一句话错了!你打开的窗口是没有,但是,你不能保证系统打开的窗口中也没有吧!
先前我用 setwindowpos() 试过,发现只能移动有标题栏的窗口。MoveWindow 确实还没试过。
MoveWindow()应该可以搞定。
因为我是在我本地测试没问题,才把代码发上来的~~~~~天狼工作室
http://www.j2soft.cn/
我自己写的代码能移动带标题栏的窗口,但怎么也无法移动这个 object dock 的标签停驻栏。郁闷了ObjectDock Plus 下载地址: ftp://file1.myfiles.com.cn/myfiles/App/myfiles_HA_StardockObjectDockPlus_v13_Fix.rar各位高手帮我看看,该怎么来移动它的标签停驻栏(标签停驻栏设置为非“附加到边缘”状态)