Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Create components using mix CE Lua script and win API.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Fri Aug 19, 2022 8:08 pm    Post subject: Create components using mix CE Lua script and win API. Reply with quote

So, I try write script to make form (using CE Lua) and controls (Buttons using win API). But, I can't provide the correct way to make buttons click handler for the buttons created using 'createWindowEx'.
How to write CE Lua code to handle buttons click under function or procedure?.

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

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

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

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

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

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

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

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

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

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

function CallWindowProcW(wndproc, hWnd, Msg, wParam, lParam)
  return executeCodeLocalEx("user32.CallWindowProcW", wndproc, hWnd, Msg, wParam, 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()

local happy = 'f:\\happy.bmp'
local sad = 'f:\\sad.bmp'
local hButton1, hButton2
--local hInstance = GetModuleHandle(nil)

-- Create Happy Button
hButton1 = CreateWindow(0, "Button", "Happy",  f.Handle, WS_VISIBLE + WS_BORDER + WS_CHILD | BS_TEXT | BS_BOTTOM,
                        10, 10, 100, 50, 10000, hInstance, 0)
hBitmap1 = LoadImage(hInstance, happy, IMAGE_BITMAP, 30, 30, LR_LOADFROMFILE | LR_DEFAULTCOLOR)
_SendMessage(hButton1, BM_SETIMAGE, IMAGE_BITMAP, hBitmap)

-- Create Sad Button
hInstance2 = GetModuleHandle(nil)
hButton2 = CreateWindow(0, "Button", "Sad",  f.Handle, WS_VISIBLE + WS_BORDER + WS_CHILD | BS_TEXT | BS_TOP,
                        120, 10, 100, 50, 0, hInstance2, 0)
hBitmap2 = LoadImage(hInstance2, sad, IMAGE_BITMAP, 25, 25, LR_LOADFROMFILE | LR_DEFAULTCOLOR)
_SendMessage(hButton2, BM_SETIMAGE, IMAGE_BITMAP, hBitmap2)



Button click event (NOT FINISH)

Code:
--- THREAD
--- HOW TO HANDLE THIS PART FOR BUTTON CLICK
function WindProc(hwnd, wMsg, wParam, lParam)
 if wMsg == WM_LBUTTONUP then
   if lParam == hButton1 then
      showMessage("Button was clicked!")
  end
  --WindProc = CallWindowProc(WndProcOld, hwnd, wMsg, wParam, lParam)
 end
end

-- THIS PART DOESN'T WORK
function hButton1Click()
 showMessage('You ate happy')
end

--hButton1.onClick = hButton1Click
--


I forgot this, same thread anyway:
https://www.cheatengine.org/forum/viewtopic.php?t=615443&sid=1b04415607e410b7d6e3b107629c20f9



Capture.JPG
 Description:
 Filesize:  18.22 KB
 Viewed:  1289 Time(s)

Capture.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Sat Aug 20, 2022 1:44 am    Post subject: Reply with quote

use a peekMessage loop
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Sat Aug 20, 2022 5:56 am    Post subject: Reply with quote

I will only give an idea that focuses on the result; I think of the effects function that customizes a "Panel". It will give the same result.

Because your project is a "Tutorial", I postpone my proposal.



Note: I can't be at my pc for 3 weeks and I can't test your code because I'm just following on the phone. I hope you get results.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sat Aug 20, 2022 10:23 pm    Post subject: Reply with quote

NVM, this is more easier using CE 7.4 Lua script

Code:
function createSpeedButton(Parent)
local b = createComponentClass('TSpeedButton', Parent)
 b.Parent = Parent
 return b
end

if f then f.destroy() end
f = createForm()
f.setSize(300,100)
f.Caption = 'Speed Button'

bmap = createImage(self)
bmap.Height = 24
bmap.Width = 24
bmap.Picture.loadFromStream(findTableFile('ok.png').Stream)
bmp = bmap.Picture.Bitmap

bBtn = createSpeedButton(f)
bBtn.Left = 40
bBtn.Top = 10
bBtn.Width = 100
bBtn.Height = 40
bBtn.Caption = 'Go'
bBtn.CanShowGlyph = true
bBtn.Glyph = bmp

function Button1Click(sender);
  showMessage('Go...Clicked !!')
end;

f.show()
bBtn.onClick = Button1Click



Capture.JPG
 Description:
 Filesize:  13.4 KB
 Viewed:  1205 Time(s)

Capture.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Sun Aug 21, 2022 4:21 am    Post subject: Reply with quote

I think you can draw the control box @DB mentioned in the same way, give it a textOut (by putting a long and full box and a square empty box on top of it) and configure a table that creates its functions.

It could be something too complicated with the checkmark. Shocked


I still find "setWindowTheme" my favourite. Very Happy

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sun Aug 21, 2022 5:37 am    Post subject: Reply with quote

AylinCE wrote:
I think you can draw the control box @DB mentioned in the same way, ......


Sure, that is another alternative for the component visual style.
I am just learn how to improve winapi in CE Lua scripts which more easier in C# / C++. Very Happy

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1253

PostPosted: Sun Aug 21, 2022 10:50 am    Post subject: Reply with quote

Your ideas and solutions are always helpful.

Ok, hope you get a result.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites