KeepMove.bas
上传用户:albinfu
上传日期:2021-08-24
资源大小:71k
文件大小:2k
- Attribute VB_Name = "KeepMove"
- Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
- Public Const WM_WINDOWPOSCHANGING = &H46
- Type WINDOWPOS
- hwnd As Long
- hWndInsertAfter As Long
- X As Long
- Y As Long
- cx As Long
- cy As Long
- flags As Long
- End Type
- Public PreWindProc2 As Long, MuLimit As Boolean
- '===========拦截窗口重定位消息===============
- Public Function WndProc2(ByVal hwnd As Long, ByVal Msg As Long, ByVal _
- wParam As Long, ByVal lParam As Long) As Long
- If MuLimit = True Then
- If Msg = WM_WINDOWPOSCHANGING Then
- Dim WPOS As WINDOWPOS
- CopyMemory WPOS, ByVal lParam, Len(WPOS)
- If WPOS.X < 0 Then
- Form1.Label1.Caption = Now & " 移动窗口范围超出左侧屏幕,已拦截操作。"
- DoEvents
- WPOS.X = 0
- CopyMemory ByVal lParam, WPOS, Len(WPOS)
- ElseIf WPOS.Y < 0 Then
- Form1.Label1.Caption = Now & " 移动窗口范围超出屏幕上限,已拦截操作。"
- DoEvents
- WPOS.Y = 0
- CopyMemory ByVal lParam, WPOS, Len(WPOS)
- ElseIf WPOS.X > Screen.Width / 15 - Form1.Width / 15 Then
- Form1.Label1.Caption = Now & " 移动窗口范围超出右侧屏幕,已拦截操作。"
- DoEvents
- WPOS.X = Screen.Width / 15 - Form1.Width / 15
- CopyMemory ByVal lParam, WPOS, Len(WPOS)
- ElseIf WPOS.Y > Screen.Height / 15 - Form1.Height / 15 Then
- Form1.Label1.Caption = Now & " 移动窗口范围超出屏幕下限,已拦截操作。"
- DoEvents
- WPOS.Y = Screen.Height / 15 - Form1.Height / 15
- CopyMemory ByVal lParam, WPOS, Len(WPOS)
- End If
- End If
- End If
- WndProc2 = CallWindowProc(PreWindProc2, hwnd, Msg, wParam, lParam)
- End Function