
Screenwidth
Screenheight
这是获取屏幕的像素
mewidth
meheight
这是获取程序本身的像素
(meleft+image1left)/15
因为VB中默认的计量单位与像素是15比1的关系 所以转化为像素就要除以15
声明api: 函数WindowFromPoint 类型POINTAPI '-----------------------------dim pt as POINTAPIptx=200pty=200dim PThWnd as long PThWnd=WindowFromPoint(pt)msgbox PThWnd'----------------------------手写的,不排除会有输入错误,但是算法是正确的。。。。
很简单,等下给你
这个最主要的就是要找到那个窗口的位置跟大小,然后移动自己到相应位置
代码如下:
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
MeMove rRctLeft ScreenTwipsPerPixelX, rRctTop ScreenTwipsPerPixelY, (rRctRight - rRctLeft) ScreenTwipsPerPixelX, (rRctBottom - rRctTop) ScreenTwipsPerPixelY
End If
End Sub
在工具箱上右击->自定义工具箱->在com组件中找到vbnetwinsock控件。VB中使用方法是工程-部件-MicrosoftWinsockControl60然后把工具条中的MWC控件拖入窗体中也可以直接双击。
With CommonDialog1
ShowOpen
当前的路径 = Left(FileName, InStrRev(FileName, "\") - 1)
End With
以上就是关于vb判断控件在屏幕上的坐标全部的内容,包括:vb判断控件在屏幕上的坐标、VB获取窗口下,鼠标光标位置所在的控件句柄、vb窗体或控件如何在一个已运行的程序上定位等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)