Jump to content

ToDoList


Recommended Posts

Hey guys,

 

I wanted to have a small ToDo list for my computer but I didn't really find what I needed. Maybe somebody else has use for it.

Untitled.png

Spoiler
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_Version=Beta
    #AutoIt3Wrapper_Icon=ToDo.ico
    #AutoIt3Wrapper_Outfile=..\ToDo.exe
    #AutoIt3Wrapper_Outfile_x64=..\ToDo.exe
    #AutoIt3Wrapper_Compression=4
    #AutoIt3Wrapper_Res_Comment=ToDoList
    #AutoIt3Wrapper_Res_Description=ToDoList
    #AutoIt3Wrapper_Res_Fileversion=1.1.0.0
    #AutoIt3Wrapper_Res_ProductVersion=1.1.0.0
    #Tidy_Parameters=/reel /sf /ri
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#Region Includes
    ;|----------------------------------------------------------------------------------------------------------------|
    ;|---------------------------------------------- Standard includes -----------------------------------------------|
    ;|----------------------------------------------------------------------------------------------------------------|
    #include <File.au3>
    #include <Date.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiEdit.au3>
    #include <GuiListView.au3>
    #include <ListViewConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <WinAPI.au3>
    #include <FontConstants.au3>
#EndRegion Includes

#Region Variables
    ;|----------------------------------------------------------------------------------------------------------------|
    ;|---------------------------------------- Global variables and constants ----------------------------------------|
    ;|----------------------------------------------------------------------------------------------------------------|

    Opt("GUIResizeMode", $GUI_DOCKALL)

    ;|-------------|
    ;| Script data |
    ;|-------------|
    Global Const $_gc_sScriptName = StringLeft(@ScriptName, StringInStr(@ScriptName, ".", 0, -1) - 1)
    Global Const $_gc_sDir_Dropbox = @ScriptDir
    Global Const $_gc_sFile = $_gc_sDir_Dropbox & "\_Settings\" & $_gc_sScriptName & ".dat"
    Global Const $_gc_hClr_Green = 0x267F00, $_gc_hClr_Black = 0x000000
    Global $_gv_hLV
#EndRegion Variables

