Jump to content
Sign in to follow this  
jonez34

If Statement Replacement

Recommended Posts

jonez34

I am trying to write up a GUI that allows registry modification. I have posted what I have so far but I am going to add way more check boxes and a few input boxes so I need to know if there is a way to replace all the If Then Elseif statements that I am going to use to save some typing. I have been looking in the help file about the case command but don't know if that is going to help me. For the code below I am using the $gui_unchecked and $gui_checked options so there are going to be a ton of If statements, is there any other way to do these?

Thanks in advance.

#include <guiconstants.au3>
#NoTrayIcon
GUICreate ("registry")
GUISetState (@SW_SHOW)
$applybutton = GUICtrlCreateButton ("Apply",10,360,60)
$cancelbutton = GUICtrlCreateButton ("Cancel",70,360,60)
$closebutton = GUICtrlCreateButton ("Close",320,360,60)
$rclickdesk = GUICtrlCreateCheckbox ("Disable Right Click On Desktop",10,40)
$rclickstart = GUICtrlCreateCheckbox ("Disable Right Click On Start Bar",10,60)
$removeicons = GUICtrlCreateCheckbox ("Remove All Icons From Taskbar",10,80)




While 1
    $msg = GUIGetMsg ()
    if $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $closebutton Then
        ExitLoop
    EndIf
    if $msg = $applybutton Then
        If GUICtrlRead ($rclickdesk) = $GUI_CHECKED Then
            RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoViewContextMenu","REG_DWORD","1")
        Elseif GUICtrlRead ($rclickdesk) = $GUI_UNCHECKED Then
             RegDelete ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoViewContextMenu")
        EndIf
        
    If GUICtrlRead ($rclickstart) = $GUI_CHECKED Then
        RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoTrayContextMenu","REG_DWORD","1")
    ElseIf GUICtrlRead ($rclickstart) = $GUI_UNCHECKED Then
        RegDelete ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoTrayContextMenu")
    Elseif GUICtrlRead ($removeicons) = $GUI_CHECKED Then
        RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoViewTrayItems","REG_DWORD","1")
    EndIf
    
EndIf

;If GUICtrlRead ($removeicons) = $GUI_CHECKED Then
    ;RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoTrayItemsDisplay","REG_DWORD","1")
;ElseIf GUICtrlRead ($removeicons) = $GUI_UNCHECKED Then
    ;RegDelete ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoTrayItemsDisplay")
;EndIf

WEnd

Share this post


Link to post
Share on other sites
Valuater

maybe...

#include <guiconstants.au3>
#NoTrayIcon

GUICreate("registry")
$applybutton = GUICtrlCreateButton("Apply", 10, 360, 60)
$cancelbutton = GUICtrlCreateButton("Cancel", 70, 360, 60)
$closebutton = GUICtrlCreateButton("Close", 320, 360, 60)
$rclickdesk = GUICtrlCreateCheckbox("Disable Right Click On Desktop", 10, 40)
$rclickstart = GUICtrlCreateCheckbox("Disable Right Click On Start Bar", 10, 60)
$removeicons = GUICtrlCreateCheckbox("Remove All Icons From Taskbar", 10, 80)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $closebutton Then ExitLoop

    If $msg = $applybutton Then
        If _IsChecked($rclickdesk) Then
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoViewContextMenu", "REG_DWORD", "1")
        Else
            RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoViewContextMenu")
        EndIf

        If _IsChecked($rclickstart) Then
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoTrayContextMenu", "REG_DWORD", "1")
        Else
            RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoTrayContextMenu")
        EndIf
        
        If _IsChecked($removeicons) Then
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoViewTrayItems", "REG_DWORD", "1")
        EndIf
    EndIf

    ;If GUICtrlRead ($removeicons) = $GUI_CHECKED Then
    ;RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoTrayItemsDisplay","REG_DWORD","1")
    ;ElseIf GUICtrlRead ($removeicons) = $GUI_UNCHECKED Then
    ;RegDelete ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoTrayItemsDisplay")
    ;EndIf

WEnd


Func _IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Zedna

I made it for you :P

#NoTrayIcon
#include <guiconstants.au3>

Global $a_ctrl[3][2]
Global $reg_key = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"

GUICreate ("registry")
$applybutton = GUICtrlCreateButton ("Apply",10,360,60)
$cancelbutton = GUICtrlCreateButton ("Cancel",70,360,60)
$closebutton = GUICtrlCreateButton ("Close",320,360,60)

$a_ctrl[0][0] = GUICtrlCreateCheckbox ("Disable Right Click On Desktop",10,40)
$a_ctrl[0][1] = "NoViewContextMenu"
$a_ctrl[1][0]= GUICtrlCreateCheckbox ("Disable Right Click On Start Bar",10,60)
$a_ctrl[1][1] = "NoTrayContextMenu"
$a_ctrl[2][0] = GUICtrlCreateCheckbox ("Remove All Icons From Taskbar",10,80)
$a_ctrl[2][1] = "NoViewTrayItems"

GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg ()
    if $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $closebutton Then ExitLoop
    
    if $msg = $applybutton Then
        For $i = 0 To 2
            If _IsChecked($a_ctrl[$i][0]) Then
                RegWrite ($reg_key,$a_ctrl[$i][1],"REG_DWORD","1")
;~              MsgBox(0,$reg_key,$a_ctrl[$i][1] & @CRLF & "ON")
            Else
                RegDelete ($reg_key,$a_ctrl[$i][1])
;~              MsgBox(0,$reg_key,$a_ctrl[$i][1] & @CRLF & "OFF")
            EndIf
        Next
    EndIf
WEnd

Func _IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

commented MsgBox's are for visual testing.

Edited by Zedna

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.