Jump to content

GUI design more clearly with much checkboxes


Aelc
 Share

Recommended Posts

Hey guys,

Im not that good on GUI design and want to improve my skills there

I just written a script which list all windows and compare them to processes which can be restarted/closed/hided/showed

reason for this script was an experimental other script which failed and hided some important windows :D 

So i want to list all these windows but if i have like 10 windows open, they fill all my screen.

Has anyone suggestions to show this more clearly maybe?

Btw: this script isn't done yet - just made the basic functions work. But im not that motivated to finsh it when i see this chaos on screen :P:D 

 

 

;;; Author: aElc
;;; Scripts: Some out of older Topics, which were just modified a bit! much thanks for them! (I will research them to get the names and insert them)



;includes
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <Array.au3>



;hide tray
Opt("TrayIconHide", 1)

;close 2nd instance if exist
If WinExists("emergency Window Manager by ~Aelc~", "") Then WinClose("emergency Window Manager by ~Aelc~", "")

;list windows
Local $aList = WinList()

;vars
$index = $aList[0][0]
_ArrayDelete($aList, 0)
_ArraySort($aList, 0)
Local $checkbox[UBound($aList)]
Local $left = 10
Dim $path[1]
Dim $return[1]
Local $top = 10
$multi = 400
Dim $restarts[1]
Local $own = False
$taskbackup = False

;; TOP&LEFT To $i list $VAR
;~ Local $toparray[400][4]


;create GUI
$form = GUICreate("emergency Window Manager by ~Aelc~", @DesktopWidth - 40, @DesktopHeight - 100, -1, -1)

;draw checkboxes
For $i = 1 To $index - 2
    $class = _WinAPI_GetClassName(WinGetHandle($aList[$i][1]))
    If $class = "Shell_TrayWnd" Then $taskbackup = $i
    $handle = WinGetHandle($aList[$i][1])
If $i <> 1 Then $top = $top + 20
If $i = 41 Or $i = 81 Or $i = 121 Or $i = 161 Or $i = 201 Then $Top = 10
Switch $i
    Case 41
                $left = $multi
    Case 81
                $left = $multi * 2
    Case 121
                $left = $multi * 3
    Case 161
                $left = $multi * 4
    Case 201
                $left = $multi * 5
EndSwitch

;; JUST FOR CHECKING -> TOP&LEFT To $i list
;~ $toparray[0][0] = "Top"
;~ $toparray[0][1] = "$i"
;~ $toparray[0][2] = "Left"
;~ $toparray[$i][0] = $top
;~ $toparray[$i][1] = $i
;~ $toparray[$i][2] = $left

    If $aList[$i][0] = "" Then
        $title = "~NoTitle~"
    Else
        $title = $aList[$i][0]
    EndIf
    If $title = "AutoIt v3" Then
        $checkbox[$i] = GUICtrlCreateCheckbox("**this program**", $left, $top, $multi - 290, 17)
        GUICtrlSetState(-1, $GUI_DISABLE)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetBkColor(-1, 0xFFFFFF)
        $own = $i
    Else
        $checkbox[$i] = GUICtrlCreateCheckbox($title & "  |  CLASS:" & $class & " |  Handle:  " & $handle, $left, $top, $multi - 10, 17)
    EndIf
;~ If Mod ($i,2 ) = 0 Then GUICtrlSetState ( -1, $GUI_CHECKED )
;~ GUICtrlSetState ( -1, $GUI_CHECKED )
Next

