找回密码
 加入
搜索
查看: 1853|回复: 4

[求助] 高手帮忙优化挂机锁代码

[复制链接]
发表于 2009-1-9 07:52:52 | 显示全部楼层 |阅读模式
这是我修改的别人的代码  可以行得通 但发现CPU使用效率时高时低
由于有些代码还没详细懂 不敢乱删  求高手优化一下 (压缩包里的 1。AU3 )
#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Date.au3>
;~ ;;=====================================================================================================
Const $WM = 0x114
Const $TB_LINEUP                 = 0
Const $TB_LINEDOWN               = 1
Const $TB_PAGEUP                 = 2
Const $TB_PAGEDOWN               = 3
Const $TB_THUMBPOSITION          = 4
Const $TB_THUMBTRACK             = 5
Const $WM_AUTOITLBUTTONDOWN = 0x1400 + 0x0A30
Const $WM_AUTOITRBUTTONDOWN = 0x1400 + 0x0A31
Const $WM_AUTOITMBUTTONDOWN = 0x1400 + 0x0A32
Const $WM_AUTOITMOUSEWHEELUP = 0x1400 + 0x0D30
Const $HCBT_SETFOCUS = 0x1400 + 0x1A30
Const $HCBT_ACTIVATE = 0x1400 + 0x1A31
Const $HCBT_CREATEWND = 0x1400 + 0x1A32
Const $HCBT_DESTROYWND = 0x1400 + 0x1A33
Const $HCBT_MINMAX = 0x1400 + 0x1A34
Const $WM_KEYDOWN1 = 0x0400 + 0x0A30

FileInstall("hook.dll", @TempDir & "\hook.dll", 1)
FileInstall("bg.jpg", @TempDir & "\bg.jpg", 1)
;==================================================
Opt("MouseCoordMode", 0)
Opt("TrayIconHide", 1)
Send("#m")
$bg_form=GUICreate("背景", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))

If FileExists(@ScriptDir & "\bg.jpg") Then
        $pic1 = GUICtrlCreatePic(@ScriptDir & "\bg.jpg", 0,0,@DesktopWidth ,@DesktopHeight)
Else
        $pic1 = GUICtrlCreatePic(@TempDir & "\bg.jpg", (@DesktopWidth - 400) / 2, (@DesktopHeight - 300) / 2, 400, 300)
EndIf
GUICtrlSetState(-1, $gui_disable)
GUISetState(@SW_SHOW)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("本机己锁定!", 258, 95, @DesktopWidth / 2 - 129, @DesktopHeight / 2 - 52, BitOR($WS_SYSMENU, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER))
$Slider_1 = GuiCtrlCreateSlider(8, 48,250, 60)
GUICtrlSetLimit ($Slider_1,255)
GUICtrlSetData($Slider_1, 255)
GUIRegisterMsg($WM, "MY_WM_HSCROLL")
$mm=IniDelete ( '1.ini', "mm" ,"mm")
$Label1 = GUICtrlCreateLabel("本机已锁定,请输入解锁密码:",10, 8, 200, 20)
GUICtrlSetState(-1, $gui_disable)
$Input1 = GUICtrlCreateInput("", 16, 28, 145, 21, $ES_PASSWORD)
GUICtrlSetLimit(-1, 18)
$Button1 = GUICtrlCreateButton("解锁", 184, 25, 57, 25, 0)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
#EndRegion ### START Koda GUI section ### Form=
WinSetOnTop("本机己锁定", "", 1)
GUISetState(@SW_SHOW)
HotKeySet("!","jiesu")
;;===============================================================
Global $DLLinst = DllCall("kernel32.dll", "hwnd", "LoadLibrary", "str", @TempDir & "\hook.dll")
Global $mouseHOOKproc = DLLCall("kernel32.dll","hwnd","GetProcAddress","hwnd",$DLLInst[0],"str","MouseProc")
Global $keyHOOKproc = DLLCall("kernel32.dll","hwnd","GetProcAddress","hwnd",$DLLInst[0],"str","KeyProc")
Global $cbtHOOKproc = DllCall("kernel32.dll", "hwnd", "GetProcAddress", "hwnd", $DLLinst[0], "str", "CBTProc")

Global $hhMouse = DLLCall("user32.dll","hwnd","SetWindowsHookEx","int",$WH_MOUSE, _
        "hwnd",$mouseHOOKproc[0],"hwnd",$DLLinst[0],"int",0)
Global $hhKey = DLLCall("user32.dll","hwnd","SetWindowsHookEx","int",$WH_KEYBOARD, _
        "hwnd",$keyHOOKproc[0],"hwnd",$DLLinst[0],"int",0)
Global $hhCBT = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_CBT, _
                "hwnd", $cbtHOOKproc[0], "hwnd", $DLLinst[0], "int", 0)

