#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIListBox.au3>
If FileExists(@WindowsDir & "\noteside.data") Then
	$location = FileRead(@WindowsDir & "\noteside.data")
Else
	$location = "left"
EndIf
#RequireAdmin
#NoTrayIcon
;~ Global $WM_COMMAND = 0x0111

; LESEN-------
; 
; Hey leute, ich habs nicht so mit kommentaren also einfach im Forum fragen, wenn ihr was nicht checkt!!!
;
; LESEN-------

Global $old_klapp = 0, $ausgefahren = False, $editleft = 170, $listleft = 0, $nowreading = "", $newstatus = 0, $status1 = 0
Global $doubleclick = 1000, $pressed = False
Global $lb_height = 170-25,$lb_top=25, $lb_width = 160
Dim $start, $n = 0, $MousePos = True

$regread = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","noteside")
;~ MsgBox(0, "hi", $regread)
If $regread <> """" & @ScriptFullPath & """" Then ; Liest die Registry aus!!!
	$msgbox = MsgBox(68, "Autostart?", "Wollen sie Noteside in den Autostart schieben, so dass es bei jedem Hochfahren gestartet wird?")
	If $msgbox = 6 Then
		RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run","Noteside", "REG_SZ", """" & @ScriptFullPath & """")
	EndIf
EndIf

; hidden gui----
$hiddengui = GUICreate("hiddengui")
GUISetState(@SW_HIDE)
; hidden gui----

If $location = "left" Then
	Global $with = 170
	Global $heigh = 180
	Global $left = -160
	Global $top = 0
	Global $lb_left = 0
	$rightplus = 0
	$text = ">"
ElseIf $location = "right" Then
	Global $with = 170
	Global $heigh = 180
	Global $left = @DesktopWidth - 10
	Global $top = 0
	Global $lb_left = 10
	$rightplus = 5
	$text = "<"
EndIf

$Maingui = GUICreate("noteside", $with,$heigh,$left,$top, $WS_POPUP,$WS_EX_TOPMOST,$hiddengui)
GUISetBkColor(0xFF8800)
$List1 = GUICtrlCreateList("",$lb_left,$lb_top,$lb_width,$lb_height) ;0,25,160,170-25
GUICtrlSetTip(-1, "Zum ansehen Doppelklicken")
$Edit1 = GUICtrlCreateEdit("",170,25,160,160-25,$ES_WANTRETURN)
$back = GUICtrlCreateButton("<<",5 + $rightplus,2,20,21)
GUICtrlSetState(-1,$GUI_DISABLE)
$exit = GUICtrlCreateButton("X",27 + $rightplus,2,20,21)
GUICtrlSetTip(-1,"Beendet das Programm")
GUICtrlSetColor(-1,0xCF2202)
GUICtrlSetFont(-1,10,700)
GUICtrlCreateLabel("Noteside - Notizen",50 + $rightplus,5,120,19)
GUICtrlSetFont(-1,10,700)
$new = GUICtrlCreateButton("+",5 + $rightplus,162,20,18)
GUICtrlSetFont(-1,9,600)
GUICtrlSetTip(-1,"Neue Notiz hinzufügen")
$del = GUICtrlCreateButton("-",28 + $rightplus,162,20,18)
GUICtrlSetFont(-1,9,600)
GUICtrlSetTip(-1,"Notiz löschen")
GUICtrlCreateLabel("by Answer",75,163)
$setting = GUICtrlCreateButton($text, 135, 162, 20,18)
GUICtrlSetTip(-1, "Fenster auf der anderen Seite anzeigen")
If FileExists(@MyDocumentsDir & "\noteside.ini") Then
	$iniread = IniReadSectionNames(@MyDocumentsDir & "\noteside.ini")
	For $i = 1 To $iniread[0]
		GUICtrlSetData($List1, $iniread[$i])
	Next
EndIf
WinSetTrans($Maingui, "",0)
GUISetState()
For $i = 1 To 180 Step 3
	Sleep(1)
	WinSetTrans($Maingui, "", $i)
Next
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\", "noteinstalled") <> "installed" Then
	RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\", "noteinstalled", "REG_SZ", "installed")
	MsgBox(64, "Willkommen " & @UserName, "Dieses Programm ist einfach zu benutzen. Gehe mit der Maus über ein Control, um Infos darüber zu erhalten." & @LF & "Falls es sonst noch Frgen gibt, wende dich an maximilianlinde@yahoo.de")