;draw buttons
$leftB = 530
$button = GUICtrlCreateButton("SHOW", $leftB, @DesktopHeight - 140, 100, 20)
$button1 = GUICtrlCreateButton("HIDE", $leftB + 110, @DesktopHeight - 140, 100, 20)
$button2 = GUICtrlCreateButton("CLOSE", $leftB + 110 * 2, @DesktopHeight - 140, 100, 20)
$button3 = GUICtrlCreateButton("RESTART", $leftB + 110 * 3, @DesktopHeight - 140, 100, 20)
$button4 = GUICtrlCreateButton("mark all", $leftB - 220, @DesktopHeight - 140, 100, 20)
$button5 = GUICtrlCreateButton("unmark all", $leftB - 330, @DesktopHeight - 140, 100, 20)
$button6 = GUICtrlCreateButton("mark basic", $leftB - 440, @DesktopHeight - 140, 100, 20)
$button7 = GUICtrlCreateButton("refresh list", $leftB - 110, @DesktopHeight - 140, 100, 20)

;show gui
GUISetState(@SW_SHOW)

;loop
While 1
    If $own <> False Then
        If GUICtrlRead($checkbox[$own], 1) = "**this program**" And _IsChecked($checkbox[$own]) Then GUICtrlSetState($checkbox[$own], $GUI_UNCHECKED)
        If GUICtrlGetState($checkbox[$own]) <> 80 Then GUICtrlSetState($checkbox[$own], $GUI_DISABLE)
    EndIf
    Sleep(30)
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
            ;button
        Case $button
            For $i = 0 To UBound($aList) - 1
                If $aList[$i][0] <> "**this program**" Then
                    If _IsChecked($checkbox[$i]) Then
                        WinSetState($aList[$i][1], "", @SW_SHOW)
                        GUICtrlSetBkColor($checkbox[$i], 0xFFFFFF)
                        Sleep(20)
                    EndIf
                EndIf

            Next
            For $i = 0 To UBound($aList) - 1
                GUICtrlSetBkColor($checkbox[$i], Default)
            Next
            ;button^1
        Case $button1
            For $i = 0 To UBound($aList) - 1
                If $aList[$i][0] <> "**this program**" Then
                    If _IsChecked($checkbox[$i]) Then
                        WinSetState($aList[$i][1], "", @SW_HIDE)
                        GUICtrlSetBkColor($checkbox[$i], 0xFFFFFF)
                        Sleep(20)
                    EndIf
                EndIf

            Next
            For $i = 0 To UBound($aList) - 1
                GUICtrlSetBkColor($checkbox[$i], Default)
            Next
            ;button^2
        Case $button2
            $msgb = MsgBox(33, "Sure?", "Are you sure to restart all these processes?" & @CRLF & "Maybe there are some OS basic programs and your computer could crash!")
            If $msgb = 1 Then
                For $i = 0 To UBound($aList) - 1
                    If _IsChecked($checkbox[$i]) Then
                        WinClose($aList[$i][1], "")
                        GUICtrlSetState($checkbox[$i], $GUI_UNCHECKED)
                        GUICtrlSetBkColor($checkbox[$i], 0xFFFFFF)
                        Sleep(300)
                    EndIf
                Next
                For $i = 0 To UBound($aList) - 1
                    GUICtrlSetBkColor($checkbox[$i], Default)
                Next
            Else
                ContinueLoop
            EndIf
            ;button^3
        Case $button3
            $i2 = 0
            $progress = 0
            For $i = 0 To UBound($aList) - 1
                If _IsChecked($checkbox[$i]) Then $progress = $progress + 1
            Next
            If $progress > 4 Then ProgressOn("working...", "")
            For $i = 0 To UBound($aList) - 1
                If _IsChecked($checkbox[$i]) Then
                    ReDim $path[$i2 + 1]
                    If $progress > 4 Then ProgressSet($i + 1 / UBound($aList) * 100, Round($i / UBound($aList) * 100, 2) & "% (" & $i + 1 & "/" & UBound($aList) & ")")
                    $path[$i2] = _WinGetPath($aList[$i][1], 0)
                    If StringLen($path[$i2]) < 2 Then $path[$i2] = _WinGetPath($aList[$i][0], 1)
                    $i2 = $i2 + 1
                EndIf
            Next
            If $progress > 4 Then ProgressSet(100, 100 & "% (" & $i & "/" & UBound($aList) & ")")
            Sleep(500)
            If $progress > 4 Then ProgressOff()
            $path = _multiple_array_value_to_unique($path)
            GUIDelete()
            ReDim $checkbox[UBound($path) + 1]

            ;create GUI2
            $form = GUICreate("emergency Window Manager by ~Aelc~ - Restarts -", @DesktopWidth - 40, @DesktopHeight - 100, -1, -1)

            ;draw checkboxes
            $multi = 600
            $top = 10
            $left = 10
            For $i = 0 To UBound($path) - 1
                If $i > 40 Then
                    If $i = 41 Then $top = 10
                    $left = $multi
                    If $i < 81 Then $top = $top + 20
                Else
                    $top = $top + 20
                EndIf
                If $i > 80 Then
                    If $i = 81 Then $top = 10
                    $left = $multi * 2
                    If $i < 81 Then $top = $top + 20
                EndIf
                If $i > 120 Then
                    If $i = 121 Then $top = 10
                    $left = $multi * 3
                    If $i < 121 Then $top = $top + 20
                EndIf
                If $i > 160 Then
                    If $i = 161 Then $top = 10
                    $left = $multi * 4
                    If $i < 161 Then $top = $top + 20
                EndIf
                $checkbox[$i] = GUICtrlCreateCheckbox($path[$i][0], $left, $top, $multi - 10, 17)
                GUICtrlSetState(-1, $GUI_CHECKED)
            Next

            ;draw buttons
            $leftB = 530
            $button = GUICtrlCreateButton("RESTART", $leftB, @DesktopHeight - 140, 100, 20)

            ;show gui
            GUISetState(@SW_SHOW)

            ;loop
            While 1
                Sleep(30)
                $msg = GUIGetMsg()
                Switch $msg
                    Case $GUI_EVENT_CLOSE
                        ShellExecute(@ScriptFullPath)
                        Exit
                        ;button
                    Case $button
                        $msgb = MsgBox(33, "Sure?", "Are you sure to restart all these processes?" & @CRLF & "Maybe there are some OS basic programs and your computer could crash!")
                        If $msgb = 1 Then
                            For $i = 0 To UBound($path) - 1
                                If _IsChecked($checkbox[$i]) Then
                                    $return = _get_process_by_path($path[$i][0])
                                    MsgBox(0, "Shutdown", "Path: " & $path[$i][0] & @CRLF & "Process: " & $return, 0.5)
                                    ProcessClose($return)
                                    Sleep(1000)
                                    ShellExecute($path[$i][0])
                                    Sleep(1000)
                                EndIf
                            Next
                        Else
                            ContinueLoop
                        EndIf
                EndSwitch
            WEnd
            ;endloop GUI2

        Case $button4
            For $i = 0 To UBound($aList) - 1
                If GUICtrlRead($checkbox[$i], 1) = "**this program**" Then
                Else
                    If Not _IsChecked($checkbox[$i]) Then GUICtrlSetState($checkbox[$i], $GUI_CHECKED)
                EndIf
            Next
        Case $button5
            For $i = 0 To UBound($aList) - 1
                If _IsChecked($checkbox[$i]) Then GUICtrlSetState($checkbox[$i], $GUI_UNCHECKED)
            Next
        Case $button6
            For $i = 0 To UBound($aList) - 1
                GUICtrlSetState($checkbox[$i], $GUI_UNCHECKED)
                If $aList[$i][0] = "Start" Then GUICtrlSetState($checkbox[$i], $GUI_CHECKED)
                If $aList[$i][0] = "Program Manager" Then GUICtrlSetState($checkbox[$i], $GUI_CHECKED)
                If $taskbackup <> False Then GUICtrlSetState($checkbox[$taskbackup], $GUI_CHECKED)
            Next
        Case $button7
            ShellExecute(@ScriptFullPath)
            Exit
    EndSwitch
