如何把图存在单Au3脚本里?并且还可以响应事件
把图存在AU3脚本里论坛里有,但是如何把图存在Au3脚本里,同时还可以响应事件?如附件,这里编写了一个可以通过上下左右方向键移动图片的脚本,不想带着jpg图片了,想保存在Au3脚本的二进制数里(这个论坛里有例子了),存在Au3脚本里如何还能响应键盘事件,从而改变图片的位置?
整个工程见附件
代码如下:#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <WinAPI.au3>
Global $hHook, $hStub_KeyProc
Global $g_iPlaneLeft = 200
Global $g_iPlaneTop = 200
Global $g_iSpeed = 2
#Region ### START Koda GUI section ### Form=D:\prj\Au3\koda_1.7.3.0\Forms\mb\GameMan30.kxf
$frmMain = GUICreate("方向键移动飞机的位置", 400, 300, 192, 124)
GUISetBkColor(0x000000)
$pic_Plane = GUICtrlCreatePic("Plane.JPG", $g_iPlaneLeft, $g_iPlaneTop, 14, 13)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
OnAutoItExitRegister("Cleanup")
$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case Else
;
EndSwitch
; 刷新Plane位置
GUICtrlSetPos($pic_Plane, $g_iPlaneLeft, $g_iPlaneTop)
;Sleep(10)
WEnd
; ===========================================================
; 按键分支 Up Down Left Right方向键
; ===========================================================
Func EvaluateKey($keycode)
If ($keycode = 27) Then ; esc key
Exit
ElseIf ($keycode = 0x25) Then ; Left key
$g_iPlaneLeft = $g_iPlaneLeft - $g_iSpeed
;ConsoleWrite("Left" & @CRLF)
ElseIf ($keycode = 0x26) Then ; Up key
$g_iPlaneTop = $g_iPlaneTop - $g_iSpeed
;ConsoleWrite("Up" & @CRLF)
ElseIf ($keycode = 0x27) Then ; Right key
$g_iPlaneLeft = $g_iPlaneLeft + $g_iSpeed
;ConsoleWrite("Right" & @CRLF)
ElseIf ($keycode = 0x28) Then ; LEFT key
$g_iPlaneTop = $g_iPlaneTop + $g_iSpeed
;ConsoleWrite("Down" & @CRLF)
Else
;
EndIf
EndFunc ;==>EvaluateKey
; ===========================================================
; 回调函数
; ===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
Local $tKEYHOOKS
$tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
If $nCode < 0 Then
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndIf
;---> 如果是KeyDown事件 ($WM_KEYDOWN = 256,$WM_KEYUP = 257)
If $wParam = $WM_KEYDOWN Then
EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
EndIf
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc ;==>_KeyProc
Func Cleanup()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub_KeyProc)
EndFunc ;==>Cleanup 转成二进制,在程序运行时先释放到指定路径然后调用 回复 2# zldfsz
有能直接在内存里运行的方法吗? 回复 3# mbdnmt
http://www.autoitx.com/forum.php?mod=viewthread&tid=36747 #Include <WinAPIEx.au3>
_WinAPI_CreateStreamOnHGlobal 回复 5# netegg
蛋蛋是不是回错页面了 回复 6# zldfsz
没有啊,把图像转成二进制数据,然后加载呀
页:
[1]