DLLCall(@TempDir&"\hook.dll","int","SetValuesMouse","hwnd",$Form1,"hwnd",$hhMouse[0])
DLLCall(@TempDir&"\hook.dll","int","SetValuesKey","hwnd",$Form1,"hwnd",$hhKey[0])
DllCall(@TempDir & "\hook.dll", "int", "SetValuesCBT", "hwnd", $Form1, "hwnd", $hhCBT[0])
GUIRegisterMsg($WM_AUTOITLBUTTONDOWN,"myfunc")
GUIRegisterMsg($WM_AUTOITRBUTTONDOWN,"myfunc")
GUIRegisterMsg($WM_AUTOITMOUSEWHEELUP,"myfunc")
GUIRegisterMsg($HCBT_ACTIVATE, "myCBTfunc")
GUIRegisterMsg($WM_KEYDOWN1,"myfunc")
HotKeySet("!f","jiesu")
;;;===================================================================================================================
While 1
        HotKeySet("F3","jiesu")
        if win_show("本机己锁定!") Then 
$coords = WinGetPos($Form1)
        _MouseTrap($coords[0], $coords[1], $coords[0] + $coords[2], $coords[1] + $coords[3])
        ;屏蔽鼠标
                If Not WinActive("本机己锁定") Then WinActivate("本机己锁定")
        EndIf
                
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $Button1
                        _isok()
                        
                EndSwitch
                WEnd


Func _isok()
        $psw = GUICtrlRead($Input1)
        If $psw = $mm Then
                _MouseTrap()
                _GUICtrlStatusBar_SetText($StatusBar1, "密码正确,解除锁定!")
                DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 300, "long", 0x00050010)
                Send("#+m")
                myexit()
        Else
                _GUICtrlStatusBar_SetText($StatusBar1, "密码错误!")
                GUICtrlSetData($Input1, "")
                ControlFocus("本机己锁定", "", $Input1)
        EndIf
        
EndFunc   ;==>_isok

Func movewin()
        If TimerDiff($timer1) >= 15000 And GUICtrlRead($Input1) = "" Then
                WinMove("本机己锁定", "", Random(0, Round(@DesktopWidth - 258), 1), Random(0, Round(@DesktopHeight - 95), 1))
                $timer1 = TimerInit()
        EndIf
EndFunc   ;==>movewin

Func MyCBTFunc($hWndGUI, $MsgID, $WParam, $LParam)
        If $LParam = 0x0007f578 Then WinClose($WParam);~          ToolTip($LParam)
EndFunc   ;==>MyCBTFunc

Func MyFunc($hWndGUI, $MsgID, $WParam, $LParam)
        $timer3=TimerInit()
        if win_show("本机己锁定!") Then
        Return
Else
        GUISetState(@SW_SHOW,$Form1)
EndIf
        
EndFunc


Func win_show($x)
    Return BitAND(WinGetState($x),2)
EndFunc
Func jiesu()
                _MouseTrap()
                _GUICtrlStatusBar_SetText($StatusBar1, "密码正确,解除锁定!")
                DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 300, "long", 0x00050010)
                Send("#+m")
                myexit()
        EndFunc
        Func MY_WM_HSCROLL($hWnd, $msg, $wParam, $lParam)
    $nScrollCode      = BitAnd($wParam, 0x0000FFFF)
    $nPos           = BitShift($wParam, 16)
    $hwndScrollBar    = $lParam
    Switch $nScrollCode
        Case $TB_LINEDOWN ,$TB_LINEUP,$TB_PAGEDOWN,$TB_PAGEUP,$TB_THUMBTRACK
            WinSetTrans ($bg_form,"",GUICtrlRead($Slider_1))
    EndSwitch
EndFunc
Func myexit()
        FileDelete(@TempDir & "\hook.dll")
        FileDelete(@TempDir & "\bg.jpg")
        DLLCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hhMouse[0])
    DLLCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hhKey[0])
    DLLCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hhCBT[0])
    DLLCall("kernel32.dll","int","FreeLibrary","hwnd",$DLLinst[0])
        Exit
EndFunc   ;==>myexit


[ 本帖最后由 askask150 于 2009-1-12 01:04 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2009-1-9 12:29:42 | 显示全部楼层
有空再研究下哦
发表于 2009-1-9 17:13:54 | 显示全部楼层
While 1
    HotKeySet("F3","jiesu") ;不知道你为什么要把,这个函数放在这里,而不放在文件的开头。
    if win_show("本机己锁定!") Then
$coords = WinGetPos($Form1)
    _MouseTrap($coords[0], $coords[1], $coords[0] + $coords[2], $coords[1] + $coords[3])
    ;屏蔽鼠标
        If Not WinActive("本机己锁定") Then WinActivate("本机己锁定")
    EndIf
        
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            _isok()
            
        EndSwitch
sleep(100) ;在这里加个延迟应该能降低CPU的使用率.
        WEnd
 楼主| 发表于 2009-1-12 01:04:10 | 显示全部楼层
哦   谢谢楼上的大哥   
HotKeySet("F3","jiesu") ; ----这个后来我放在前面了  但我忘了更新这个了
发表于 2017-6-22 11:37:24 | 显示全部楼层
yes!怎么样,过得去吧!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-24 21:14 , Processed in 0.073344 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表