EndIf
While 1
	$msg = GUIGetMsg()
	$pos = MouseGetPos()
	If $ausgefahren = True Then
		If $location = "left" Then
			If $pos[0] > 170 Or $pos[1] > 180 Then
				For $i = 0 To - 160 Step -10
					Sleep(7)
					WinMove("noteside", "", $i, 0)
				Next
				$ausgefahren = False
				WinSetTrans($Maingui, "", 180)
			EndIf
		ElseIf $location = "right" Then
			If $pos[0] < @DesktopWidth - 170 Or $pos[1] > 180 Then
				For $i = @DesktopWidth - 170 To @DesktopWidth - 10 Step 10
					Sleep(7)
					WinMove("noteside", "", $i, 0)
				Next
				$ausgefahren = False
				WinSetTrans($Maingui, "", 180)
			EndIf
		EndIf
	Else
		If $location = "left" Then
			If $pos[0] < 10 And $pos[1] < 180 Then
				For $i = -160  To 0 Step 10
					Sleep(10)
					WinMove("noteside", "", $i, 0)
				Next
				$ausgefahren = True
				WinSetTrans($Maingui, "", 255)
			EndIf
		ElseIf $location = "right" Then
			If $pos[0] > @DesktopWidth - 10 And $pos[1] < 180 Then
				For $i = @DesktopWidth - 10  To @DesktopWidth - 170 Step -10
					Sleep(10)
					WinMove("noteside", "", $i, 0)
				Next
				$ausgefahren = True
				WinSetTrans($Maingui, "", 255)
			EndIf
		EndIf
	EndIf
	If $msg = $setting Then
		If GUICtrlRead($setting) = ">" Then
			FileDelete(@WindowsDir & "\noteside.data")
			FileWrite(@WindowsDir & "\noteside.data", "right")
		Else
			FileDelete(@WindowsDir & "\noteside.data")
			FileWrite(@WindowsDir & "\noteside.data", "left")
		EndIf
		If FileExists(@WindowsDir & "\noteside.data") Then
			$location = FileRead(@WindowsDir & "\noteside.data")
		Else
			$location = "left"
		EndIf
		GUIDelete($Maingui)
		If $location = "left" Then
			Global $with = 170
			Global $heigh = 180
			Global $left = -160
			Global $top = 0
			Global $lb_left = 0
			$rightplus = 0
			$text = ">"
		ElseIf $location = "right" Then
			Global $with = 170
			Global $heigh = 180
			Global $left = @DesktopWidth - 10
			Global $top = 0
			Global $lb_left = 10
			$rightplus = 5
			$text = "<"
		EndIf

		$Maingui = GUICreate("noteside", $with,$heigh,$left,$top, $WS_POPUP,$WS_EX_TOPMOST,$hiddengui)
		GUISetBkColor(0xFF8800)
		$List1 = GUICtrlCreateList("",$lb_left,$lb_top,$lb_width,$lb_height) ;0,25,160,170-25
		GUICtrlSetTip(-1, "Zum ansehen Doppelklicken")
		$Edit1 = GUICtrlCreateEdit("",170,25,160,160-25,$ES_WANTRETURN)
		$back = GUICtrlCreateButton("<<",5 + $rightplus,2,20,21)
		GUICtrlSetState(-1,$GUI_DISABLE)
		$exit = GUICtrlCreateButton("X",27 + $rightplus,2,20,21)
		GUICtrlSetTip(-1,"Beendet das Programm")
		GUICtrlSetColor(-1,0xCF2202)
		GUICtrlSetFont(-1,10,700)
		GUICtrlCreateLabel("Noteside - Notizen",50 + $rightplus,5,120,19)
		GUICtrlSetFont(-1,10,700)
		$new = GUICtrlCreateButton("+",5 + $rightplus,162,20,18)
		GUICtrlSetFont(-1,9,600)
		GUICtrlSetTip(-1,"Neue Notiz hinzufügen")
		$del = GUICtrlCreateButton("-",28 + $rightplus,162,20,18)
		GUICtrlSetFont(-1,9,600)
		GUICtrlSetTip(-1,"Notiz löschen")
		GUICtrlCreateLabel("by Answer",75,163)
		$setting = GUICtrlCreateButton($text, 135, 162, 20,18)
		GUICtrlSetTip(-1, "Fenster auf der anderen Seite anzeigen")
		If FileExists(@MyDocumentsDir & "\noteside.ini") Then
			$iniread = IniReadSectionNames(@MyDocumentsDir & "\noteside.ini")
			For $i = 1 To $iniread[0]
				GUICtrlSetData($List1, $iniread[$i])
			Next
		EndIf
		WinSetTrans($Maingui, "",0)
		GUISetState()
		For $i = 1 To 180 Step 3
			Sleep(1)
			WinSetTrans($Maingui, "", $i)
		Next
		GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
		If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\", "noteinstalled") <> "installed" Then
			RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\", "noteinstalled", "REG_SZ", "installed")
			MsgBox(64, "Willkommen " & @UserName, "Dieses Programm ist einfach zu benutzen. Gehe mit der Maus über ein Control, um Infos darüber zu erhalten." & @LF & "Falls es sonst noch Frgen gibt, wende dich an maximilianlinde@yahoo.de")
		EndIf
	EndIf
	If $msg = $exit Then Exit
	If $msg = $back Then
		If $newstatus = 0 And $nowreading <> ""	Then
			IniWrite(@MyDocumentsDir & "\noteside.ini", $nowreading, "notiz", GUICtrlRead($Edit1))
		ElseIf $newstatus = 1 Then
			$name = InputBox("Name", "Bitte den namen der Notiz eingeben")
			If $name <> "" And Not @error Then
				IniWrite(@MyDocumentsDir & "\noteside.ini",$name,"notiz", GUICtrlRead($Edit1))
			EndIf
			$newstatus = 0
			$status1 = 1
		EndIf
		GUICtrlSetState($new, $GUI_ENABLE)
		GUICtrlSetState($del, $GUI_ENABLE)
		GUICtrlSetState($back, $GUI_DISABLE)
		Do
			Sleep(7)
			$editleft = $editleft + 5
			$listleft = $listleft + 5
			GUICtrlSetPos($List1,$listleft,25)
			GUICtrlSetPos($Edit1,$editleft,25)
		Until $editleft = 170 + $rightplus + $rightplus
		If $status1 = 1 Then
			$status1 = 0
			GUICtrlSetData($List1,"")
			If FileExists(@MyDocumentsDir & "\noteside.ini") Then
				$iniread = IniReadSectionNames(@MyDocumentsDir & "\noteside.ini")
				For $i = 1 To $iniread[0]
					GUICtrlSetData($List1, $iniread[$i])
				Next
			Else
				GUICtrlSetData($List1, "")
			EndIf
		EndIf
	EndIf
	If $msg = $new Then
		GUICtrlSetState($back,$GUI_ENABLE)
		GUICtrlSetData($Edit1, "")
		$newstatus = 1
		Do
			Sleep(7)
			$editleft = $editleft - 5
			$listleft = $listleft - 5
			GUICtrlSetPos($List1,$listleft,25)
			GUICtrlSetPos($Edit1,$editleft,25)
		Until $editleft = 0 + $rightplus + $rightplus
	EndIf
	If $msg = $del Then
		If GUICtrlRead($List1) <> "" Then
			If MsgBox(4,"Löschen", "Wollen Sie diese Notiz löschen") = 6 Then
