Jump to content

Delete GUICtrlCreateCombo Item


Rawox
 Share

Recommended Posts

Hi there,

I managed to delete the item from the combobox... but I have a really wierd problem by now... I don't know how to fix it, can someone please take a look at it.

When I have 3 pixelfixers created and I delete the second and add a new one, it will overwrite "solid pixelfixer 3" because "solid pixelfixer 3" already exists in the ComboBox...

Anyone knows a workaround?

#Include <Array.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ComboConstants.au3>
#Include <GuiComboBox.au3>
#include "PixelFixer.au3"

Global $Title = "RPixFix"
Global $Version = "0.4"

$MainGui =                      GUICreate ( $Title & " " & $Version, 300, 200 )
$Tab =                          GUICtrlCreateTab ( 10, 10, 280, 180 )
                                GUICtrlCreateTabItem ( "Pixel Localization" )
                                GUICtrlCreateGroup ( "Static color", 25, 40, 250, 80 )
$BtRed =                        GUICtrlCreateButton ( "Red", 40, 60, 74, 24 )
$BtGreen =                      GUICtrlCreateButton ( "Green", 115, 60, 75, 24 )    
$BtBlue =                       GUICtrlCreateButton ( "Blue", 191, 60, 74, 24 )
$BtBlack =                      GUICtrlCreateButton ( "Black", 40, 85, 112, 24 )
$BtWhite =                      GUICtrlCreateButton ( "White", 153, 85, 112, 24 )
$FocusGroup =                   GUICtrlCreateGroup ( "Cycle colors", 25, 125, 250, 50 )
$ChRed =                        GUICtrlCreateCheckbox ( "Red", 40, 144 )
$ChGreen =                      GUICtrlCreateCheckbox ( "Green", 86, 144 )
$ChBlue =                       GUICtrlCreateCheckbox ( "Blue", 140, 144 )
$RunCycle =                     GUICtrlCreateButton ( "Run", 190, 142, 70, 24 )

                                GUICtrlCreateTabItem ( "PixelFixers" )
                                GUICtrlCreateGroup ( "PixelFixers", 25, 40, 250, 54 )
Global $FixersCombo =           GUICtrlCreateCombo ( "", 40, 59, 135, 24, $CBS_DROPDOWNLIST )
                                _GUICtrlComboBox_SetCueBanner ( $FixersCombo, "No PixelFixers selected." )
$DeleteFixer =                  GUICtrlCreateButton ( "Delete", 180, 58, 80, 23 )
                                GUICtrlCreateGroup ( "New PixelFixer", 25, 99, 250, 76 )
                                GUICtrlCreateLabel ( "W:", 40, 122 )
$PixelWidth =                   GUICtrlCreateInput ( "10", 58, 118, 40 )
$PixelWidthUD =                 GUICtrlCreateUpDown ( $PixelWidth )
                                GUICtrlCreateLabel ( "H:", 108, 122 )
$PixelHeight =                  GUICtrlCreateInput ( "10", 123, 118, 40 )
$PixelHeightUD =                GUICtrlCreateUpDown ( $PixelHeight )
                                GUICtrlCreateLabel ( "Method:", 40, 150 )
$MethodSolid =                  GUICtrlCreateRadio ( "Solid", 90, 146 )
$MethodNoise =                  GUICtrlCreateRadio ( "Noise", 140, 146 )
$AddNewFixer =                  GUICtrlCreateButton ( "Add", 190, 146, 72, 20 )     

                                GUICtrlCreateTabItem ( "Options" )
                                GUICtrlCreateLabel ( "Interval:", 170, 122 )
