Option Explicit
''''''''''''''移动窗体
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
''''''''''''''获取活动窗口句柄
Private Declare Function GetForegroundWindow Lib "user32" () As Long
''''''''''''''判断按键是否按下
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
''''''''''''''获取窗体标题
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
''''''''''''''半透明
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Dim intGetWindowHWnd As Long
Dim myWidth, myHeight As Long
Dim getWidth As Long
Dim getHeight As Long
Private Sub Command1_Click()
MsgBox "123"
End Sub
Private Sub Form_Load()
On Error Resume Next
Dim ExsTyle As Long, crKey As Long, bAlpha As Byte, dwFlags As Long
ExsTyle = GetWindowLong(hwnd, GWL_EXSTYLE)
ExsTyle = ExsTyle Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, ExsTyle
dwFlags = 2
bAlpha = 125
SetLayeredWindowAttributes hwnd, 0, bAlpha, dwFlags
Me.BackColor = vbBlue
myWidth = Width: myHeight = Height
End Sub
Private Sub Form_MouseDown(button As Integer, Shift As Integer, x As Single, y As Single)
On Error Resume Next
If button = 2 Then
Call FormMove(intGetWindowHWnd, getWidth, getHeight, x, y)
’========================================================
Call FormMove(intGetWindowHWnd, getWidth, getHeight, x, y)
‘问题在这里,上句中的intGetWindowHWnd,getWidth, getHeight,各是什么值?
’========================================================
End If
End Sub
Private Sub Form_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
If button = 2 Then
If FormMove(intGetWindowHWnd, getWidth, getHeight, x, y) Then
Cls
Me.ForeColor = vbRed
Print: Print "移动窗体成功!你可以继续以下操作"
End If
End If
End Sub
Private Function FormMove(hwnd As Long, gWidth As Long, gHeight As Long, x As Single, y As Single)
Dim aLeft, aTop, aWidth, aHeight As Long
On Error Resume Next
aLeft = (Screen.Width / Width * x) / Screen.TwipsPerPixelX
aTop = (Screen.Height / Height * y) / Screen.TwipsPerPixelY
aWidth = gWidth / Screen.TwipsPerPixelX
aHeight = gHeight / Screen.TwipsPerPixelY
FormMove = MoveWindow(hwnd, aLeft, aTop, aWidth, aHeight, True)
End Function
''''''''''''''移动窗体
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
''''''''''''''获取活动窗口句柄
Private Declare Function GetForegroundWindow Lib "user32" () As Long
''''''''''''''判断按键是否按下
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
''''''''''''''获取窗体标题
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
''''''''''''''半透明
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Dim intGetWindowHWnd As Long
Dim myWidth, myHeight As Long
Dim getWidth As Long
Dim getHeight As Long
Private Sub Command1_Click()
MsgBox "123"
End Sub
Private Sub Form_Load()
On Error Resume Next
Dim ExsTyle As Long, crKey As Long, bAlpha As Byte, dwFlags As Long
ExsTyle = GetWindowLong(hwnd, GWL_EXSTYLE)
ExsTyle = ExsTyle Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, ExsTyle
dwFlags = 2
bAlpha = 125
SetLayeredWindowAttributes hwnd, 0, bAlpha, dwFlags
Me.BackColor = vbBlue
myWidth = Width: myHeight = Height
End Sub
Private Sub Form_MouseDown(button As Integer, Shift As Integer, x As Single, y As Single)
On Error Resume Next
If button = 2 Then
Call FormMove(intGetWindowHWnd, getWidth, getHeight, x, y)
’========================================================
Call FormMove(intGetWindowHWnd, getWidth, getHeight, x, y)
‘问题在这里,上句中的intGetWindowHWnd,getWidth, getHeight,各是什么值?
’========================================================
End If
End Sub
Private Sub Form_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
If button = 2 Then
If FormMove(intGetWindowHWnd, getWidth, getHeight, x, y) Then
Cls
Me.ForeColor = vbRed
Print: Print "移动窗体成功!你可以继续以下操作"
End If
End If
End Sub
Private Function FormMove(hwnd As Long, gWidth As Long, gHeight As Long, x As Single, y As Single)
Dim aLeft, aTop, aWidth, aHeight As Long
On Error Resume Next
aLeft = (Screen.Width / Width * x) / Screen.TwipsPerPixelX
aTop = (Screen.Height / Height * y) / Screen.TwipsPerPixelY
aWidth = gWidth / Screen.TwipsPerPixelX
aHeight = gHeight / Screen.TwipsPerPixelY
FormMove = MoveWindow(hwnd, aLeft, aTop, aWidth, aHeight, True)
End Function