Jump to content

Check\Uncheck Single RadioButton


Recommended Posts

As always I must remind everyone I’m an accountant and not a programmer and rusty on many aspects of Autoit. I think I've tried all the examples I could find on Transparent Gui's where the controls can be accessed through the transparency. However whenever radio buttons are involved their state can only be changed once. I figured I will need to fix this manually by checking the state and changing it each time its clicked. Is this correct or can something be done in the styles maybe that can fix this problem. As an example I’m attaching a snippet I think was written by Kip http://www.autoitscript.com/forum/index.php?showtopic=74768&st=0&p=543233&hl=kip%20transparent&fromsearch=1&#entry543233

but all the examples with RadioButtons and transparency have this same problem. Help please.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <WINAPI.au3>

Global Const $WM_LBUTTONDOWN = 0x0201 ; Drag Window 1 of 3 addin
Local $iWidth = 260, $iHeight = 200

;---------------------------------------
$hGui = GUICreate("BG", $iWidth, $iHeight, -1, 200, $WS_POPUPWINDOW, $WS_EX_TOPMOST )
GUISetBkColor(0xff0000)
WinSetTrans($hGui, "", 50)

GUIRegisterMsg($WM_LBUTTONDOWN, "_WinMove") ; Drag Window 2 of 3 addin
GUISetState()

;---------------------------------------
$gui = GUICreate("Control Gui", $iWidth - 5, $iHeight - 4, 0, -20, $WS_POPUPWINDOW, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGui)
GUICtrlCreateLabel("This is text on a transparent Layered GUI" & @CRLF & " Press Esc to Exit", 10, 10, 200, 50)
$but = GUICtrlCreateRadio("RadioButton", ($iWidth - 120 - 5) / 2, ($iHeight - 23 - 4) / 2, 120, 23)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUISetBkColor(0xABCDEF)

_WinAPI_SetLayeredWindowAttributes($gui, 0xABCDEF)

GUISetState()
;---------------------------------------

Do
    $msg = GUIGetMsg()
    If $msg = $but Then MsgBox(0, "", "Button Pressed")
Until $msg = $GUI_EVENT_CLOSE

; From http://www.autoitscript.com/forum/index.php?s=&showtopic=74560&view=findpost&p=541838
Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03

    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
        Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, _WinAPI_GetLastError(), 0)
        Case Else
            Return 1
    EndSelect
EndFunc   ;==>_WinAPI_SetLayeredWindowAttributes

; =================================================================
; Drag Window 3 of 3 addin
; =================================================================
Func _WinMove($hwnd, $Command, $wParam, $lParam)
    If BitAND(WinGetState($hwnd), 32) Then Return $GUI_RUNDEFMSG    
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    DllCall("user32.dll", "int", "SendMessage", "hWnd", $hwnd, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)   
    Return
EndFunc   ;==>_WinMove
Edited by 1905russell
Link to comment
Share on other sites

  • Moderators

1905Russel,

The problem you have is nothing to do with transparency - it is that Radio button controls can only ever be turned on! They rely on another Radio button in the same group being turned on to then be automatically turned off. If you need a single control that the user can toggle, you need to use a Checkbox.

Here is a simple example:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCheck = GUICtrlCreateCheckbox("CheckBox", 10, 10, 100, 20)

$hSingleRadio = GUICtrlCreateRadio("Single Radio", 10, 50, 100, 20)
$hButton = GUICtrlCreateButton("Uncheck", 200, 45, 80, 30)

GUIStartgroup()

$hDoubleRadio_1 = GUICtrlCreateRadio("Double Radio 1", 10, 100, 100, 20)
$hDoubleRadio_2 = GUICtrlCreateRadio("Double Radio 1", 10, 130, 100, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            GUICtrlSetState($hSingleRadio, $GUI_UNCHECKED)
    EndSwitch

WEnd

- You can toggle the Checkbox as aften as you want.

- You can only turn the Single Radio on once - it is then stuck on because there is not a second Radio to take over the checked state. Just to make the point, I have created a button which will uncheck the Single Radio button, but as you can easlily ascertain, you cannot uncheck the Single Radio button by clicking the control itself.

- You can toggle the Double Radios as often as you like - by simply selecting the un-checked one.

I hope that is clear. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks Melba23 - Yes it’s very clear. I should have tested it without transparency first. Now I understand. I really prefer the look of the single Radio button and I tried to use _GUICtrlButton_GetCheck() if 1 or 0 to force it but was still having problems. I guess its more practical just to use the checkbox or in a worst case use the single radio with separate uncheckButton. Thanks again for the insight.

Link to comment
Share on other sites

  • Moderators

1905russell,

A thought has just struck me - take a look at this:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hRadio = GUICtrlCreateRadio("Single Radio", 10, 10, 100, 20)

GUISetState()

$fState = False

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hRadio
            $fState = Not $fState
            If $fState = False Then GUICtrlSetState($hRadio, $GUI_UNCHECKED)
    EndSwitch

WEnd

Now you can have the "look" you wanted. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I had a similar thought tho you beat me too it and yours is less code shows the differance between an amature and a pro solving the problem , took me 7 lines to your 2 :mellow:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCheck = GUICtrlCreateCheckbox("CheckBox", 10, 10, 100, 20)

$hSingleRadio = GUICtrlCreateRadio("Single Radio", 10, 50, 100, 20)
$bSingleRadioState = False
$hButton = GUICtrlCreateButton("Uncheck", 200, 45, 80, 30)

GUIStartgroup()

$hDoubleRadio_1 = GUICtrlCreateRadio("Double Radio 1", 10, 100, 100, 20)
$hDoubleRadio_2 = GUICtrlCreateRadio("Double Radio 1", 10, 130, 100, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            GUICtrlSetState($hSingleRadio, $GUI_UNCHECKED)
        Case $hSingleRadio
            If $bSingleRadioState Then
                GUICtrlSetState($hSingleRadio,$GUI_UNCHECKED)
                $bSingleRadioState = False
            Else
                GUICtrlSetState($hSingleRadio,$GUI_CHECKED)
                $bSingleRadioState = True
            EndIf
    EndSwitch

WEnd
Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

  • Moderators

Yoriz,

I am an amateur too! :mellow: And my first attempt looked just like yours - until I realised that it turns on by itself! :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

As always an amazing job from team Autoit. - Resulting in the lonely “Single Radio”.

Yoritz - thank you, it’s nice to know that if all else failed your code would have saved the day and who cares about 1 or 2 extra lines as long as we got the “look”.

Melba23 – wow, impressed, thank you for being struck with thoughts and building it so simply.

Link to comment
Share on other sites

  • 7 years later...
On 2/20/2010 at 10:30 AM, Melba23 said:

1905russell,

 

A thought has just struck me - take a look at this:

 

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hRadio = GUICtrlCreateRadio("Single Radio", 10, 10, 100, 20)

GUISetState()

$fState = False

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hRadio
            $fState = Not $fState
            If $fState = False Then GUICtrlSetState($hRadio, $GUI_UNCHECKED)
    EndSwitch

WEnd

Now you can have the "look" you wanted. :mellow:

 

M23

Genial

Link to comment
Share on other sites

  • Moderators

@antonioj84 did you not see that this thread is almost 8 years old? Please do not resurrect old threads, especially when you are not contributing anything to the original discussion.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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