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 


Changing the color of checkboxes

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Pitronic
How do I cheat?
Reputation: 0

Joined: 11 Aug 2022
Posts: 2

PostPosted: Thu Aug 11, 2022 2:01 pm    Post subject: Changing the color of checkboxes Reply with quote

I have a question. When creating a form on UDF1 with checkboxes. What can be added to lua so that the checkbox changes colors if the checkbox is checked, the checkbox color is red, and if not, the checkbox color is black by default, so that the activation deactivation functions look more beautiful.
Back to top
View user's profile Send private message Send e-mail
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Fri Aug 12, 2022 3:06 am    Post subject: Reply with quote

checkboxes can't have a custom color (it's determined by the windows theme)

but if you really need it you can always draw a checkbox yourself. e.g a paintbox that responds to clicks so you can update the state on clicks

_________________
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: 30

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Fri Aug 12, 2022 11:02 am    Post subject: Reply with quote

Simple idea. You can add color to it.

Note: I used the Checkbox "Click" event in the effect. Reusing the Click event outside.

I'm releasing the "Change" thing to the outside and you.

Code:
function chkbox_effect(chk,lbl,clr1,clr2,text1,text2)
 chk.AutoSize=false
 chk.Caption=""
 chk.Checked=false
 lbl.Left=chk.Left + 15
 lbl.Top=chk.Top + 1
 lbl.Font.Color = clr1
 lbl.Font.Style="fsBold"
 lbl.Font.Size=12
 lbl.caption=text1
 chk.Height=lbl.Height + 4
 chk.Width=lbl.Width + 15
 --lbl.Color=0xffffff

 chk.OnClick=function()
  if chk.Checked==true then
    lbl.Font.Color = clr2
    lbl.caption=text2
  else
   lbl.Font.Color = clr1
   lbl.caption=text1
  end
 end
end

if frm1 then frm1.Destroy() frm1=nil end
 frm1 = createForm()

 ChkBox1 = createCheckBox(frm1) ChkBox1.AutoSize=false
 ChkBox1.Left = 30 ChkBox1.Top = 30
 ChkBox2 = createCheckBox(frm1) ChkBox2.AutoSize=false
 ChkBox2.Left = 30 ChkBox2.Top = 55

 Lbl1 = createLabel(frm1)
 Lbl2 = createLabel(frm1)

chkbox_effect(ChkBox1,Lbl1,0x000000,0x0000ff,"Hack Deactive","Hack Active")
chkbox_effect(ChkBox2,Lbl2,0x000000,0x0000ff,"Hack Deactive","Hack Active")

ChkBox1.OnChange=function()
 if ChkBox1.Checked==true then
   print("Hack 1 Active!")
 else
   print("Hack 1 DeActive!")
 end
end

ChkBox2.OnChange=function()
 if ChkBox2.Checked==true then
   print("Hack 2 Active!")
 else
   print("Hack 2 DeActive!")
 end
end

-- use UDF1 or your Trainer Name and control name ..
--chkbox_effect(UDF1.CECheckbox1,UDF1_CELabel1,0x000000,0x0000ff,"Hack Deactive","Hack Active")
--chkbox_effect(UDF1.CECheckbox2,UDF1_CELabel2,0x000000,0x0000ff,"Hack Deactive","Hack Active")

_________________
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 13, 2022 9:28 pm    Post subject: This post has 1 review(s) Reply with quote

Or like this

Code:
local red=858083
local green=32768

if f then f.destroy() end

f=createForm()

chk1=createCheckBox(f)
chk1.font.size=14
chk1.left = 30
chk1.top = 30
chk1.caption='This is OFF'
executeCodeLocalEx('uxtheme.SetWindowTheme', chk1.handle, "", "")
chk1.font.color = red

chk2=createCheckBox(f)
chk2.font.size=14
chk2.left = 30
chk2.top = 70
chk2.caption='This is OFF'
executeCodeLocalEx('uxtheme.SetWindowTheme', chk2.handle, "", "")
chk2.color = red
chk2.font.color=0xffffff

function chk1_tickChange()
 if chk1.Checked == true then
    chk1.caption='This is ON'
    chk1.font.color=green
 else
    chk1.caption='This is OFF'
    chk1.font.color=red
 end