$Interval =                     GUICtrlCreateInput ( "25", 210, 118, 50 )
$IntervalUD =                   GUICtrlCreateUpDown ( $Interval )

                                GUICtrlCreateTabItem ( "About" )
    
                                GUICtrlSetState ( $FocusGroup, $GUI_FOCUS )
                                GUICtrlSetState ( $MethodSolid, $GUI_CHECKED )
                                GUICtrlSetState ( $ChRed, $GUI_CHECKED )
                                GUICtrlSetState ( $ChGreen, $GUI_CHECKED )
                                GUICtrlSetState ( $ChBlue, $GUI_CHECKED )
                                GUISetState ( @SW_SHOW, $MainGui )

While 1
    Switch GUIGetMsg()
        Case $DeleteFixer
            If GUICtrlRead ( $FixersCombo ) <> "" Then
                $CurrentFixer = StringTrimLeft ( GUICtrlRead ( $FixersCombo ), 17 )
                ConsoleWrite ( "Deleting Fixer: " & $CurrentFixer & " || " )
                $CurSel = _GUICtrlComboBox_GetCurSel ( $FixersCombo )
                _GUICtrlComboBox_DeleteString ( $FixersCombo, $CurSel )
                GUICtrlSetState ( $FixersCombo, $GUI_FOCUS )
                GUICtrlSetState ( $FocusGroup, $GUI_FOCUS )
                GUIDelete ( $ahSolidFixers[$CurrentFixer] )
                ConsoleWrite ( $ahSolidFixers[0] & " || " )
                _ArrayDelete ( $ahSolidFixers, $CurrentFixer )
                $ahSolidFixers[0] = $ahSolidFixers[0] - 1
                _ArrayDisplay ( $ahSolidFixers )
            EndIf
        Case $AddNewFixer
            If GUICtrlRead ( $MethodSolid ) = $GUI_CHECKED Then
                createSolidFixer ( GUICtrlRead ( $PixelWidth ), GUICtrlRead ( $PixelHeight ), GUICtrlRead ( $Interval ) )
                GUICtrlSetData ( $FixersCombo, "Solid PixelFixer " & $ahSolidFixers[0] ) ; Creates new item.
                GUICtrlSetData ( $FixersCombo, "Solid PixelFixer " & $ahSolidFixers[0] ) ; Sets new item to current.
                ConsoleWrite ( $ahSolidFixers[0] & " || " )
                _ArrayDisplay ( $ahSolidFixers )
            ElseIf GUICtrlRead ( $MethodNoise ) = $GUI_CHECKED Then
                
            EndIf
        Case $BtRed
            HotKeySet ( "{ESC}", "deleteLocalizator" )
            createLocalizator ( 0xFF0000 )
        Case $BtGreen
            HotKeySet ( "{ESC}", "deleteLocalizator" )
            createLocalizator ( 0x00FF00 )
        Case $BtBlue
            HotKeySet ( "{ESC}", "deleteLocalizator" )
            createLocalizator ( 0x0000FF )
        Case $BtBlack
            HotKeySet ( "{ESC}", "deleteLocalizator" )
            createLocalizator ( 0x000000 )
        Case $BtWhite
            HotKeySet ( "{ESC}", "deleteLocalizator" )
            createLocalizator ( 0xFFFFFF )
        Case $RunCycle
            HotKeySet ( "{ESC}", "deleteCycle" )
            ConsoleWrite ( " Red " & GUICtrlRead ( $ChRed ) & " Green " &  GUICtrlRead ( $ChGreen ) & " Blue " & GUICtrlRead ( $ChBlue ) & " || " )
            createCycle ( GUICtrlRead ( $ChRed ), GUICtrlRead ( $ChGreen ), GUICtrlRead ( $ChBlue ) )
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Included File

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global $Title = "RPixFix"
Global $ahSolidFixers[6] = [0]
Global $aAllColors[3] = [0xFF0000, 0x00FF00, 0x0000FF]
$iColourCount = 0

