Jump to content

Radio button style help please


am632
 Share

Recommended Posts

Hi,

I have this script...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 324, 222, 192, 124)
$Radio1 = GUICtrlCreateRadio("Radio One", 104, 72, 113, 17)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Radio1), "wstr", 0, "wstr", 0)
GUICtrlSetFont(-1, 12, 400, 0, "Palatino Linotype")
GUICtrlSetColor(-1, 0xFF0000)

$Radio2 = GUICtrlCreateRadio("Radio Two", 104, 110, 113, 17)
GUICtrlSetFont(-1, 12, 400, 0, "Palatino Linotype")
GUICtrlSetColor(-1, 0xFF0000)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

What the problem is, I want to change the text colour of the radio buttons to red, I have done this using the DllCall code as you can see in the script which works perfectly but at the same time it has lost the 'style' of the radio button, I have made a second button without the theming modification so you can see the difference. The second 'circle' is larger which is what I want, how can I change the text colour but not the style of the circle?

Thanks

Link to comment
Share on other sites

I don't know / can't remember whether this is possible but you can do a workaroud:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Form1", 324, 222, 192, 124)
$Radio1 = GUICtrlCreateRadio("", 104, 72, 14, 17)
;~ DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Radio1), "wstr", 0, "wstr", 0)
$Label = GUICtrlCreateLabel("Radio One", 120, 70, 100, 17)
$hLabel = GUICtrlGetHandle($Label)
GUICtrlSetFont(-1, 12, 400, 0, "Palatino Linotype")
GUICtrlSetColor(-1, 0xFF0000)

$Radio2 = GUICtrlCreateRadio("Radio Two", 104, 110, 113, 17)
GUICtrlSetFont(-1, 12, 400, 0, "Palatino Linotype")
GUICtrlSetColor(-1, 0xFF0000)

GUISetState(@SW_SHOW)

Global $hLabelWndProc = DllCallbackRegister("LabelWndProc", "long", "hwnd;uint;wparam;lparam")
Global $hOldLabelProc = _WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, DllCallbackGetPtr($hLabelWndProc))

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, $hOldLabelProc)
            DllCallbackFree($hLabelWndProc)
            GUIDelete()
            Exit

    EndSwitch
WEnd

Func LabelWndProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_LBUTTONDOWN
            GUICtrlSetState($Radio1, $GUI_CHECKED)
            GUICtrlSetState($Radio2, $GUI_UNCHECKED)
    EndSwitch
    Return _WinAPI_CallWindowProc($hOldLabelProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>EditWndProc

Maybe you can use it.

Edit: added cleanup of subclassing resources and unchecked 2nd radio button

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hi,

Thanks for the example it seems to work just fine, do you think it may be easier to just not have a label on my radio box - so like

$Radio1 = GUICtrlCreateRadio("", 104, 72, 113, 17)

then just have a label $Label1 = GUICtrlCreateLabel("Radio One", 152, 104, 100, 25) right next to it without your aditional function?

Would you agree this is simpler or can you see any downsides to it?

Thanks

Link to comment
Share on other sites

It's up to you how you design your controls / GUI.

Btw, I made some small modifications.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...