hansm
New Member
Posts: 2
|
Post by hansm on Mar 1, 2021 11:09:06 GMT -5
Is there a way to change the color of a button (not a bmpbutton) after it is created?
on forehand thanks, Hans
|
|
|
Post by Walt Decker on Mar 1, 2021 14:07:55 GMT -5
If you had access to the window callback function you could do it via WM_CTLCOLORBTN. Since you do not: STRUCT tRect, X AS LONG, Y AS LONG, X1 AS LONG, Y1 AS LONG BtnHndl = HWND(#Btn) OPEN "User32" FOR DLL AS #USER OPEN "gdi32" FOR DLL AS #GDI CALLDLL #USER, "GetClientRect", BntHndl AS ULONG, tRect AS STRUCT, RetVal AS VOID CALLDLL #USER, "GetDC", BntHndl AS ULONG, BtnDc AS ULONG CALLDLL #GDI, "CreateSolidBrush", RGBcolor AS ULONG, BrushHndl AS ULONG CALLDLL #USER, "FillRect, BtnDc AS ULONG, tRect AS STRUCT, BrushHndl AS ULONG, RetVal AS VOID CALLDLL #GDI, "DeleteObject", BrushHndl AS ULONG, RevVal AS VOID CALLDLL #USER, "ReleaseDC", BtnHndl AS ULONG, BtnDc AS ULONG, RetVal AS VOID
You will probably have to go through that process every time the button is clicked and/or the window is resized.
You may have to add a couple of steps to reset the button text. I am not sure how LB will handle the change in color.
|
|
|
Post by Rod on Mar 1, 2021 15:34:38 GMT -5
Yep as Walt shows its tricky, bmpbutton is the usual solution though you can highlight a normal button in other ways.
button #main.arrow, "A Button", [Clicked], UL, 10, 10, 100,20 graphicbox #main.gb 5, 5, 110,30 open "Button Example" for window as #main #main "trapclose [quit]" #main.gb "down ; fill red ; flush ; hide" wait
[Clicked] #main.gb "show" wait
[quit] close #main end
|
|
|
Post by Brandon Parker on Mar 2, 2021 0:51:40 GMT -5
You should be able to do it using the WMLiberty.dll with Liberty BASIC. If that is something you would like to explore then either someone else or myself should be able to create an example for you. It might take me a few days though since I have some important obligations coming up over the next day or so.
{:0)
Brandon Parker
|
|
hansm
New Member
Posts: 2
|
Post by hansm on Mar 2, 2021 10:06:07 GMT -5
Rod's sugestion is perfect for me. What I need is a robust reminder that I clicked a button, which must influence the interpretation of what I see in a textbox with results of a calulation. I made a slight change in the code for demonstration purpose. Thanks for all.
button #main.arrow, "A Button", [Clicked], UL, 10, 10, 100,20
graphicbox #main.gb 5, 5, 110,30
open "Button Example" for window as #main
#main "trapclose [quit]"
#main.gb "down ; fill red ; flush "
wait
[Clicked]
if count=1 then count=0 else count=1
if count=0 then
#main.gb "down ; fill red ; flush "
else
#main.gb "down ; fill green ; flush "
end if
wait
[quit]
close #main
end
|
|
|
Post by Walt Decker on Mar 2, 2021 16:40:09 GMT -5
You should be able to do it using the WMLiberty.dll with Liberty BASIC. If that is something you would like to explore then either someone else or myself should be able to create an example for you. It might take me a few days though since I have some important obligations coming up over the next day or so. {:0) Brandon Parker Mr. Parker, where does one find WMLiberty.dll and the docs for it?
|
|
|
Post by Rod on Mar 2, 2021 16:49:50 GMT -5
|
|
|
Post by Chris Iverson on Mar 2, 2021 20:52:34 GMT -5
It may still not do what you want; WM_CTLCOLORBTN is essentially ignored for standard buttons nowadays.
Per MSDN(https://docs.microsoft.com/en-us/windows/win32/controls/wm-ctlcolorbtn#remarks):
|
|