Func createLocalizator ( $Color )
    Global $Localizator =   GUICreate ( $Title & " is fixing pixels...", @DesktopWidth+2, @DesktopHeight+100, -1, -1, $WS_POPUP, $WS_EX_TOPMOST, WinGetHandle("[CLASS:Progman]") )
    
    $Label =                GUICtrlCreateLabel ( "", 0, 0, @DesktopWidth+2, @DesktopHeight+100 )
                            GUICtrlSetBkColor ( $Label, $Color )
                            
                            GUISetCursor ( 16, 1 )
                            GUISetState ( @SW_SHOW, $Localizator )
                            
EndFunc

Func deleteLocalizator ( )
    GUISetCursor ( )
    GUIDelete ( $Localizator )
    HotKeySet ( "{ESC}" )
EndFunc

Global $Red = True
Global $Blue = True
Global $Green = True

Func createCycle ( $Red, $Green, $Blue )
    Global $Cycle =         GUICreate ( $Title & " is fixing pixels...", @DesktopWidth+2, @DesktopHeight+100, -1, -1, $WS_POPUP, $WS_EX_TOPMOST, WinGetHandle("[CLASS:Progman]") )
    
    Global $Label =         GUICtrlCreateLabel ( "", 0, 0, @DesktopWidth+2, @DesktopHeight+100 )
                            GUICtrlSetBkColor ( $Label, 0x0000FF )
                            
                            GUISetState ( @SW_SHOW, $Cycle )
                            GUISetCursor ( 16, 1 )
                            
                            AdlibRegister ( "createCycleLib", 1500 )

EndFunc
            
Func createCycleLib ( )
    If $Red = True Then
        GUICtrlSetBkColor ( $Label, 0x00FF00 )
        $Blue = True
        $Red = False
        $Green = False
    ElseIf $Blue = True Then
        GUICtrlSetBkColor ( $Label, 0xFF0000 )
        $Green = True
        $Blue = False
        $Red = False
    ElseIf $Green = True Then
        GUICtrlSetBkColor ( $Label, 0x0000FF )
        $Red = True
        $Blue = False
        $Green = False
    EndIf
EndFunc

Func deleteCycle ( )
    AdlibUnRegister ( )
    GUISetCursor ( )
    GUIDelete ( $Cycle )
    HotKeySet ( "{ESC}" )
EndFunc

Func createSolidFixer ( $FixerWidth, $FixerHeight, $FixerRefreshMS )
    
    If $ahSolidFixers[0] = 5 Then Return
    $ahSolidFixers[0] += 1
        
    $ahSolidFixers[$ahSolidFixers[0]] = GUICreate ( $Title & " is fixing pixels...", $FixerWidth, $FixerHeight, -1, -1, $WS_POPUP, $WS_EX_TOPMOST, WinGetHandle("[CLASS:Progman]") )

    Global $Label =         GUICtrlCreateLabel ( "", 0, 0, $FixerWidth, $FixerHeight, -1, $GUI_WS_EX_PARENTDRAG )
                            
                            GUISetCursor ( 3, 1 )
                            GUISetState ( @SW_SHOW, $ahSolidFixers[$ahSolidFixers[0]] )
    
                            AdlibRegister ( "createSolidFixerLib", $FixerRefreshMS )
                            
EndFunc

Func createSolidFixerLib ( )
    $iColourCount = Mod($iColourCount + 1, 3)

    For $i = 1 To $ahSolidFixers[0]
        GUISetBkColor($aAllColors[$iColourCount], $ahSolidFixers[$i])
    Next
EndFunc
Edited by Rawox
Link to comment
Share on other sites

You could manage the GUI ID's and the combobox entries with two 1dim-arrays. Make sure, that correspondig values have the same index.

When you delete a GUI, you'll need it's ID returned by GUICreate(). Search for this ID in the gui-array and you will get the index. That index points to the combobox entry in the other array. Then just delete both array items and delete the combobox entry with these UDF's:

_GUICtrlComboBox_FindString() returns the index of a combobox entry

_GUICtrlComboBox_DeleteString() deletes that string

Edit:

Ok, you edited your post while I was writing this. I leave it, maybe it's still useful. ;)

Edited by Der_Andi
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...