WEnd
;endloop










;;;FUNCs
;;;FUNCs
;;;FUNCs
;;;FUNCs
;;;FUNCs

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





Func _WinGetPath($handle = "", $title = 0, $strComputer = 'localhost')
    ;check if handle or title used
    If $title = 0 Then
        $class = _WinAPI_GetClassName($handle)
        $win = '[CLASS:' & $class & ']'
    EndIf
    If $title = 1 Then
        $win = WinGetTitle($handle)
    EndIf
    ;get PID
    $pid = WinGetProcess($win)
    ;vars
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    ;getobj
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    ;return loop
    If IsObj($colItems) Then
        For $objItem In $colItems
            If $objItem.ExecutablePath Then Return $objItem.ExecutablePath
        Next
    EndIf
EndFunc   ;==>_WinGetPath





Func _multiple_array_value_to_unique($array)
    Local $aUnique = _ArrayUnique($array)
    _ArrayDelete($aUnique, 0)
    Dim $aUnique2D[UBound($aUnique)][2]
    For $1 = 0 To UBound($aUnique) - 1
        $aUnique2D[$1][0] = $aUnique[$1]
        $aCount = _ArrayFindAll($array, $aUnique[$1])
        $aUnique2D[$1][1] = UBound($aCount)
    Next
    _ArraySort($aUnique2D)
    _ArrayColDelete($aUnique2D, 1)
    Return $aUnique2D
