在CE Lua中使用WINAPI创建的对象上单击事件

问题描述

我进行了测试,并且能够使用Cheat Engine Lua脚本+ winapi使带有图标的按钮成为可能。 但是我找不到如何处理使用winapi创建的按钮的事件。 下面是我通过作弊引擎Lua脚本使用的代码,包括使用“ executeCodeLocal”调用的winapi函数:

Buttons created using winapi + Lua

function GetModuleHandle(lpModuleName)
 return executeCodeLocal("kernel32.GetModuleHandleA",lpModuleName)
end

function CreateWindow(oControl,oClass,oName,oHwnd,oDWStyle,nleft,ntop,nwidth,nheight)
 return executeCodeLocalEx("user32.CreateWindowExA",nheight,0)
end

function LoadIcon(hInstance,lpIconName)
 return executeCodeLocalEx("user32.LoadIconA",lpIconName)
end

function _SendMessage(hWnd,Msg,wParam,lParam)
  return executeCodeLocalEx("user32.SendMessageA",hWnd,lParam)
end

function LoadImage(hInst,lpszName,uType,cxDesired,cyDesired,fuLoad)
  return executeCodeLocalEx("user32.LoadImageA",hInst,fuLoad)
end

function SetWindowLong(hWnd,nIndex,dwNewLong)
 return executeCodeLocalEx("user32.SetWindowLongPtrA",dwNewLong)
end

function GetWindowLong(prmlngWindowHandle,prmlngIndex)
  return executeCodeLocalEx("user32.GetWindowLongA",prmlngWindowHandle,prmlngIndex)
end

function CallWindowProc(hWnd,lParam)
 return executeCodeLocalEx("user32.CallWindowProcA",lpPrevWndFunc,lParam)
end

function RegisterClass(lpwcx)
  return executeCodeLocalEx("user32.RegisterClassW",lpwcx)
end

function SetWindowLongW(hWnd,dwCallBack)
 return executeCodeLocalEx("user32.SetWindowLongW",dwCallBack)
end

function CallWindowProcW(wndproc,lParam)
  return executeCodeLocalEx("user32.CallWindowProcW",wndproc,lParam)
end

--Window Style
WS_VISIBLE       = 0x10000000
WS_BORDER        = 0x00800000
WS_CHILD         = 0x40000000

-- Window Message
WM_LBUTTONUP = 0x0202
WM_LBUTTONDOWN = 0x020
WM_COMMAND = 0x111

-- Button Style
BS_TEXT          = 0x00000000
BS_BOTTOM        = 0x00000800
BS_TOP           = 0x00000400
BS_LEFT          = 0x00000100
BS_RIGHT         = 0x00000200
BM_SETIMAGE      = 0xF7
BS_BITMAP        = 0x00000080
BS_DEFPUSHBUTTON = 0x00000001

GWL_WNDPROC      = -4
IMAGE_BITMAP = 0
IMAGE_ICON = 1
LR_LOADFROMFILE = 16
LR_DEFAULTCOLOR = 0x00000000
LR_CREATEDIBSECTION = 8192
LR_DEFAULTSIZE = 64
--------------------------------------------------------------------------------

if f then f.destroy() end
f = createForm()
f.Height = 70
f.Width = 230
f.Position = 'poScreenCenter'
f.Caption = 'Test Winapi'
f.Show()

open = 'd:\\open.bmp'
save = 'd:\\save.bmp'

-- Create Open Button
hInstance = GetModuleHandle(nil)
hButton = CreateWindow(0,"Button","Open",f.Handle,WS_VISIBLE + WS_BORDER + WS_CHILD | BS_TEXT | BS_BOTTOM,10,100,50,10000,hInstance,0)
hBitmap = LoadImage(hInstance,open,IMAGE_BITMAP,30,LR_LOADFROMFILE | LR_DEFAULTCOLOR)
_SendMessage(hButton,BM_SETIMAGE,hBitmap)

-- Create Save Button
hInstance2 = GetModuleHandle(nil)
hButton2 = CreateWindow(0,"Save",WS_VISIBLE + WS_BORDER + WS_CHILD | BS_TEXT | BS_TOP,120,hInstance2,0)
hBitmap2 = LoadImage(hInstance2,save,25,LR_LOADFROMFILE | LR_DEFAULTCOLOR)
_SendMessage(hButton2,hBitmap2)

但是,如何处理创建的按钮上的click事件? 如果我在使用,例如:

function hButton_onClick()
 showMessage('Button open has clicked')
end

hButton.OnClick = hButton_onClick

函数返回错误,因为hButton为nil值。 该如何解决?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...