#Region
    _GUI_Main()

    Func _GUI_Main()
        Local $_lv_iSysDPI = _SysGetDPI()
        Local $_lv_hGUI = GUICreate("SysControl_ToDo", 400, 400, @DesktopWidth - 410, 10, BitOR($WS_POPUP, 0), BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED))
        GUISetFont(8.5 / $_lv_iSysDPI)
        GUISetBkColor(0x123456)

        Local $_lv_iBttn_Mns = GUICtrlCreateButton("-", 2, 2, 21, 21)
        Local $_lv_iBttn_Pls = GUICtrlCreateButton("+", 25, 2, 21, 21)
        Local $_lv_iInpt_Hdr = GUICtrlCreateInput("", 48, 2, 347, 21)

        Local $_lv_iLV = GUICtrlCreateListView("#|Date|Text|Entry", 2, 25, 396, 250, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $WS_TABSTOP, $WS_VISIBLE, $WS_CHILD, $WS_CLIPSIBLINGS), BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
        $_gv_hLV = GUICtrlGetHandle($_lv_iLV)
        Local $_lv_hLV_Hdr = _GUICtrlListView_GetHeader($_gv_hLV)
        GUIRegisterMsg($WM_NOTIFY, "GUI_msg_LV")

        ; Load file
        Local $_lv_aFile, $_lv_aItem
        _FileReadToArray($_gc_sFile, $_lv_aFile, 2, ChrW(160))
        For $_lv_iData = 0 To UBound($_lv_aFile) - 1
            $_lv_aItem = $_lv_aFile[$_lv_iData]
            $_lv_aItem[0] = Execute($_lv_aItem[0])
            $_lv_aItem[3] = StringReplace($_lv_aItem[3], ChrW(161), @CRLF)
            $_lv_sData = _ArrayToString($_lv_aItem, "|", 1)
            GUICtrlCreateListViewItem($_lv_sData, $_lv_iLV)
            _GUICtrlListView_SetItemChecked($_gv_hLV, $_lv_iData, $_lv_aItem[0])
        Next
        $_lv_aData = ""

        _GUICtrlListView_SetColumnWidth($_gv_hLV, 0, 50)
        _GUICtrlListView_SetColumnWidth($_gv_hLV, 1, 120)
        _GUICtrlListView_HideColumn($_gv_hLV, 2)
        _GUICtrlListView_SetColumnWidth($_gv_hLV, 3, $LVSCW_AUTOSIZE_USEHEADER)
        ControlDisable($_lv_hGUI, "", $_lv_hLV_Hdr)

        Local $_lv_iEdt_Nmbr = GUICtrlCreateEdit("1", 2, 280, 25, 118, BitOR($ES_RIGHT, $ES_AUTOVSCROLL, $ES_READONLY))
        Local $_lv_iEdt_Bdy = GUICtrlCreateEdit("", 26, 280, 371, 118, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
        _WinAPI_SetLayeredWindowAttributes($_lv_hGUI, 0x123456)
        GUISetState()

        GUICtrlSetFont($_lv_iEdt_Nmbr, Default, Default, Default, "Courier New")
        GUICtrlSetFont($_lv_iEdt_Bdy, Default, Default, Default, "Courier New")

        Local $_lv_boLV_Slctn_Chngd
        Local $_lv_iMsg, $_lv_iTxt_Hdr
        Local $_lv_iLV_Slctd = -1
        Local $_lv_iTmr = TimerInit()
        Local $_lv_sFile = "", $_lv_sText = ""

        While 1
            $_lv_boLV_Slctn_Chngd = _GUICtrlListView_GetSelectedIndices($_gv_hLV) <> $_lv_iLV_Slctd
            If $_lv_boLV_Slctn_Chngd Then $_lv_iLV_Slctd = _GUICtrlListView_GetSelectedIndices($_gv_hLV)
            $_lv_iMsg = GUIGetMsg()
            $_lv_iTxt_Hdr = GUICtrlRead($_lv_iInpt_Hdr)

            Switch $_lv_iMsg
                Case $GUI_EVENT_CLOSE
                    ; Save comment and call line number drawing
                    If _GUICtrlEdit_GetModify($_lv_iEdt_Bdy) Then
                        $_lv_iTxt_Bdy = GUICtrlRead($_lv_iEdt_Bdy)
                        _GUICtrlListView_SetItemText($_gv_hLV, $_lv_iLV_Slctd, $_lv_iTxt_Bdy, 2)
                        _GUI_ev_LineNumbers($_lv_iEdt_Nmbr, $_lv_iEdt_Bdy)
                    EndIf

                    $_lv_iCount = _GUICtrlListView_GetItemCount($_gv_hLV) - 1
                    $_lv_aState = _GUICtrlListView_GetItemCheckedState($_gv_hLV, $_lv_iCount)
                    $_lv_sFile = ""
                    For $_lv_iItem = 0 To $_lv_iCount
                        $_lv_aData = _GUICtrlListView_GetItemTextArray($_gv_hLV, $_lv_iItem)
                        $_lv_aData[0] = $_lv_aState[$_lv_iItem]
                        $_lv_aData[3] = StringReplace($_lv_aData[3], @CRLF, ChrW(161))
                        If $_lv_sFile Then $_lv_sFile &= @CRLF
                        $_lv_sFile &= _ArrayToString($_lv_aData, ChrW(160))
                    Next
                    $_lv_hFile = FileOpen($_gc_sFile, 2 + 8 + 256)
                    FileWrite($_lv_hFile, $_lv_sFile)
                    FileClose($_lv_hFile)
                    Exit
                Case $_lv_iBttn_Pls
                    _GUICtrlListView_BeginUpdate($_gv_hLV)
                    $_lv_iNumber = StringFormat("%03d", _GUICtrlListView_GetItemCount($_gv_hLV) + 1)
                    GUICtrlCreateListViewItem($_lv_iNumber & "|" & _Now() & "|" & "|" & $_lv_iTxt_Hdr, $_lv_iLV)
                    GUICtrlSetData($_lv_iInpt_Hdr, "")
                    _GUICtrlListView_HideColumn($_gv_hLV, 2)
                    _GUICtrlListView_SetColumnWidth($_gv_hLV, 3, $LVSCW_AUTOSIZE_USEHEADER)
                    _GUICtrlListView_EndUpdate($_gv_hLV)
                Case $_lv_iBttn_Mns
                    _GUICtrlListView_BeginUpdate($_gv_hLV)
                    _GUICtrlListView_DeleteItemsSelected($_gv_hLV)
                    _GUICtrlListView_EndUpdate($_gv_hLV)
            EndSwitch

            ; Check item selection
            If $_lv_boLV_Slctn_Chngd Then
                $_lv_sText = _GUICtrlListView_GetItemText($_gv_hLV, $_lv_iLV_Slctd, 2)
                GUICtrlSetData($_lv_iEdt_Bdy, $_lv_sText)
                _GUI_ev_LineNumbers($_lv_iEdt_Nmbr, $_lv_iEdt_Bdy)
                If Not $_lv_iLV_Slctd Then
                    WinMove($_lv_hGUI, "", @DesktopWidth - 410, 10, 400, 277)
                Else
                    WinMove($_lv_hGUI, "", @DesktopWidth - 410, 10, 400, 400)
                EndIf
            EndIf
            If $_lv_iLV_Slctd = "" Then GUICtrlSetData($_lv_iEdt_Bdy, "")

            ; Handle state of controls
            _GUICtrl_SetEnableDisable($_lv_iBttn_Pls, GUICtrlRead($_lv_iInpt_Hdr))
            _GUICtrl_SetEnableDisable($_lv_iEdt_Bdy, Not ($_lv_iLV_Slctd = ""))
            _GUICtrl_SetEnableDisable($_lv_iBttn_Mns, Not ($_lv_iLV_Slctd = ""))

            ; Save comment and call line number drawing
            If _GUICtrlEdit_GetModify($_lv_iEdt_Bdy) Then
                $_lv_iTxt_Bdy = GUICtrlRead($_lv_iEdt_Bdy)
                _GUICtrlListView_SetItemText($_gv_hLV, $_lv_iLV_Slctd, $_lv_iTxt_Bdy, 2)
                _GUI_ev_LineNumbers($_lv_iEdt_Nmbr, $_lv_iEdt_Bdy)
            EndIf
        WEnd
    EndFunc   ;==>_GUI_Main
#EndRegion

#Region Helper
    Func _GUI_ev_LineNumbers($_fp_hCtrl_Cnt, $_fp_hCtrl_Edt)
        ;|---------------------------------------------------------|
        ;| _GUI_ev_LineNumbers                                     |
        ;|---------------------------------------------------------|
        ;| $_fp_hCtrl_Cnt = Handle to the line number edit control |
        ;| $_fp_hCtrl_Edt = Handle to the edit control             |
        ;|---------------------------------------------------------|
        Local $_lv_iLine, $_lv_iLines = _GUICtrlEdit_GetLineCount($_fp_hCtrl_Edt)
        Local $_lv_iVsbl_Edt, $_lv_iVsbl_Cnt
        Local $_lv_Index = 1
        Local $_lv_sTxt_Cnt = "1" & @CRLF

        For $_lv_iLine = 1 To $_lv_iLines - 1
            $_lv_iCharIndex = _GUICtrlEdit_LineIndex($_fp_hCtrl_Edt, $_lv_iLine)
            If StringMid(GUICtrlRead($_fp_hCtrl_Edt), $_lv_iCharIndex - 1, 2) = @CRLF Then
                $_lv_Index += 1
                $_lv_sTxt_Cnt &= $_lv_Index & @CRLF
            Else
                If $_lv_iLine < $_lv_iLines - 1 Then $_lv_sTxt_Cnt &= @CRLF
            EndIf
        Next
        GUICtrlSetData($_fp_hCtrl_Cnt, $_lv_sTxt_Cnt)

        $_lv_iVsbl_Edt = _GUICtrlEdit_GetFirstVisibleLine($_fp_hCtrl_Edt)
        $_lv_iVsbl_Cnt = _GUICtrlEdit_GetFirstVisibleLine($_fp_hCtrl_Cnt)
        If $_lv_iVsbl_Edt <> $_lv_iVsbl_Cnt Then
            _GUICtrlEdit_LineScroll($_fp_hCtrl_Cnt, 0, $_lv_iVsbl_Edt - $_lv_iVsbl_Cnt)
        EndIf

        _GUICtrlEdit_SetModify($_fp_hCtrl_Edt, False)
        _GUICtrlEdit_SetModify($_fp_hCtrl_Cnt, False)
    EndFunc   ;==>_GUI_ev_LineNumbers

    Func _GUICtrl_ListView_DrawItem(ByRef $_fb_hDC, ByRef $_fb_tCustDraw, $_fp_sFont, $_fp_iSize, $_fp_iWeight, $_fp_hClr_Txt, $_fp_hClr_BK, $_fp_boStrike = False)
        ;|----------------------------------------|
        ;| _GUICtrl_ListView_DrawItem             |
        ;|----------------------------------------|
        ;| $_fb_hDC = Handle                      |
        ;| $_fb_tCustDraw = Custom draw structure |
        ;| $_fp_sFont = Font name                 |
        ;| $_fp_iSize = Font size                 |
        ;| $_fp_iWeight = Font weight             |
        ;| $_fp_hClr_Txt = Color of text          |
        ;| $_fp_hClr_BK = Color of background     |
        ;| $_fp_boStrike = Strikethrough          |
        ;|----------------------------------------|
        If $_fp_sFont = Default Then $_fp_sFont = "Segoe UI"
        Local $_lv_hFont = _WinAPI_CreateFont($_fp_iSize, 0, 0, 0, $_fp_iWeight, False, False, $_fp_boStrike, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $FIXED_PITCH) ;, $_fp_sFont)
        $_fb_hDC = DllStructGetData($_fb_tCustDraw, 'hdc')
        DllStructSetData($_fb_tCustDraw, 'clrText', _RGB2BGR($_fp_hClr_Txt))
        DllStructSetData($_fb_tCustDraw, 'clrTextBk', _RGB2BGR($_fp_hClr_BK))
        _WinAPI_SelectObject($_fb_hDC, $_lv_hFont)
        _WinAPI_DeleteObject($_lv_hFont)
    EndFunc   ;==>_GUICtrl_ListView_DrawItem

    Func _GUICtrl_SetDisable($_fp_iControl)
        ;|-----------------------------------|
        ;| _GUICtrl_SetDisable               |
        ;|-----------------------------------|
        ;| $_fp_iControl = ID of the control |
        ;|-----------------------------------|
        If BitAND(GUICtrlGetState($_fp_iControl), $GUI_DISABLE) Then Return True
        GUICtrlSetState($_fp_iControl, $GUI_DISABLE)
        Return False
    EndFunc   ;==>_GUICtrl_SetDisable

    Func _GUICtrl_SetEnable($_fp_iControl)
        ;|-----------------------------------|
        ;| _GUICtrl_SetEnable                |
        ;|-----------------------------------|
        ;| $_fp_iControl = ID of the control |
        ;|-----------------------------------|
        If BitAND(GUICtrlGetState($_fp_iControl), $GUI_ENABLE) Then Return True
        GUICtrlSetState($_fp_iControl, $GUI_ENABLE)
        Return False
    EndFunc   ;==>_GUICtrl_SetEnable

    Func _GUICtrl_SetEnableDisable($_fp_iControl, $_fc_boState)
        ;|------------------------------------------------------|
        ;| _GUICtrl_SetEnableDisable                            |
        ;|------------------------------------------------------|
        ;| $_fp_iControl = ID of the control                    |
        ;| $_fc_boState = State to check for enabling/disabling |
        ;|------------------------------------------------------|
        If $_fc_boState Then
            _GUICtrl_SetEnable($_fp_iControl)
        Else
            _GUICtrl_SetDisable($_fp_iControl)
        EndIf
    EndFunc   ;==>_GUICtrl_SetEnableDisable

    Func _GUICtrlListView_GetItemCheckedState(Const $_fc_hWnd, Const $_fc_iItems)
        ;|------------------------------------------|
        ;| _GUICtrlListView_GetItemCheckedState     |
        ;|------------------------------------------|
        ;| $_fc_hWnd = Handle to the listview       |
        ;| $_fc_iItems = Count of items in listview |
        ;|------------------------------------------|
        If Not IsHWnd($_fc_hWnd) Then Return SetError(1)

        Local $_lv_bUnicode = _GUICtrlListView_GetUnicodeFormat($_fc_hWnd)

        Local $_lv_tLVITEM = DllStructCreate($tagLVITEM)
        Local $_lv_iSize = DllStructGetSize($_lv_tLVITEM)
        If @error Then Return SetError($LV_ERR, $LV_ERR, False)
        DllStructSetData($_lv_tLVITEM, "Mask", $LVIF_STATE)
        DllStructSetData($_lv_tLVITEM, "StateMask", 0xffff)

        Local $_lv_aItems[$_fc_iItems + 1]
        Local $_lv_tMemMap
        Local $_lv_pMemory

        For $_lv_iItem = 0 To $_fc_iItems
            DllStructSetData($_lv_tLVITEM, "Item", $_lv_iItem)

            If _WinAPI_InProcess($_fc_hWnd, $__g_hLVLastWnd) Then
                _SendMessage($_fc_hWnd, $LVM_GETITEMW, 0, $_lv_tLVITEM, 0, "wparam", "struct*")
            Else
                $_lv_pMemory = _MemInit($_fc_hWnd, $_lv_iSize, $_lv_tMemMap)
                _MemWrite($_lv_tMemMap, $_lv_tLVITEM)
                If $_lv_bUnicode Then
                    _SendMessage($_fc_hWnd, $LVM_GETITEMW, 0, $_lv_pMemory, 0, "wparam", "ptr")
                Else
                    _SendMessage($_fc_hWnd, $LVM_GETITEMA, 0, $_lv_pMemory, 0, "wparam", "ptr")
                EndIf
                _MemRead($_lv_tMemMap, $_lv_pMemory, $_lv_tLVITEM, $_lv_iSize)
                _MemFree($_lv_tMemMap)
            EndIf
            $_lv_aItems[$_lv_iItem] = BitAND(DllStructGetData($_lv_tLVITEM, "State"), 0x2000) <> 0
        Next
        Return $_lv_aItems
    EndFunc   ;==>_GUICtrlListView_GetItemCheckedState

    Func GUI_msg_LV($_fp_hWnd, $_fp_iMsg, $_fp_wParam, $_fp_lParam)
        ;|-------------------------------------------------------------------|
        ;| GUI_msg_LV                                                        |
        ;|-------------------------------------------------------------------|
        ;| $_fp_hWnd = Window handle of the GUI in which the message appears |
        ;| $_fp_iMsg = Windows message ID                                    |
        ;| $_fp_wParam = First message parameter as hex value                |
        ;| $_fp_lParam = Second message parameter as hex value               |
        ;|-------------------------------------------------------------------|
        Local $_lv_hWndFrom, $_lv_iCode, $_lv_tNMHDR
        $_lv_tNMHDR = DllStructCreate($tagNMHDR, $_fp_lParam)
        $_lv_hWndFrom = HWnd(DllStructGetData($_lv_tNMHDR, "hWndFrom"))
        $_lv_iCode = DllStructGetData($_lv_tNMHDR, "Code")

        If $_lv_hWndFrom <> $_gv_hLV Then Return $GUI_RUNDEFMSG
        If $_lv_iCode <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG
        If Not _GUICtrlListView_GetViewDetails($_lv_hWndFrom) Then Return $GUI_RUNDEFMSG

        Local $_lv_tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $_fp_lParam)
        Local $_lv_iDrawState = DllStructGetData($_lv_tCustDraw, 'dwDrawStage'), $_lv_iItem, $_lv_iSubItem, $_lv_hDC

        Switch $_lv_iDrawState
            Case $CDDS_ITEMPREPAINT
                Return $CDRF_NOTIFYSUBITEMDRAW
            Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                $_lv_iItem = DllStructGetData($_lv_tCustDraw, 'dwItemSpec')
                $_lv_iSubItem = DllStructGetData($_lv_tCustDraw, 'iSubItem')
                Local $_lv_hClr_Txt = 0x000000, $_lv_hClr_BK = 0xFFFFFF, $_lv_iSize = 14, $_lv_sFont = Default, $_lv_iWeight = $FW_NORMAL, $_lv_boStrike = False
                If _GUICtrlListView_GetItemChecked($_gv_hLV, $_lv_iItem) Then
                    $_lv_hClr_Txt = $_gc_hClr_Green
                    $_lv_boStrike = True
                Else
                    $_lv_hClr_Txt = $_gc_hClr_Black
                EndIf
                _GUICtrl_ListView_DrawItem($_lv_hDC, $_lv_tCustDraw, $_lv_sFont, $_lv_iSize, $_lv_iWeight, $_lv_hClr_Txt, $_lv_hClr_BK, $_lv_boStrike)
                Return $CDRF_NEWFONT
        EndSwitch
        Return $GUI_RUNDEFMSG
    EndFunc   ;==>GUI_msg_LV