end

function chk2_tickChange()
 if chk2.Checked == true then
    chk2.caption='This is ON'
    chk2.color = green
    chk2.font.color=0xffffff
 else
    chk2.caption='This is OFF'
    chk2.color = red
    chk2.font.color=0xffffff
 end
end

f.Show()
chk1.OnChange=chk1_tickChange
chk2.OnChange=chk2_tickChange



Anyhow I am not find how to change check box color / check mark color in win API yet.
or check for user32 properties to quick change windows theme



Capture.JPG
 Description:
 Filesize:  16.89 KB
 Viewed:  2315 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: 30

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Sun Aug 14, 2022 7:09 am    Post subject: Reply with quote

Corroder wrote:
Or like this

executeCodeLocalEx('uxtheme.SetWindowTheme', chk2.handle, "", "")


I give up. Your code is more original. Shocked
This might give @DB a different idea in the new update.

You can share this in the Lua section. (for archive)

and +1

_________________
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: Mon Aug 15, 2022 11:45 pm    Post subject: Reply with quote

Don't give up...
This is a sample using uxtheme for some properties on CE Form

Code:
function ActivateWindowTheme(hWnd, pszSubAppName, pszSubIdList)
  return executeCodeLocalEx('uxtheme.SetWindowTheme', hWnd, pszSubAppName, pszSubIdList)
end

if frm then frm.destroy() end

frm = createForm()

btn1 = createButton(frm)
btn1.setSize(100,50)
btn1.setPosition(10,10)
btn1.Caption = 'Original CE'

btn2 = createButton(frm)
btn2.setSize(100,50)
btn2.setPosition(120,10)
btn2.Caption = 'To UxTheme'
ActivateWindowTheme(btn2.handle,"BUTTON","")

cb1 = createCheckBox(frm)
cb1.setPosition(10,70)
cb1.Caption = 'Original'

cb2 = createCheckBox(frm)
cb2.setPosition(10,100)
cb2.Caption = 'UxTheme'
ActivateWindowTheme(cb2.handle,"CHECKBOX","")

cb3 = createCheckBox(frm)
cb3.setPosition(10,130)
cb3.Caption = 'UxTheme With Color'
ActivateWindowTheme(cb3.handle,"CHECKBOX","")
cb3.Color = 54852
cb3.Font.Color = 0xffffff

frm.show()


See the different ?



Capture.JPG
 Description:
 Filesize:  18.54 KB
 Viewed:  2245 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: 457

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

PostPosted: Tue Aug 16, 2022 1:50 am    Post subject: Reply with quote

I really recommend to just use ownerdraw checkboxes and draw the boxes and text the way you like. (try window subclassing checkbox if you wish)
_________________
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
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Aug 16, 2022 5:45 am    Post subject: Reply with quote

Dark Byte wrote:
... (try window subclassing checkbox if you wish)


Yes, I see. Anyhow I don't have any experiences to write window subclassing in CE Lua and of course to manage the event handler for the control.
Btw, this is a subclassing project using Lua WINAPI.
And thanks DB for your recommendation.

https://github.com/luapower/winapi/blob/master/winapi/checkboxclass.lua?ts=3

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

Joined: 01 Oct 2008
Posts: 941

PostPosted: Tue Aug 16, 2022 9:08 am    Post subject: Reply with quote

Corroder wrote:

...

https://github.com/luapower/winapi/blob/master/winapi/checkboxclass.lua?ts=3


That's for luajit, interfacing windows api via its ffi.
May be this https://github.com/stevedonovan/winapi , but it's 9 yr old (b4 5.3?), not sure if it can build with ce, or if there're updated version.

_________________
- Retarded.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Aug 16, 2022 7:13 pm    Post subject: Reply with quote

panraven wrote:
Corroder wrote:

...

https://github.com/luapower/winapi/blob/master/winapi/checkboxclass.lua?ts=3


That's for luajit, interfacing windows api via its ffi.
May be this https://github.com/stevedonovan/winapi , but it's 9 yr old (b4 5.3?), not sure if it can build with ce, or if there're updated version.


Thanks panraven for info. Let see if I can ported window sub classing in C#/C++ script to CE Lua. If success then it will good and I should post them here later. Smile