EndFunc   ;==>_multiple_array_value_to_unique





Func _get_process_by_path($path)
    Dim $name
    Dim $start2 = 0
    Dim $start = 0
    For $i = StringLen($path) To 2 Step -1
        If StringMid($path, $i, 1) = "." And $start2 = 0 Then $start2 = $i
        If StringMid($path, $i, 1) = "\" And $start = 0 Then $start = $i
        If $start > 0 Then
            $name = StringTrimLeft($path, $start)
            ExitLoop
        EndIf
    Next
    Return $name
EndFunc   ;==>_get_process_by_path

 

 

 

I tend to be more complicated than necessary, maybe there are much shorter ways to get the functions. If so i would enjoy to know them :) 

 

Thank you in advance

 

 

 

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Link to comment
Share on other sites

20 hours ago, Aelc said:

Has anyone suggestions to show this more clearly maybe?

Try different pages for certain classes rather than having everything all on one page, i.e. a drop down list and different pages for tooltips, border effects, Q event handlers, etc.

Link to comment
Share on other sites

6 hours ago, Sidley said:

Try different pages for certain classes rather than having everything all on one page, i.e. a drop down list and different pages for tooltips, border effects, Q event handlers, etc.

ty for for your suggestion

yeah i already thought about it.

i just find a topic to create dropdownlist with checkboxes :) (needed because i don't want to click twice to check it)

 

i will add it on the left side and create a 2nd group on the right to show specified data of the window which checkbox is hovered

 

 

what do you mean with Q event handler? :o 

why do i get garbage when i buy garbage bags? <_<

Link to comment
Share on other sites

5 hours ago, Earthshine said:

I take my inspiration for GUIs in AutoIt from a script on this forum

 

GUITemplate.au3 9.5 kB · 2 downloads

Wow ! that looks awesome! Will try to implement it :) Thank You!

 

5 hours ago, Sidley said:

No Idea, it was one of the common classes in the program you posted 😁

:D oh, when i run it Q event handlers don't appear :o 

Yeah sorting it a bit would be nice - you are right 

 

 

1 hour ago, Zedna said:

I suggest to use ListView witch checkboxes.

I use it in many my projects and I'm very satistfied with it.

Yeah a mix out of @Earthshines post and Listview would be nice i guess

 

Thank You all 

Will post it when i got a new version of it :) 

 

why do i get garbage when i buy garbage bags? <_<

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...