Jump to content

My latest script, looking for advice


benners
 Share

Recommended Posts

I have written a script that I am mainly happy with and would appreciate it someone could spare the time to give it the once over to check for any obvious blunders or AutoIt no no's. There probably are some small errors but I would really like some pointers to improve\reduce coding and layout and slaps for doing things totally against AutoIt etiquette, if there is such a thing.

I try to make the code as short and clean as I know how so do things like use 2 if statements instead of if..then..else e.g

If a = b then do something
If a <> b then do something else

instead of

if a = b then 
    do something
else
    then do something else
endif

This may lead to problems I can't see but someone else would be pissing their sides at :">

Here (1.38MB) is a link to the rar file. Inside there is the script, a compile exe, a help file and the programs ini.

Thanks

Link to comment
Share on other sites

Very Nice!

I have never used IniDelete, Normally, I just use INIWrite "" or "(replacement value)"

like here and in your question

If GUICtrlRead($Transform_inp) = '' Then IniDelete($SaveINI, 'Transforms')
    If GUICtrlRead($Transform_inp) <> '' Then IniWrite($SaveINI, 'Transforms', 'MST', GUICtrlRead($Transform_inp))
    If GUICtrlRead($UserName_inp) = '' Then IniDelete($SaveINI, 'Options', 'USERNAME')
    If GUICtrlRead($UserName_inp) <> '' Then IniWrite($SaveINI, 'Options', 'USERNAME', GUICtrlRead($UserName_inp))
    If GUICtrlRead($CompanyName_inp) = '' Then IniDelete($SaveINI, 'Options', 'COMPANYNAME')
    If GUICtrlRead($CompanyName_inp) <> '' Then IniWrite($SaveINI, 'Options', 'COMPANYNAME', GUICtrlRead($CompanyName_inp))
    If GUICtrlRead($InstallLocation_inp) = '' Then IniDelete($SaveINI, 'Options', 'INSTALLLOCATION')
    If GUICtrlRead($InstallLocation_inp) <> '' Then IniWrite($SaveINI, 'Options', 'INSTALLLOCATION', GUICtrlRead($InstallLocation_inp))
    If GUICtrlRead($Display_cbo) = 'Full'  Then IniDelete($SaveINI, 'Display', 'Display')
    If GUICtrlRead($Display_cbo) <> '' And GUICtrlRead($Display_cbo) <> 'Full'  Then IniWrite($SaveINI, 'Display', 'Display', GUICtrlRead($Display_cbo))

also, since this look so good, maybe you want to look at placing icons on the tabs

( or add an "About" tab to finish the row)

Great Job!!!

8)

NEWHeader1.png

Link to comment
Share on other sites

heres an example of Icons on Tabs, By Holger

#include <GUIConstants.au3>

;Global Const $TCM_SETIMAGELIST = 0x1303
;Global Const $TCM_SETITEM = 0x1306

; Disable visual styles for controls
;DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)

Global $hImageList = 0


$main_GUI            = GUICreate("Tab Sample", 400, 300, -1, -1);, BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPSIBLINGS))
$ok_button            = GUICtrlCreateButton("OK", 110, 270, 70, 20)
$cancel_button        = GUICtrlCreateButton("Cancel", 220, 270, 70, 20)
GUISetState()

; Creates the first child window that is implemented into the main GUI
$child1                = GUICreate("", 370, 215, 15, 40, BitOr($WS_CHILD,$WS_TABSTOP), -1, $main_GUI)
;GUISetBkColor(0x257788); just for dimensing the child
$child1_tab            = GUICtrlCreateTab(0, 0, 370, 215)
$child1_tabitem1    = GUICtrlCreateTabItem("Child1Tab1")
$child1_tabitem2    = GUICtrlCreateTabItem("Child1Tab2")
$child1_tabitem3    = GUICtrlCreateTabItem("Child1Tab3")
GUICtrlCreateTabItem("")

GUISetState()

; Creates the second child window that is implemented into the main GUI
$child2                = GUICreate("", 370, 215, 15, 40, BitOr($WS_CHILD,$WS_TABSTOP), -1, $main_GUI)
;GUISetBkColor(0x257788); just for dimensing the child

$child3                = GUICreate("", 210, 220, 158, 0, BitOr($WS_CHILD,$WS_TABSTOP), -1, $child2)
;GUISetBkColor(0x257788)
$listview            = GUICtrlCreateListView("Col1|Col2", 0, 2, 210, 211, BitOr($LVS_NOSORTHEADER,$LVS_SHOWSELALWAYS,$WS_TABSTOP), $WS_EX_CLIENTEDGE)
GUICtrlCreateListViewItem("ItemLong1|ItemLong2", $listview)
GUICtrlCreateListViewItem("ItemLong3|ItemLong4", $listview)
GUICtrlCreateListViewItem("ItemLong5|ItemLong6", $listview)
GUISetState()

GUISwitch($child2)
$child2_tab            = GUICtrlCreateTab(0, 0, 156, 215)
$child2_tabitem1    = GUICtrlCreateTabItem("Child2Tab1")
$child2_tabitem2    = GUICtrlCreateTabItem("Child2Tab2")
GUICtrlCreateTabItem("")

; Switch back the main GUI and create the tabs
GUISwitch($main_GUI)
$main_tab            = GUICtrlCreateTab(10, 10, 380, 250)
$main_tabitem1        = GUICtrlCreateTabItem("MainTab1")
$main_tabitem2        = GUICtrlCreateTabItem("MainTab2")
GUICtrlCreateTabItem("")
GUICtrlSetState($main_tabitem1,$GUI_SHOW)