_________________
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: 457

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

PostPosted: Tue Aug 16, 2022 11:40 pm    Post subject: Reply with quote

i was talking about things like https://docs.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-setwindowsubclass

and then intercept WM_PAINT to draw a custom checkbox

_________________
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
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Aug 18, 2022 11:58 pm    Post subject: Reply with quote

This is an alternative to create custom checkbox in the primitive ways.
Of course someone able to make a function to make custom checkbox if you wish.

like

Code:
function createCustomCheckBox(hwnd, l, t, w, h, cbname. cbcaption. cbstate, etc...)

end


So, this is an example to create custom checkbox using panel, label and image in the primitive way. Very Happy Very Happy

Code:
if f then f.destroy() end
f = createForm()
f.Position = 'poScreenCenter'
f.Height = 80
f.Caption = 'Primitive Custom Checkbox'

-- create panel as a checkbox
cb = createPanel(f)
cb.Width = 24
cb.Height = 24
cb.Left = 10
cb.Top = 10
cb.Color = f.Color
cb.Caption = ''

-- create label for chackbox
cblbl = createLabel(f)
cblbl.Left = cb.Left + cb.Width + 7
cblbl.Top = cb.Top + 4
cblbl.Caption = 'My Custom Checkbox - Not Active'

-- create Image for checkbox
cbstate = createImage(cb)
cbstate.Picture.loadFromStream(findTableFile('cb_unactive.png').Stream)
cbstate.Width = cb.Width
cbstate.Height = cb.Height
cbstate.Stretch = true
cbstate.Tag = 0

-- create panel as a checkbox
cb1 = createPanel(f)
cb1.Width = 24
cb1.Height = 24
cb1.Left = 10
cb1.Top = 40
cb1.Color = f.Color
cb1.Caption = ''

-- create label for chackbox
cblbl1 = createLabel(f)
cblbl1.Left = cb1.Left + cb1.Width + 7
cblbl1.Top = cb1.Top + 4
cblbl1.Caption = 'This is off'

-- create Image for checkbox
cbstate1 = createImage(cb1)
cbstate1.Picture.loadFromStream(findTableFile('cb_unactive.png').Stream)
cbstate1.Width = cb1.Width
cbstate1.Height = cb1.Height
cbstate1.Stretch = true
cbstate1.Tag = 0


function cb_onClick()
 if cbstate.Tag == 0 then
    cbstate.Picture.loadFromStream(findTableFile('cb_active.png').Stream)
    cblbl.Caption = 'Active'
    -- your code here
    cbstate.Tag = 1
  else
    cbstate.Picture.loadFromStream(findTableFile('cb_unactive.png').Stream)
    cblbl.Caption = 'My Custom Checkbox - Not Active'
    -- your code here
    cbstate.Tag = 0
  end
end

function cb_onClick1()
 if cbstate1.Tag == 0 then
    cbstate1.Picture.loadFromStream(findTableFile('cb_active.png').Stream)
    cblbl1.Caption = 'This is on'
    -- your code here
    cbstate1.Tag = 1
  else
    cbstate1.Picture.loadFromStream(findTableFile('cb_unactive.png').Stream)
    cblbl1.Caption = 'This is off'
    -- your code here
    cbstate1.Tag = 0
  end
end

f.show()
cbstate.onClick = cb_onClick
cbstate1.onClick = cb_onClick1


Just an illustration. Hope you have better idea Very Happy



Capture.JPG
 Description:
 Filesize:  15.06 KB
 Viewed:  2069 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: 30

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Fri Aug 19, 2022 1:46 am    Post subject: Reply with quote

The magic of "setWindowTheme" still remains. One line of code and good result. With just this code, a library can be created for other objects and different visuals can be given in existing gui controls.

Code:

if f then f.destroy() end

f=createForm()

chk1=createCheckBox(f)
chk1.font.size=14
chk1.left = 30
chk1.top = 30
chk1.caption='This is OFF'
executeCodeLocalEx('uxtheme.SetWindowTheme', chk1.handle, "", "")

executeCodeLocalEx('uxtheme.SetWindowTheme', f.handle, "", "")
f.color = 0x00ff00
f.font.color = 0xff0000
chk1.font.color = 0x0000ff

_________________
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