VisualFreeBasic查看不方便复制文字的方法

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消息

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值