Bind_ImageList($main_tab)

While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $cancel_button
            ExitLoop
            
        Case $msg[0] = $main_tab
            $tabidx = GUICtrlRead($main_tab)
            Select
                Case $tabidx = 0
                    GUISetState(@SW_HIDE, $child2)
                    GUISetState(@SW_SHOW, $child1)
            
                Case $tabidx = 1
                    GUISetState(@SW_HIDE, $child1)
                    GUISetState(@SW_SHOW, $child2)
            EndSelect
    EndSelect
WEnd

DllCall("comctl32.dll", "int", "ImageList_Destroy", "hwnd", $hImageList)
Exit



Func ImageList_Create()
    $hImageList = DllCall("comctl32.dll", "hwnd", "ImageList_Create", "int", 16, "int", 16, "int", 0x0021, "int", 0, "int", 1)
    $hImageList = $hImageList[0]
    Return $hImageList
EndFunc


Func Bind_ImageList($nCtrl)
    $hImageList = ImageList_Create()
    GUICtrlSendMsg($nCtrl, $TCM_SETIMAGELIST, 0, $hImageList)
    
    $szIconFile = "shell32.dll"

    $tcitem = DllStructCreate("uint;dword;dword;ptr;int;int;int")
    DllStructSetData($tcitem, 1, 0x0002)
    DllStructSetData($tcitem, 6, 0)
    AddImageToTab($nCtrl, 0, $tcitem, $szIconFile, 12)
    
    DllStructSetData($tcitem, 6, 1)
    AddImageToTab($nCtrl, 1, $tcitem, $szIconFile,21)
    
    $tcitem = 0
EndFunc


Func AddImageToTab($nCtrl, $nTabIndex, $nItem, $szIconFile, $nIconID)
    $hIcon = DllStructCreate("int")
    $result = DllCall("shell32.dll", "int", "ExtractIconEx", "str", $szIconFile, "int", $nIconID, "hwnd", 0, "ptr", DllStructGetPtr($hIcon), "int", 1)
    $result = $result[0]
    If $result > 0 Then
        DllCall("comctl32.dll", "int", "ImageList_AddIcon", "hwnd", $hImageList, "hwnd", DllStructGetData($hIcon,1))
        DllCall("user32.dll", "int", "SendMessage", "hwnd", ControlGetHandle($main_GUI, "", $nCtrl), "int", $TCM_SETITEM, "int", $nTabIndex, "ptr", DllStructGetPtr($nItem))
        DllCall("user32.dll", "int", "DestroyIcon", "hwnd", $hIcon)
    EndIf
    
   $hIcon = 0
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

Very Nice!

I have never used IniDelete, Normally, I just use INIWrite "" or "(replacement value)"

like here and in your question

If GUICtrlRead($Transform_inp) = '' Then IniDelete($SaveINI, 'Transforms')
    If GUICtrlRead($Transform_inp) <> '' Then IniWrite($SaveINI, 'Transforms', 'MST', GUICtrlRead($Transform_inp))
    If GUICtrlRead($UserName_inp) = '' Then IniDelete($SaveINI, 'Options', 'USERNAME')
    If GUICtrlRead($UserName_inp) <> '' Then IniWrite($SaveINI, 'Options', 'USERNAME', GUICtrlRead($UserName_inp))
    If GUICtrlRead($CompanyName_inp) = '' Then IniDelete($SaveINI, 'Options', 'COMPANYNAME')
    If GUICtrlRead($CompanyName_inp) <> '' Then IniWrite($SaveINI, 'Options', 'COMPANYNAME', GUICtrlRead($CompanyName_inp))
    If GUICtrlRead($InstallLocation_inp) = '' Then IniDelete($SaveINI, 'Options', 'INSTALLLOCATION')
    If GUICtrlRead($InstallLocation_inp) <> '' Then IniWrite($SaveINI, 'Options', 'INSTALLLOCATION', GUICtrlRead($InstallLocation_inp))
    If GUICtrlRead($Display_cbo) = 'Full'  Then IniDelete($SaveINI, 'Display', 'Display')
    If GUICtrlRead($Display_cbo) <> '' And GUICtrlRead($Display_cbo) <> 'Full'  Then IniWrite($SaveINI, 'Display', 'Display', GUICtrlRead($Display_cbo))

also, since this look so good, maybe you want to look at placing icons on the tabs

( or add an "About" tab to finish the row)

Great Job!!!

8)

Thanks Valuater, hi praise indeed.

I am always looking for ways to improve and I can't seem to stop meddling , sometimes I hit a brick wall, go away but come back 5 mins later to try again, maybe it should be renamed AutoCrack, its so addictive :)

I will try putting the icons on Tabs, that will look sweet and not something I would have thought of, and that tiny free space is crying out for a tab but I left it just in case I though of any more additions.

Thanks for your time.

Link to comment
Share on other sites

also, since this look so good, maybe you want to look at placing icons on the tabs

HI Valuater,

I have looked at Holgers code and Dll calls are above me at this stage so I don't really understand despite reading the help file :) but despite this I have added the code and selected a few icons from shell32 (I will add my own later) and now have a problem with the 1st tab.

When the GUI is loaded the tab controls aren't visible but when switching away from and back to the 1st tab they appear, I assume this may be a painting problem (right term?) and added a GUICtrlCreateTabItem in the Bind_ImageList function, this works but was wondering if it was the correct way. I remember having this problem when trying to edit the Log tab text to add the number of errors maybe I'll redo that now ^_^

script attached:

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