- 帖子
- 79
- 积分
- 441
- 威望
- 331
- 金钱
- 275
- 在线时间
- 108 小时
|
10楼
发表于 2008-6-17 14:18
| 只看该作者
好!我发源码给大家看看!!
窗口代码- Option Explicit
- Dim IsDragging As Boolean
- Private Sub SetOnTop(ByVal IsOnTop As Integer)
- Dim rtn As Long
- If IsOnTop = 1 Then
- '将窗口置于最上面
- rtn = SetWindowPos(frmMain.hwnd, -1, 0, 0, 0, 0, 3)
- Else
- rtn = SetWindowPos(frmMain.hwnd, -2, 0, 0, 0, 0, 3)
- End If
- End Sub
- Private Sub Check1_Click()
- SetOnTop (Check1.Value)
- End Sub
- Private Sub Form_Load()
- Check1.Value = 1
- SetOnTop (Check1.Value)
- IsDragging = False
- End Sub
- 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
- Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
- If IsDragging = True Then
- Screen.MousePointer = vbDefault
- IsDragging = False
- '释放鼠标消息抓取
- ReleaseCapture
- End If
- End Sub
- Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
- If IsDragging = False Then
- IsDragging = True
- Screen.MouseIcon = LoadPicture(App.Path + "\pass.ico")
- Screen.MousePointer = vbCustom
- '将以后的鼠标输入消息都发送到本程序窗口
- SetCapture (frmMain.hwnd)
- End If
-
- End Sub
复制代码 模板代码- Option Explicit
- Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
- Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
- Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
- Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
- Declare Function GetLastError Lib "kernel32" () As Long
- Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
- Declare Function ReleaseCapture Lib "user32" () As Long
- Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
- Public Const WM_GETTEXT = &HD
- Type POINTAPI
- x As Long
- y As Long
- End Type
复制代码 |
|