Page 2 of 2
Re: ButtonGadget modify color by CallBack [Resolved]
Posted: Sun Jun 25, 2023 3:11 pm
by Blue
Thanks for the explanation, mk-soft, and for refining Rashad’s code.
Breaking the code into 2 separate elements makes it self explanatory and clears up its workings as well as the purpose of the parameters.
Excellent improvement.
Re: ButtonGadget modify color by CallBack [Resolved]
Posted: Sun Jun 25, 2023 5:05 pm
by Blue
Hi
AZJIO
Out of curiosity, I tried your code.
It needs to be reworked to make it DPi aware.
take a look :

On a high resolutions display, that is illegible.
(Of course, deselecting PB's DPi option makes the whole thing normal.)
Re: ButtonGadget modify color by CallBack [Resolved]
Posted: Sun Jun 25, 2023 7:56 pm
by AZJIO
When starting the program, calculate the DPI and add the coefficient where it is needed.
DesktopResolutionX()
GetDeviceCaps
Re: ButtonGadget modify color by CallBack [Resolved]
Posted: Sun Jun 25, 2023 8:16 pm
by Blue
AZJIO wrote: Sun Jun 25, 2023 7:56 pm
When starting the program, calculate the DPI and add the coefficient where it is needed.[…]
Hmmm… seems that we may need a debate as to who should do such work

.
i know how to make MY code DPi aware, so that my programs (or parts thereof) don’t appear as postage stamps on my display. I’m not so sure others do.
However, in the case that concerns us here, I was merely pointing out that your code is lacking in this respect.
Re: ButtonGadget modify color by CallBack [Resolved]
Posted: Sun Jun 25, 2023 8:44 pm
by AZJIO
I gave a link to the launcher in which this is done and works. I don't want to complicate the code where I showed examples of using other functions to draw a square border in different styles, since oval borders look messy. That is, I would not like to add DPI check, processor architecture, type of operating system to the code. For each DPI use case, the calculations will be different and depend on what you want to draw on the button. If you don't need a font and an icon, then you don't need DPI at all. You may need to calculate the size of the icon, for example 32x32, if it fits on the button. I cannot predict all the options that you may need, I just showed how to do it. There are function names, and you yourself will figure out mathematical calculations, I hope everyone studied at school.
Re: ButtonGadget modify color by CallBack [Resolved]
Posted: Sun Jun 25, 2023 9:12 pm
by Blue
--------------------------------------------------------------------------------------------------
*** Never mind - I found the (very simple) solution ***
It was staring me in the face...
--------------------------------------------------------------------------------------------------
Question to
mk-soft in particular, but anyone is welcome to answer.
I would like to display disabled buttons with a specific colour to mark them clearly as disabled.
I was thinking that the "natural" place for that would be in the
DrawButtonCB() procedure (see mock-up below), but, so far, I haven't figured out how to identify disabled buttons... Any suggestion or solution ?
mk-soft wrote: Sun Jun 25, 2023 9:32 am
[...]
But I would check the PB ID and the gadget type.
Code: Select all
[...]
Procedure DrawButtonCB(wParam, *lParam.DRAWITEMSTRUCT)
SetBkMode_(*lParam\hDC, #TRANSPARENT)
If *lParam\itemState & #ODS_DISABLED ; <<< Solution : so simple...
SelectObject_(*lParam\hDC, A_Brush_for_Disabled_Gadgets)
SetTextColor_(*lParam\hDC, #A_Pale_Colour)
ElseIf *lParam\itemState & #ODS_SELECTED
SelectObject_(*lParam\hDC, BBrush)
SetTextColor_(*lParam\hDC, $D9FEFE)
Else
SelectObject_(*lParam\hDC, TBrush)
SetTextColor_(*lParam\hDC, $FF3028)
EndIf
[etc...]
EndProcedure
Procedure WCB(hWnd,uMsg,wParam,lParam)
[etc...]
EndProcedure
[... rest of the code ...]
Re: ButtonGadget modify color by CallBack [Resolved]
Posted: Sun Jun 25, 2023 9:19 pm
by Blue
AZJIO wrote: Sun Jun 25, 2023 8:44 pm
I gave a link to the launcher in which this is done and works.
You could have stopped right there,
AZJIO.
A simple answer is sometimes all that's required.
I was
* NOT * questioning your programming abilities.