;~ 				MsgBox(0, "", GUICtrlRead($List1))
				IniDelete(@MyDocumentsDir & "\noteside.ini",GUICtrlRead($List1))
				If FileRead(@MyDocumentsDir & "\noteside.ini") = "" Then
					FileDelete(@MyDocumentsDir & "\noteside.ini")
				EndIf
				GUICtrlSetData($List1, "")
				If FileExists(@MyDocumentsDir & "\noteside.ini") Then
					$iniread = IniReadSectionNames(@MyDocumentsDir & "\noteside.ini")
					For $i = 1 to $iniread[0]
						GUICtrlSetData($List1, $iniread[$i])
					Next
				EndIf
			EndIf
		EndIf
	EndIf
WEnd
Func _duoclick()
	If GUICtrlRead($List1) <> "" Then
		GUICtrlSetState($back,$GUI_ENABLE)
		GUICtrlSetState($new, $GUI_DISABLE)
		GUICtrlSetState($del, $GUI_DISABLE)
		$nowreading = GUICtrlRead($List1)
		GUICtrlSetData($Edit1, IniRead(@MyDocumentsDir & "\noteside.ini",GUICtrlRead($List1),"notiz","ERROR - Text Not Found"))
		Do
			Sleep(7)
			$editleft = $editleft - 5
			$listleft = $listleft - 5
			GUICtrlSetPos($List1,$listleft,25)
			GUICtrlSetPos($Edit1,$editleft,25)
		Until $editleft = 0 + $rightplus + $rightplus
	EndIf
EndFunc
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
    If Not IsHWnd($List1) Then $hWndListBox = GUICtrlGetHandle($List1)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $List1, $hWndListBox
            Switch $iCode
                Case $LBN_DBLCLK
                    _duoclick()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND