VisualFreeBasic:类似VisualBasic6的FreeBasic语言集成开发环境
http://www.yfvb.com/soft-48.htm
在vb6时代,这样代码很多,网上找了下,核心功能如下:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If IsDragging = True Then
Dim rtn As Long, curwnd As Long
Dim tempstr As String
Dim strlong As Long
Dim point As POINTAPI
point.x = x
point.y = y
'将客户坐标转化为屏幕坐标并显示在PointText文本框中
If ClientToScreen(frmMain.hwnd, point) = 0 Then Exit Sub
PointText.Text = Str(point.x) + "," + Str(point.y)
'获得鼠标所在的窗口句柄并显示在hWndText文本框中
curwnd = WindowFromPoint(point.x, point.y)
hWndText.Text = Str(curwnd)
'获得该窗口的类型并显示在WndClassText文本框中
tempstr = Space(255)
strlong = Len(tempstr)
rtn = GetClassName(curwnd, tempstr, strlong)
If rtn = 0 Then Exit Sub
tempstr = Trim(tempstr)
WndClassText.Text = tempstr
'向该窗口发送一个WM_GETTEXT消息,以获得该窗口的文本,并显示在PasswordText文本框中
tempstr = Space(255)
strlong = Len(tempstr)
rtn = SendMessage(curwnd, WM_GETTEXT, strlong, tempstr)
tempstr = Trim(tempstr)
PasswordText.Text = tempstr
End If
End Sub
复制到vfb里改改就用了,api各种函数都是默认即可使用,不用在自己声明,大致如下:
Dim Shared IsDragging As Boolean
Sub Form1_Image1_WM_LButtonDown(hWndForm As hWnd, MouseFlags As Long, xPos As Long, yPos As Long) '按下鼠标左键
If IsDragging = False Then
IsDragging = True
'Screen.MouseIcon = LoadPicture(App.Path + "\Eye.ico")
'Screen.MousePointer = vbCustom
'将以后的鼠标输入消息都发送到本程序窗口
SetCursor LoadCursor(Null, IDC_CROSS)
SetCapture(hWndForm)
End If
End Sub
Sub Form1_WM_LButtonUp(hWndForm As hWnd, MouseFlags As Long, xPos As Long, yPos As Long) '释放鼠标左键
If IsDragging = True Then
'Screen.MousePointer = vbDefault
IsDragging = False
SetCursor LoadCursor(Null, IDC_ARROW)
'释放鼠标消息抓取
ReleaseCapture
End If
End Sub
Sub Form1_WM_MouseMove(hWndForm As hWnd, MouseFlags As Long, xPos As Long, yPos As Long) '移动鼠标
If IsDragging Then
Dim rtn As Long
dim curwnd As Long
Dim tempstr As String
Dim strlong As Long
Dim pt As Point
Dim p As LPPOINT = @pt
Print Str(xPos) + "," + Str(yPos)
( *p).x = xPos
( *p).y = yPos
'将客户坐标转化为屏幕坐标并显示在PointText文本框中
If ClientToScreen(hWndForm, p) = 0 Then Exit Sub
'获得鼠标所在的窗口句柄并显示在hWndText文本框中
Print Str(( *p).x) + "," + Str(( *p).y)
pt.x = ( *p).x
pt.y = ( *p).y
curwnd = WindowFromPoint(pt)
if 0 = curwnd Then Exit sub
Print "WindowFromPoint " + Str(curwnd)
'获得该窗口的类型并显示在WndClassText文本框中
tempstr = Space(255)
strlong = Len(tempstr)
rtn = GetClassNameA(curwnd, tempstr, strlong)
If rtn = 0 Then Exit Sub
Print "strlong " + Str(strlong)
tempstr = Trim(tempstr)
Print "GetClassName " + tempstr
'向该窗口发送一个WM_GETTEXT消息,以获得该窗口的文本,并显示在PasswordText文本框中
tempstr = Space(512)
strlong = Len(tempstr)
'Dim temp As String ptr =@tempstr
'rtn = SendMessageA(curwnd, WM_GETTEXT, strlong,temp)
tempstr = AfxGetWindowText(curwnd)
tempstr = Trim(tempstr)
Print tempstr
Text1.Text = tempstr
End If
End Sub
改动要点如下:
api函数要传指针,vfb里指针申明可以直接用@符号把非指针变量给赋值
指针属性读取是p->x 或(*p).x
另外因为单字符集A 宽字符集W问题,api默认用法不一样
鼠标指针改变设置也用法稍有不同
vfb里内置AfxGetWindowText 比 SendMessageA(curwnd, WM_GETTEXT 更好用
最后,这个应用只能用在一般地方,稍微厉害点程序人家都是自定义密码框,屏蔽掉WM_GETTEXT消息