vb窗体或控件如何在一个已运行的程序上定位
已经把窗口设在最前以后,要使我编写的vb窗体覆盖在某程序表面,并且固定在这个窗口的某个位置,那个程序的窗口移动的话vb窗体也要跟着移动例如:我要让vb里的pictureb...
已经把窗口设在最前以后,要使我编写的vb窗体覆盖在某程序表面,并且固定在这个窗口的某个位置,那个程序的窗口移动的话vb窗体也要跟着移动
例如:我要让vb里的picturebox控件跟着某个已运行的程序的窗口移动
vb整个窗体跟着移动也可以
最好要在那个程序不运行的时候就不显示 展开
例如:我要让vb里的picturebox控件跟着某个已运行的程序的窗口移动
vb整个窗体跟着移动也可以
最好要在那个程序不运行的时候就不显示 展开
6个回答
展开全部
很简单,等下给你
这个最主要的就是要找到那个窗口的位置跟大小,然后移动自己到相应位置
代码如下:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Dim rRct As RECT
Function cmdGetClass(exeTitle As String) As Boolean
If exeTitle = "" Then cmdGetClass = False: Exit Function
Dim lngHand As Long
Dim strName As String * 255
Dim lngProcID As Long
lngHand = FindWindow(vbNullString, exeTitle)
GetClassName lngHand, strName, Len(strName)
If Left$(strName, 1) = vbNullChar Then
cmdGetClass = False
Else
GetWindowThreadProcessId lngHand, lngProcID
GetWindowRect lngHand, rRct
cmdGetClass = True
End If
End Function
Private Sub Command1_Click()
Dim sCaption As String '要找的窗口的标题
sCaption = "我的电脑"
If cmdGetClass(sCaption) Then
Me.Move rRct.Left * Screen.TwipsPerPixelX, rRct.Top * Screen.TwipsPerPixelY, (rRct.Right - rRct.Left) * Screen.TwipsPerPixelX, (rRct.Bottom - rRct.Top) * Screen.TwipsPerPixelY
End If
End Sub
这个最主要的就是要找到那个窗口的位置跟大小,然后移动自己到相应位置
代码如下:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Dim rRct As RECT
Function cmdGetClass(exeTitle As String) As Boolean
If exeTitle = "" Then cmdGetClass = False: Exit Function
Dim lngHand As Long
Dim strName As String * 255
Dim lngProcID As Long
lngHand = FindWindow(vbNullString, exeTitle)
GetClassName lngHand, strName, Len(strName)
If Left$(strName, 1) = vbNullChar Then
cmdGetClass = False
Else
GetWindowThreadProcessId lngHand, lngProcID
GetWindowRect lngHand, rRct
cmdGetClass = True
End If
End Function
Private Sub Command1_Click()
Dim sCaption As String '要找的窗口的标题
sCaption = "我的电脑"
If cmdGetClass(sCaption) Then
Me.Move rRct.Left * Screen.TwipsPerPixelX, rRct.Top * Screen.TwipsPerPixelY, (rRct.Right - rRct.Left) * Screen.TwipsPerPixelX, (rRct.Bottom - rRct.Top) * Screen.TwipsPerPixelY
End If
End Sub
展开全部
这个恐怕难吧,比判断一个外部程序是否运行都还难哟!
期待高手解决!
期待高手解决!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分低了点吧,兄弟!高手是不会帮你解决这样的问题的,不过别人心情好,也说不一定
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用setparent函数,把程序的某个控件设置为目标窗口下的子窗口,可以做到这一点。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建一个Timer1,打开一个记事本。其他要求可细谈。
代码如下。
================
Private Const HWND_TOPMOST = -1
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
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 Sub Form_Load()
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Dim h As Long, r As RECT
h = FindWindow("notepad", vbNullString)
GetWindowRect h, r
SetWindowPos hwnd, HWND_TOPMOST, r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top, 0
End Sub
代码如下。
================
Private Const HWND_TOPMOST = -1
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
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 Sub Form_Load()
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Dim h As Long, r As RECT
h = FindWindow("notepad", vbNullString)
GetWindowRect h, r
SetWindowPos hwnd, HWND_TOPMOST, r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top, 0
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的要求和你的分差距太多,高手一般懒的弄的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询