Re:发几个代码.VB写的!
--------------------------------- 模块部分
Attribute VB_Name = "Module1" Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 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 ReleaseCapture Lib "user32" () As Long Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long Declare Function GetActiveWindow Lib "user32" () As Long Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '窗口总在最前端 retvalue = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, 300, 300, SWP_SHOWWINDOW) Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long '具体可以使用的常量及其用法 Public Const LWA_ALPHA = &H2 '表示把窗体设置成半透明样式 Public Const LWA_COLORKEY = &H1 '表示不显示窗体中的透明色 Public Const WS_EX_LAYERED = &H80000 Public Const GWL_EXSTYLE = (-20) Public Const WM_SYSCOMMAND = &H112 Public Const SC_MOVE = &HF010 Public Const HTCAPTION = 2 Public Const WM_NCLBUTTONDOWN = &HA1 Public Const HWND_TOPMOST = -1 Public Const SWP_SHOWWINDOW = &H40 Public Const WM_CLOSE = &H10 'Closing window Public Const SW_SHOW = 5 'showing window Public Const WM_SETTEXT = &HC 'Setting text of child window Public Const WM_GETTEXT = &HD 'Getting text of child window Public Const WM_GETTEXTLENGTH = &HE Public Const EM_GETPASSWORDCHAR = &HD2 'Checking if its a password field or not Public Const BM_CLICK = &HF5 'Clicking a button Public Const SW_MAXIMIZE = 3 Public Const SW_MINIMIZE = 6 Public Const SW_HIDE = 0 Public Const SW_RESTORE = 9 Public Const WM_MDICASCADE = &H227 'Cascading windows Public Const MDITILE_HORIZONTAL = &H1 Public Const MDITILE_SKIPDISABLED = &H2 Public Const WM_MDITILE = &H226 '窗口半透明 'rtn = GetWindowLong(Me.hwnd, GWL_EXSTYLE) '取的窗口原先的样式 'rtn = rtn Or WS_EX_LAYERED '使窗体添加上新的样式WS_EX_LAYERED 'SetWindowLong Me.hwnd, GWL_EXSTYLE, rtn '把新的样式赋给窗体 'SetLayeredWindowAttributes Me.hwnd, 0, 192, LWA_ALPHA '把窗体设置成半透明样式,第二个参数表示透明程度 '取值范围0--255,为0时就是一个全透明的窗体了 Public Type POINTAPI x As Long y As Long End Type Attribute VB_Name = "Module2" Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long Public Const WM_HOTKEY = &H312 '消息标志常量 代表热键激活消息 Public Const MOD_ALT = &H1 'ALT标志 Public Const MOD_CONTROL = &H2 'Ctrl标志 Public Const MOD_SHIFT = &H4 'Shift标志 Public Const GWL_WNDPROC = (-4) '窗体函数地址标志 Public preWinProc As Long '原来的窗体函数地址 Public Modifiers As Long, uVirtKey As Long, idHotKey As Long ' 功能键状态 热键 Public GameWindow As Long Private Type taLong '定义类型 ll As Long End Type Private Type t2Int lWord As Integer hword As Integer End Type Public Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If Msg = WM_HOTKEY Then '如果是热键激活消息 If wParam = idHotKey Then '是指定的热键ID Dim lp As taLong, i2 As t2Int lp.ll = lParam '取参数消息 LSet i2 = lp If (i2.lWord = Modifiers) And i2.hword = uVirtKey Then '是所定义的热键被激活 If GameWindow > 0 Then If IsWindowVisible(frmMain.hwnd) Then frmMain.Show Else frmMain.Show 'SetWindowPos GameWindow, 0, 0, 0, Int(frmGame.Width / 15), Int(frmGame.Height / 15), &H20 End If ShowWindow frmMain.hwnd, SW_MINIMIZE frmMain.Show End If 'Shell "notepad", vbNormalFocus End If End If Else '将之送往原来的Window Procedure wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam) '不是本热键激活消息就送回到原窗口函数处理 End If End Function
|