重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
很简单,原因有二。第一,VB里long是32位,但是VB.NET里是64位,Dim ksWND As Integer才对。第二,VB在API里默认传址,而VB.NET默认传值,所以API里要添加Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long,添加"ByRef" lpRect As RECT) As Integer
站在用户的角度思考问题,与客户深入沟通,找到龙川网站设计与龙川网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都做网站、网站建设、企业官网、英文网站、手机端网站、网站推广、空间域名、网络空间、企业邮箱。业务覆盖龙川地区。
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long,byref lpRect As RECT) As Integer
Private Structure RECT
Dim Left As Integer
Dim Top As Integer
Dim Right As Integer
Dim Bottom As Integer
End Structure
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ksWND As integer
Dim ksTitle As String
Dim winS As RECT
If TextBox1.Text "" Then
ksTitle = TextBox1.Text
ksWND = FindWindow(vbNullString, ksTitle)
GetWindowRect(ksWND, winS)
MsgBox("左上角坐标(" winS.Left "," winS.Top ")" vbCrLf "右下角坐标(" winS.Right "," winS.Bottom ")" vbCrLf "窗口高" winS.Bottom - winS.Top "窗口宽" winS.Right - winS.Left)
Else
MsgBox("请填写窗口名称")
End If
End Sub
对不起,我没有学过vb.net,但是学过vb,希望这个可以
解决您程序的毛病。首先您注意以下两种GetClientRect
声明的方法:
Option Explicit
Private Declare Function GetClientRect Lib "user32" ( _
ByVal hwnd As Long, _
ByRef lpRect As RECT _
) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Dim r As RECT
Me.AutoRedraw = True
GetClientRect Me.hwnd, r
Print r.Left
Print r.Right
Print r.Top
Print r.Bottom
End Sub
----------------------------------------------------------------------------
Option Explicit
Private Declare Function GetClientRect Lib "user32" ( _
ByVal hwnd As Long, _
ByVal lpRect As Long _
) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Dim r As RECT
Me.AutoRedraw = True
GetClientRect Me.hwnd, VarPtr(r)
Print r.Left
Print r.Right
Print r.Top
Print r.Bottom
End Sub
看出问题了没有,就在GetClientRect的第二个参数上:
一个是按地址传递,另一个是按值传递:
ByRef lpRect As RECT 用 GetClientRect Me.hwnd, r
ByVal lpRect As Long 用 GetClientRect Me.hwnd, VarPtr(r)
据我所知vb.net按值传递的比较多,应该用VarPtr获取RECT类型
(结构体)的指针,然后传递。
希望能对你有所帮助。
把这个函数改成这样就好了Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer