有没有实现里面说的功能的API函数,求达人解决~~
在VB里,MouseDown事件里有X,Y来代表鼠标相对于某个控件的坐标。
用API函数GetCursorPos可以获得鼠标相对于屏幕的坐标
在VB里,Left和Top属性表明了一个控件相对于容器的坐标
那么问题就是:
用API函数*****可以获得一个控件相对于屏幕的坐标?
很缺德的问题,我找到脖子都疼了~~~
[解决办法]
ClientToScreen,可以把窗口的客户区坐标转为屏幕坐标,示例:
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As LongPrivate Type POINTAPI x As Long y As LongEnd TypePrivate Sub Command1_Click()Dim aX As Long, aY As LongDim aP As POINTAPIaP.x = Command1.LeftaP.y = Command1.TopaX = aP.xaY = aP.yClientToScreen Me.hwnd, aP '将相对坐标转为屏幕坐标MsgBox "我的相对坐标是:(" & aX & "," & aY & "),屏幕坐标是:(" & aP.x & "," & aP.y & ")"End SubPrivate Sub Form_Load()Me.ScaleMode = 3 '客户区以像素为单位End Sub