#EndRegion Helper

#Region Functions - Helper
    Func _RGB2BGR($_fp_iColor)
        ;|-------------------------------------------------------|
        ;| _RGB2BGR                                              |
        ;|-------------------------------------------------------|
        ;| $_fp_iColor = Color to convert from RGB format to BGR |
        ;|-------------------------------------------------------|
        Return BitAND(BitShift(String(Binary($_fp_iColor)), 8), 0xFFFFFF)
    EndFunc   ;==>_RGB2BGR

    Func _SysGetDPI()
        Local $_lv_aDPI[3]
        Local $_lv_iDPI, $_lv_iDPIRat, $_lv_iLogPixelsY = 90, $_lv_hWnd = 0
        Local $_lv_hDC = DllCall("user32.dll", "long", "GetDC", "long", $_lv_hWnd)
        Local $_lv_aRet = DllCall("gdi32.dll", "long", "GetDeviceCaps", "long", $_lv_hDC[0], "long", $_lv_iLogPixelsY)
        $_lv_hDC = DllCall("user32.dll", "long", "ReleaseDC", "long", $_lv_hWnd, "long", $_lv_hDC)
        $_lv_iDPI = $_lv_aRet[0]
        Select
            Case $_lv_iDPI = 0
                $_lv_iDPI = 96
                $_lv_iDPIRat = 94
            Case $_lv_iDPI < 84
                $_lv_iDPIRat = $_lv_iDPI / 105
            Case $_lv_iDPI < 121
                $_lv_iDPIRat = $_lv_iDPI / 96
            Case $_lv_iDPI < 145
                $_lv_iDPIRat = $_lv_iDPI / 95
            Case Else
                $_lv_iDPIRat = $_lv_iDPI / 94
        EndSelect

        $_lv_aDPI[0] = 2
        $_lv_aDPI[1] = $_lv_iDPI
        $_lv_aDPI[2] = $_lv_iDPIRat

        Return $_lv_iDPIRat
    EndFunc   ;==>_SysGetDPI
#EndRegion Functions - Helper

 

 

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