CF 准星 如何实现窗口化--白色鼠标一直跟着准星无法游戏
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private 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
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)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Const HWND_TOP = 0
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Dim rtn As Long
Dim X0 As Long
Dim Y0 As Long
Private Sub Form_Load()
Form2.Show
Me.AutoRedraw = True
Me.BackColor = vbBlack
Me.ForeColor = vbRed
Me.Line (Me.ScaleWidth / 2 - 50, Me.ScaleHeight / 2)-(Me.ScaleWidth / 2 + 50, Me.ScaleHeight / 2)
Me.Line (Me.ScaleWidth / 2, Me.ScaleHeight / 2 - 50)-(Me.ScaleWidth / 2, Me.ScaleHeight / 2 + 50)
rtn = GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes Me.hwnd, vbBlack, 180, LWA_COLORKEY Or LWA_ALPHA
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
X0 = Screen.Width
Y0 = Screen.Height
X0 = (X0 - Me.Width) / 2
Y0 = (Y0 - Me.Height) / 2
Me.Move X0, Y0
End Sub
Private Sub Form_Resize() '设置窗体出现在屏幕中央
'让窗体居中
X0 = Screen.Width
Y0 = Screen.Height
X0 = (X0 - Me.Width) / 2
Y0 = (Y0 - Me.Height) / 2
Me.Move X0, Y0
End Sub
Private Sub Timer1_Timer()
If MyHotKey(vbKeyF8) Then
Unload Me
Load Me
Me.Show
Load Me
Me.Move X0 - 10, Y0 - 10
End If
If MyHotKey(vbKeyF9) Then
Me.Hide
End If
If MyHotKey(vbKeyF10) Then Unload Me
End Sub
================模块====================
Public Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vkey As Long) As Integer
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Function MyHotKey(vKeyCode) As Boolean
MyHotKey = (GetAsyncKeyState(vKeyCode) < 0)
End Function