用VB程序移动某个程序的窗口至300,600(屏幕坐标)
已有代码如下:OptionExplicitPrivateDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(By...
已有代码如下:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Sub Command1_Click()
Dim h As Long
h = FindWindow(vbNullString, "名字")
SetWindowPos h, 0, 0, 0, 0, 0, SWP_NOSIZE
End Sub
那个"名字"就是标题,但是标题会变,不确定是什么.所以有什么办法吗?
如果可以解决这个问题追加30分!
目前只能移动到0,0的位置,我想可以换位置,代码应该在哪里改变? 展开
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Sub Command1_Click()
Dim h As Long
h = FindWindow(vbNullString, "名字")
SetWindowPos h, 0, 0, 0, 0, 0, SWP_NOSIZE
End Sub
那个"名字"就是标题,但是标题会变,不确定是什么.所以有什么办法吗?
如果可以解决这个问题追加30分!
目前只能移动到0,0的位置,我想可以换位置,代码应该在哪里改变? 展开
4个回答
展开全部
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
这个函数有两个参数,第一个是要找的窗口的类,第二个是要找的窗口的标题。在搜索的时候不一定两者都知道,但至少要知道其中的一个。有的窗口的标题是比较容易得到的,如"计算器",所以搜索时应使用标题进行搜索。但有的软件的标题不是固定的,如"记事本",如果打开的文件不同,窗口标题也不同,这时使用窗口类搜索就比较方便。如果找到了满足条件的窗口,这个函数返回该窗口的句柄,否则返回0。
第一个是要找的窗口的类,第二个是要找的窗口的标题。
这个函数有两个参数,第一个是要找的窗口的类,第二个是要找的窗口的标题。在搜索的时候不一定两者都知道,但至少要知道其中的一个。有的窗口的标题是比较容易得到的,如"计算器",所以搜索时应使用标题进行搜索。但有的软件的标题不是固定的,如"记事本",如果打开的文件不同,窗口标题也不同,这时使用窗口类搜索就比较方便。如果找到了满足条件的窗口,这个函数返回该窗口的句柄,否则返回0。
第一个是要找的窗口的类,第二个是要找的窗口的标题。
展开全部
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Sub Command1_Click()
Dim H As Long
Dim EXE As String
EXE = "名称"
H = FindWindow(vbNullString, EXE)
SetWindowPos H, 0, 300, 600, 0, 0, SWP_NOSIZE
End Sub
标题名称用变量代替,这样你可以随时修改变量的值!
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Sub Command1_Click()
Dim H As Long
Dim EXE As String
EXE = "名称"
H = FindWindow(vbNullString, EXE)
SetWindowPos H, 0, 300, 600, 0, 0, SWP_NOSIZE
End Sub
标题名称用变量代替,这样你可以随时修改变量的值!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的问题是得不到句柄,得到的话
SetWindowPos h, 0, 300, 600, 0, 0, SWP_NOSIZE
即可实现
SetWindowPos h, 0, 300, 600, 0, 0, SWP_NOSIZE
即可实现
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
h = FindWindow(vbNullString, me.Caption)
SetWindowPos h, 0, 300, 300, 0, 0, SWP_NOSIZE
SetWindowPos h, 0, 300, 300, 0, 0, SWP_NOSIZE
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询