Bonjour à tous
Je me suis amusé à développer une interface simple composée de boutons qui permette de créer des raccourcis vers tout ce qui est exécutable depuis le shell windows à savoir des fichiers, des dossiers ou des liens web.
le principe étant de proposer à l'utilisateur de regrouper ses raccourcis par thème en créant des listes, chaque thème proposera 16 possibilité de raccourcis utilisable grâce aux boutons.
l'application affiche une gui comportant 16 boutons de raccourcis et 16 autres boutons permettant de les recréer, une combo box permettant de sélectionner la liste de raccourcis désirée et de deux boutons + et - permettant d'ajouter ou supprimer des listes. Un menu reprend ces deux option et ajoute la possibilité de changer la couleur de fond de l'interface.
Dans le développement j'ai essayé de simplifier le code en utilisant les CTRLID des boutons (7 à 37 impairs pour les boutons de raccourcis, 8 à 38 pour les boutons de recréation ). Lorsque l'utilisateur clique sur un bouton libre, il lui est demandé le type de raccourcis à créer et le nom à afficher sur le bouton, une fois créé le bouton lance le lien stocké dans le fichier link (fichier ini déguisé) via une commande shellexecute
Au premier lancement, lorsque aucune liste n'a été encore créé, le script crée le fichier ini de configuration et demande le nom de la première liste puis l'affiche.
aux lacements suivants, le programme lis le fichier de configuration, regarde s'il existe des fichiers de liens (*.link) et les ajoute dans le combo.
le bouton + permet d'ajouter une nouvelle liste, le bouton - permet de supprimer la liste affichée dans le combo
un contrôle des caractères autorisés et du nom de fichier (éviter un écrasement involontaire) est réalisé avant d’écrire la nouvelle liste.
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <file.au3>
#include <Misc.au3>
global $flag, $flagbutton, $flagbouton
#Region ### START Koda GUI section ### Form=
;Opt("GUICoordMode", 2)
$fileini = @ScriptDir & "\confnaviv3.ini" ; déclaration du fichier ini
$version="V3.1" ; version du programme
;------------------------- recherche d'un fichier de lien
$search = FileFindFirstFile(@ScriptDir & "\*.link")
if $search = -1 Then ; si aucun lien on va demander à créer une liste
$nomfichier = InputBox("Navigateur " & $version, "Veuillez donner un nom à votre première liste" & @CRLF & "Exemple : 'Mes raccourcis' ")
$filelink = @ScriptDir & "\" & $nomfichier & ".link"
for $i = 7 to 37 step 2
IniWriteSection($filelink,"bouton" & $i,"label=Libre" & @crlf & "link=")
Next
Else
$filelink= @ScriptDir & "\" & FileFindNextFile($search)
EndIf
Global $arraylink=_FileListToArray(@ScriptDir & "\","*.link"); recherche de tous les fichiers de liens pour alimenter le combo
if not FileExists($fileini) Then ; si le fichier ini n'existe pas on le crée
filewrite(".\confnaviv3.ini","Fichier de configuration du navigateur " & $version & " - Marc graziani")
IniWriteSection($fileini,"option","couleur=0x52B5A9")
FileClose($fileini)
EndIf
;----------------------------initialisation des boutons de raccourcis
$label_bouton7=IniRead($filelink,"bouton7","label","")
$label_bouton9=IniRead($filelink,"bouton9","label","")
$label_bouton11=IniRead($filelink,"bouton11","label","")
$label_bouton13=IniRead($filelink,"bouton13","label","")
$label_bouton15=IniRead($filelink,"bouton15","label","")
$label_bouton17=IniRead($filelink,"bouton17","label","")
$label_bouton19=IniRead($filelink,"bouton19","label","")
$label_bouton21=IniRead($filelink,"bouton21","label","")
$label_bouton23=IniRead($filelink,"bouton23","label","")
$label_bouton25=IniRead($filelink,"bouton25","label","")
$label_bouton27=IniRead($filelink,"bouton27","label","")
$label_bouton29=IniRead($filelink,"bouton29","label","")
$label_bouton31=IniRead($filelink,"bouton31","label","")
$label_bouton33=IniRead($filelink,"bouton33","label","")
$label_bouton35=IniRead($filelink,"bouton35","label","")
$label_bouton37=IniRead($filelink,"bouton37","label","")
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)
;--------------------------mise en place de l'interface graphique
$Form1 = GUICreate("Navigateur " & $version, 448, 609, 192, 124)
GUISetBkColor(IniRead($fileini,"option","couleur","0x52B5A9"))
$MenuItem1 = GUICtrlCreateMenu("&Menu")
$MenuItem3 = GUICtrlCreateMenuItem("Nouveau", $MenuItem1)
GUICtrlSetOnEvent(-1, "_ajouter")
$MenuItem4 = GUICtrlCreateMenuItem("Supprimer Liste", $MenuItem1)
GUICtrlSetOnEvent(-1, "_suppression")
$MenuItem2 = GUICtrlCreateMenuitem("&Couleur", $MenuItem1)
GUICtrlSetOnEvent(-1, "changer_couleur")
$button7= GUICtrlCreateButton($label_bouton7, 24, 112, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button8= GUICtrlCreateButton("... ", 168, 112, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button9 = GUICtrlCreateButton($label_bouton9, 25, 162, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button10 = GUICtrlCreateButton("...", 169, 162, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button11 = GUICtrlCreateButton($label_bouton11, 26, 217, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button12 = GUICtrlCreateButton("...", 170, 217, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button13 = GUICtrlCreateButton($label_bouton13, 26, 272, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button14 = GUICtrlCreateButton("...", 170, 272, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button15 = GUICtrlCreateButton($label_bouton15, 26, 328, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button16 = GUICtrlCreateButton("...", 170, 328, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button17 = GUICtrlCreateButton($label_bouton17, 26, 385, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button18 = GUICtrlCreateButton("...", 170, 385, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button19 = GUICtrlCreateButton($label_bouton19, 26, 441, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button20 = GUICtrlCreateButton("...", 170, 441, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button21 = GUICtrlCreateButton($label_bouton21, 26, 497, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button22 = GUICtrlCreateButton("...", 170, 497, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button23= GUICtrlCreateButton($label_bouton23, 254, 112, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button24= GUICtrlCreateButton("...", 398, 112, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button25 = GUICtrlCreateButton($label_bouton25, 255, 162, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button26 = GUICtrlCreateButton("...", 399, 162, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button27 = GUICtrlCreateButton($label_bouton27, 256, 217, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button28 = GUICtrlCreateButton("...", 400, 217, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button29 = GUICtrlCreateButton($label_bouton29, 256, 272, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button30 = GUICtrlCreateButton("...", 400, 272, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button31= GUICtrlCreateButton($label_bouton31, 256, 328, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button32 = GUICtrlCreateButton("...", 400, 328, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$Button33 = GUICtrlCreateButton($label_bouton33, 256, 385, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button34 = GUICtrlCreateButton("...", 400, 385, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button35= GUICtrlCreateButton($label_bouton35, 256, 441, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button36 = GUICtrlCreateButton("...", 400, 441, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button37 = GUICtrlCreateButton($label_bouton37, 256, 497, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button38 = GUICtrlCreateButton("...", 400, 497, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$Combo1 = GUICtrlCreateCombo( "Selectionnez une liste de raccourcis", 64, 40, 233, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetOnEvent(-1, "charger_combo")
$Button33 = GUICtrlCreateButton("-", 320, 40, 30, 30,$BS_ICON)
GUICtrlSetOnEvent(-1, "_suppression")
$Button34 = GUICtrlCreateButton("+", 360, 40, 30, 30,$BS_ICON)
GUICtrlSetOnEvent(-1, "_ajouter")
$MenuItem5 = GUICtrlCreateMenu("A&ide")
$MenuItem6 = GUICtrlCreateMenuItem("A &propos", $MenuItem5)
GUICtrlSetOnEvent(-1, "apropos")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
;-----------------------------alimentation du combo
For $i=1 To Ubound($arraylink)-1
$name=stringsplit($arraylink[$i],".")
;_ArrayDisplay($name)
GUICtrlSetData($Combo1,$name[1])
Next
GUICtrlSetData($Combo1,$name[1]); affichage de la liste dans le combo
charger_combo(); lecture de la liste à l'ouverture
GUISetState(@SW_SHOW)
;-----------------------------creation de la gui question
$gui_question = GUICreate("NAVIGATEUR "& $version & " Création du lien" ,650,100)
$checkbox_internet = GUICtrlCreateCheckbox("Lien Internet", 10, 30, 120, 40)
GUICtrlSetOnEvent(-1, "check_internet")
$checkbox_Fichier= GUICtrlCreateCheckbox("Lien vers fichier", 150, 30, 120, 40)
GUICtrlSetOnEvent(-1, "check_fichier")
$checkbox_dossier= GUICtrlCreateCheckbox("Lien vers dossier", 300, 30, 120, 40)
GUICtrlSetOnEvent(-1, "check_dossier")
$checkbox_nothing=GUICtrlCreateCheckbox("Supprimer lien", 450, 30,120,40)
GUICtrlSetOnEvent(-1, "check_nothing")
$btn1 = GUICtrlCreateButton("Valider", 560, 60, 80)
GUICtrlSetOnEvent(-1, "valider_guiquestion")
guictrlcreatelabel("Ajout, Suppression ou Modification d'un raccourcis...",10,5)
GUISwitch($Form1)
#EndRegion ### END Koda GUI section ###
;----------------------fonctions
Func changer_couleur()
;msgbox(0,"","")
$couleur = _ChooseColorRGB()
GUICtrlSetData($Form1,GUISetBkColor($couleur))
IniWrite($fileini,"option","couleur", $couleur)
EndFunc
func apropos()
Msgbox(4096,"A propos...","Navigateur "& "version : " & $version & @CRLF & "Concept & develloppement : Marc GRAZIANI")
EndFunc
; ---------------------------permet d'ajouter de listes dans le programme
Func _ajouter()
$nomfichier = InputBox("Navigateur " & $version, "Veuillez donner un nom à cette liste" & @CRLF & "Exemple : 'Raccourcis ministère' ")
if @error <> 0 then Return
;msgbox(0,"debug", "check nom fichier : " & _CheckForbidden($nomfichier))
if _CheckForbidden($nomfichier) <>0 Then
msgbox (64,"Navigateur " & $version, "Erreur, le nom comporte des caractères interdits :"& @CRLF & '["/\\*?<>|:]')
Return
EndIf
$filelink = @ScriptDir & "\" & $nomfichier & ".link"
if FileFindFirstFile($filelink) <> -1 Then ; test si le fichier existe si - 1 rien est trouvé
local $messagefile = msgbox(4,"Navigateur " & $version, "Un fichier portant le même nom existe déjà " & @CRLF & " Voulez vous l'ecraser ?")
if $messagefile = 6 Then
ecrireFichier($filelink)
MsgBox(64,"Navigateur " & $version, "La liste : " & $nomfichier & " a été ajoutée")
Else
Return
EndIf
Else
ecrireFichier($filelink)
MsgBox(64,"Navigateur " & $version, "La liste : " & $nomfichier & " a été ajoutée")
EndIf
EndFunc
func ecrireFichier($nomfichier)
for $i = 7 to 37 step 2
IniWriteSection($nomfichier,"bouton" & $i,"label=Libre" & @crlf & "link=")
Next
GUICtrlSetData($combo1,"")
$arraylink=""
$arraylink=_FileListToArray(@ScriptDir & "\","*.link")
For $i=1 To Ubound($arraylink)-1
$name=stringsplit($arraylink[$i],".")
GUICtrlSetData($Combo1,$name[1])
Next
EndFunc
Func _CheckForbidden($string)
Local $pattern_forbid = '["/\\*?<>|:]'
Return StringRegExp($string, $pattern_forbid)
EndFunc
func _suppression()
$linktosupress = GUICtrlRead($combo1)
if $linktosupress == "Selectionnez une liste de raccourcis" then
MsgBox(64,"Navigateur " & $version, "Vous ne pouvez pas supprimer cet item")
Else
$file2supress = @scriptdir & "\" & $linktosupress & ".link"
$message = msgbox(1, "Navigateur " & $version, "Etes vous sur de vouloir supprimer la liste : " & @CRLF & $linktosupress )
if $message = $IDOK Then
FileDelete($file2supress)
GUICtrlSetData($combo1,"")
$arraylink=""
$arraylink=_FileListToArray(@ScriptDir & "\","*.link")
For $i=1 To Ubound($arraylink)-1
$name=stringsplit($arraylink[$i],".")
GUICtrlSetData($Combo1,$name[1])
Next
MsgBox(64,"Navigateur " & $version, "La liste : " & $linktosupress & " a été supprimée")
EndIf
EndIf
EndFunc
func charger_combo()
$comboread=GUICtrlRead($combo1)
$filelink= @scriptdir & "\" & $comboread & ".link"
for $i = 7 to 37 step 2
$link = IniRead($filelink,"bouton" & $i , "label","erreur")
GUICtrlSetData($i,$link)
Next
EndFunc
Func SpecialEvents()
Exit
EndFunc
func valider_guiquestion()
GUISetState(@SW_HIDE, $gui_question)
GUISwitch($Form1)
Faislien($flagbutton, $flagbouton, $flag)
;MsgBox(0,"TEST","La case cochée est : " & $flag,2)
EndFunc
; correspond au bouton situé a sa doite qui permet de refaire un lien
func reset_pressed()
$flagbutton=@GUI_CtrlId -1 ; Correspondance avec la variable du bouton
$flagbouton="bouton" & @GUI_CtrlId -1
GUISwitch($gui_question)
GUISetState(@SW_SHOW, $gui_question)
GUISetOnEvent($GUI_EVENT_CLOSE, "LinkCreateEvents")
EndFunc
func libre_pressed()
$flagbutton=@GUI_CtrlId ; Correspondance avec la variable du bouton
$flagbouton="bouton"& @GUI_CtrlId
GUISwitch($gui_question)
GUISetState(@SW_SHOW, $gui_question)
GUISetOnEvent($GUI_EVENT_CLOSE, "LinkCreateEvents")
EndFunc
Func link_pressed()
$flagbutton=@GUI_CtrlId ; Correspondance avec la variable du bouton
$flagbouton="bouton"& @GUI_CtrlId
exec($flagbutton,$flagbouton)
EndFunc
func LinkCreateEvents()
GUISetState(@SW_HIDE, $gui_question)
GUISwitch($Form1)
EndFunc
Func _IsChecked($control) ;Fonction pour voir si la checkbox est cochée
Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
EndFunc
; permet de n'avoir qu'une seule case cochée à la fois
Func check_dossier()
GUICtrlSetState($checkbox_Fichier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_internet,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_nothing,$GUI_UNCHECKED)
$flag= "dossier"
EndFunc
func check_fichier()
GUICtrlSetState($checkbox_dossier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_internet,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_nothing,$GUI_UNCHECKED)
$flag="fichier"
EndFunc
func check_internet()
GUICtrlSetState($checkbox_Fichier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_dossier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_nothing,$GUI_UNCHECKED)
$flag="internet"
EndFunc
func check_nothing()
GUICtrlSetState($checkbox_Fichier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_internet,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_dossier,$GUI_UNCHECKED)
$flag="Suppression"
EndFunc
Func exec($button,$section); la fonction qui permet de lancer le programme associé au bouton
$label_bouton=IniRead($filelink,$section,"label","")
if $label_bouton="Libre" Then
libre_pressed()
else
$bouton_file=IniRead($filelink,$section,"link","")
ShellExecute($bouton_file)
EndIf
EndFunc
func Faislien($Button,$section,$lien=""); Une fonction qui gère le bouton "..." de création du label sur son copain de gauche $button= le nom de la variable $buttonx, $section le nom de la section "boutonx" dans le fichier ini
if $lien= "fichier" Then
$choose = FileOpenDialog("Selectionner un fichier",@DesktopCommonDir ,"tous les fichiers (*.*)"); gestion de la selection du fichier
if @error <> 0 Then ; marche arrière ! (appui sur cancel)
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
$reponse = InputBox("Nom du lien","Nommez le bouton !","Le nom ici"); quel label aura le raccourcis
if @error = 1 Then ; (appui sur cancel)
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
iniwrite($filelink,$section,"label",$reponse); tout est ok on peut ecrire la valeur dans le fichier de config
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton); et l'afficher
IniWrite($filelink,$section,"link", $choose); on peut ecrire le chemin du fichier dans la configuration
EndIf
$lien=""
EndIf
Elseif $lien="dossier" Then
$choose=FileSelectFolder("Choisessez un dossier", "c:\") ; on fais la même chose avec le dossier
if @error <> 0 Then
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
$reponse = InputBox("Nom du lien","Nommez le bouton !","Le nom ici")
if @error = 1 Then
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
iniwrite($filelink,$section,"label",$reponse)
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
IniWrite($filelink,$section,"link", $choose)
EndIf
EndIf
ElseIf $lien="internet" Then
$choose = InputBox("Lien Internet","Ecrivez ou collez le lien","http://")
if @error <> 0 Then
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
$reponse = InputBox("Nom du lien","Nommez le bouton !","Le nom ici")
if @error = 1 Then
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
iniwrite($filelink,$section,"label",$reponse)
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
IniWrite($filelink,$section,"link", $choose)
EndIf
EndIf
ElseIf $lien="Suppression" Then
iniwrite($filelink,$section,"label","libre")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
IniWrite($filelink,$section,"link", "libre")
EndIf
$lien=""
EndFunc
Func _ChooseColorRGB($iColorRef = 0, $hWndOwnder = 0)
Local $tcc, $tChoose, $color_picked, $iResult
$tChoose = DllStructCreate($tagCHOOSECOLOR)
$tcc = DllStructCreate("int[16]")
$iColorRef = Hex(String($iColorRef), 6)
$iColorRef = '0x' & StringMid($iColorRef, 5, 2) & StringMid($iColorRef, 3, 2) & StringMid($iColorRef, 1, 2)
DllStructSetData($tChoose, "Size", DllStructGetSize($tChoose))
DllStructSetData($tChoose, "hWndOwnder", $hWndOwnder)
DllStructSetData($tChoose, "rgbResult", $iColorRef)
DllStructSetData($tChoose, "CustColors", DllStructGetPtr($tcc))
DllStructSetData($tChoose, "Flags", BitOR($__MISCCONSTANT_CC_ANYCOLOR, $__MISCCONSTANT_CC_FULLOPEN, $__MISCCONSTANT_CC_RGBINIT))
$iResult = DllCall("comdlg32.dll", "long", "ChooseColor", "ptr", DllStructGetPtr($tChoose))
$color_picked = Hex(String(DllStructGetData($tChoose, "rgbResult")), 6)
Return '0x' & StringMid($color_picked, 5, 2) & StringMid($color_picked, 3, 2) & StringMid($color_picked, 1, 2)
EndFunc
While 1
Sleep(10)
WEnd
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <file.au3>
#include <Misc.au3>
global $flag, $flagbutton, $flagbouton
#Region ### START Koda GUI section ### Form=
;Opt("GUICoordMode", 2)
$fileini = @ScriptDir & "\confnaviv3.ini" ; déclaration du fichier ini
$version="V3.1" ; version du programme
;------------------------- recherche d'un fichier de lien
$search = FileFindFirstFile(@ScriptDir & "\*.link")
if $search = -1 Then ; si aucun lien on va demander à créer une liste
$nomfichier = InputBox("Navigateur " & $version, "Veuillez donner un nom à votre première liste" & @CRLF & "Exemple : 'Mes raccourcis' ")
$filelink = @ScriptDir & "\" & $nomfichier & ".link"
for $i = 7 to 37 step 2
IniWriteSection($filelink,"bouton" & $i,"label=Libre" & @crlf & "link=")
Next
Else
$filelink= @ScriptDir & "\" & FileFindNextFile($search)
EndIf
Global $arraylink=_FileListToArray(@ScriptDir & "\","*.link"); recherche de tous les fichiers de liens pour alimenter le combo
if not FileExists($fileini) Then ; si le fichier ini n'existe pas on le crée
filewrite(".\confnaviv3.ini","Fichier de configuration du navigateur " & $version & " - Marc graziani")
IniWriteSection($fileini,"option","couleur=0x52B5A9")
FileClose($fileini)
EndIf
;----------------------------initialisation des boutons de raccourcis
$label_bouton7=IniRead($filelink,"bouton7","label","")
$label_bouton9=IniRead($filelink,"bouton9","label","")
$label_bouton11=IniRead($filelink,"bouton11","label","")
$label_bouton13=IniRead($filelink,"bouton13","label","")
$label_bouton15=IniRead($filelink,"bouton15","label","")
$label_bouton17=IniRead($filelink,"bouton17","label","")
$label_bouton19=IniRead($filelink,"bouton19","label","")
$label_bouton21=IniRead($filelink,"bouton21","label","")
$label_bouton23=IniRead($filelink,"bouton23","label","")
$label_bouton25=IniRead($filelink,"bouton25","label","")
$label_bouton27=IniRead($filelink,"bouton27","label","")
$label_bouton29=IniRead($filelink,"bouton29","label","")
$label_bouton31=IniRead($filelink,"bouton31","label","")
$label_bouton33=IniRead($filelink,"bouton33","label","")
$label_bouton35=IniRead($filelink,"bouton35","label","")
$label_bouton37=IniRead($filelink,"bouton37","label","")
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)
;--------------------------mise en place de l'interface graphique
$Form1 = GUICreate("Navigateur " & $version, 448, 609, 192, 124)
GUISetBkColor(IniRead($fileini,"option","couleur","0x52B5A9"))
$MenuItem1 = GUICtrlCreateMenu("&Menu")
$MenuItem3 = GUICtrlCreateMenuItem("Nouveau", $MenuItem1)
GUICtrlSetOnEvent(-1, "_ajouter")
$MenuItem4 = GUICtrlCreateMenuItem("Supprimer Liste", $MenuItem1)
GUICtrlSetOnEvent(-1, "_suppression")
$MenuItem2 = GUICtrlCreateMenuitem("&Couleur", $MenuItem1)
GUICtrlSetOnEvent(-1, "changer_couleur")
$button7= GUICtrlCreateButton($label_bouton7, 24, 112, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button8= GUICtrlCreateButton("... ", 168, 112, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button9 = GUICtrlCreateButton($label_bouton9, 25, 162, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button10 = GUICtrlCreateButton("...", 169, 162, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button11 = GUICtrlCreateButton($label_bouton11, 26, 217, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button12 = GUICtrlCreateButton("...", 170, 217, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button13 = GUICtrlCreateButton($label_bouton13, 26, 272, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button14 = GUICtrlCreateButton("...", 170, 272, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button15 = GUICtrlCreateButton($label_bouton15, 26, 328, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button16 = GUICtrlCreateButton("...", 170, 328, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button17 = GUICtrlCreateButton($label_bouton17, 26, 385, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button18 = GUICtrlCreateButton("...", 170, 385, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button19 = GUICtrlCreateButton($label_bouton19, 26, 441, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button20 = GUICtrlCreateButton("...", 170, 441, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button21 = GUICtrlCreateButton($label_bouton21, 26, 497, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button22 = GUICtrlCreateButton("...", 170, 497, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button23= GUICtrlCreateButton($label_bouton23, 254, 112, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button24= GUICtrlCreateButton("...", 398, 112, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button25 = GUICtrlCreateButton($label_bouton25, 255, 162, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button26 = GUICtrlCreateButton("...", 399, 162, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button27 = GUICtrlCreateButton($label_bouton27, 256, 217, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button28 = GUICtrlCreateButton("...", 400, 217, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button29 = GUICtrlCreateButton($label_bouton29, 256, 272, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button30 = GUICtrlCreateButton("...", 400, 272, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button31= GUICtrlCreateButton($label_bouton31, 256, 328, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button32 = GUICtrlCreateButton("...", 400, 328, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$Button33 = GUICtrlCreateButton($label_bouton33, 256, 385, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button34 = GUICtrlCreateButton("...", 400, 385, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button35= GUICtrlCreateButton($label_bouton35, 256, 441, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button36 = GUICtrlCreateButton("...", 400, 441, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$button37 = GUICtrlCreateButton($label_bouton37, 256, 497, 145, 41,$BS_MULTILINE)
GUICtrlSetOnEvent(-1, "link_pressed")
$button38 = GUICtrlCreateButton("...", 400, 497, 17, 41)
GUICtrlSetOnEvent(-1, "reset_pressed")
$Combo1 = GUICtrlCreateCombo( "Selectionnez une liste de raccourcis", 64, 40, 233, 30, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetOnEvent(-1, "charger_combo")
$Button33 = GUICtrlCreateButton("-", 320, 40, 30, 30,$BS_ICON)
GUICtrlSetOnEvent(-1, "_suppression")
$Button34 = GUICtrlCreateButton("+", 360, 40, 30, 30,$BS_ICON)
GUICtrlSetOnEvent(-1, "_ajouter")
$MenuItem5 = GUICtrlCreateMenu("A&ide")
$MenuItem6 = GUICtrlCreateMenuItem("A &propos", $MenuItem5)
GUICtrlSetOnEvent(-1, "apropos")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
;-----------------------------alimentation du combo
For $i=1 To Ubound($arraylink)-1
$name=stringsplit($arraylink[$i],".")
;_ArrayDisplay($name)
GUICtrlSetData($Combo1,$name[1])
Next
GUICtrlSetData($Combo1,$name[1]); affichage de la liste dans le combo
charger_combo(); lecture de la liste à l'ouverture
GUISetState(@SW_SHOW)
;-----------------------------creation de la gui question
$gui_question = GUICreate("NAVIGATEUR "& $version & " Création du lien" ,650,100)
$checkbox_internet = GUICtrlCreateCheckbox("Lien Internet", 10, 30, 120, 40)
GUICtrlSetOnEvent(-1, "check_internet")
$checkbox_Fichier= GUICtrlCreateCheckbox("Lien vers fichier", 150, 30, 120, 40)
GUICtrlSetOnEvent(-1, "check_fichier")
$checkbox_dossier= GUICtrlCreateCheckbox("Lien vers dossier", 300, 30, 120, 40)
GUICtrlSetOnEvent(-1, "check_dossier")
$checkbox_nothing=GUICtrlCreateCheckbox("Supprimer lien", 450, 30,120,40)
GUICtrlSetOnEvent(-1, "check_nothing")
$btn1 = GUICtrlCreateButton("Valider", 560, 60, 80)
GUICtrlSetOnEvent(-1, "valider_guiquestion")
guictrlcreatelabel("Ajout, Suppression ou Modification d'un raccourcis...",10,5)
GUISwitch($Form1)
#EndRegion ### END Koda GUI section ###
;----------------------fonctions
Func changer_couleur()
;msgbox(0,"","")
$couleur = _ChooseColorRGB()
GUICtrlSetData($Form1,GUISetBkColor($couleur))
IniWrite($fileini,"option","couleur", $couleur)
EndFunc
func apropos()
Msgbox(4096,"A propos...","Navigateur "& "version : " & $version & @CRLF & "Concept & develloppement : Marc GRAZIANI")
EndFunc
; ---------------------------permet d'ajouter de listes dans le programme
Func _ajouter()
$nomfichier = InputBox("Navigateur " & $version, "Veuillez donner un nom à cette liste" & @CRLF & "Exemple : 'Raccourcis ministère' ")
if @error <> 0 then Return
;msgbox(0,"debug", "check nom fichier : " & _CheckForbidden($nomfichier))
if _CheckForbidden($nomfichier) <>0 Then
msgbox (64,"Navigateur " & $version, "Erreur, le nom comporte des caractères interdits :"& @CRLF & '["/\\*?<>|:]')
Return
EndIf
$filelink = @ScriptDir & "\" & $nomfichier & ".link"
if FileFindFirstFile($filelink) <> -1 Then ; test si le fichier existe si - 1 rien est trouvé
local $messagefile = msgbox(4,"Navigateur " & $version, "Un fichier portant le même nom existe déjà " & @CRLF & " Voulez vous l'ecraser ?")
if $messagefile = 6 Then
ecrireFichier($filelink)
MsgBox(64,"Navigateur " & $version, "La liste : " & $nomfichier & " a été ajoutée")
Else
Return
EndIf
Else
ecrireFichier($filelink)
MsgBox(64,"Navigateur " & $version, "La liste : " & $nomfichier & " a été ajoutée")
EndIf
EndFunc
func ecrireFichier($nomfichier)
for $i = 7 to 37 step 2
IniWriteSection($nomfichier,"bouton" & $i,"label=Libre" & @crlf & "link=")
Next
GUICtrlSetData($combo1,"")
$arraylink=""
$arraylink=_FileListToArray(@ScriptDir & "\","*.link")
For $i=1 To Ubound($arraylink)-1
$name=stringsplit($arraylink[$i],".")
GUICtrlSetData($Combo1,$name[1])
Next
EndFunc
Func _CheckForbidden($string)
Local $pattern_forbid = '["/\\*?<>|:]'
Return StringRegExp($string, $pattern_forbid)
EndFunc
func _suppression()
$linktosupress = GUICtrlRead($combo1)
if $linktosupress == "Selectionnez une liste de raccourcis" then
MsgBox(64,"Navigateur " & $version, "Vous ne pouvez pas supprimer cet item")
Else
$file2supress = @scriptdir & "\" & $linktosupress & ".link"
$message = msgbox(1, "Navigateur " & $version, "Etes vous sur de vouloir supprimer la liste : " & @CRLF & $linktosupress )
if $message = $IDOK Then
FileDelete($file2supress)
GUICtrlSetData($combo1,"")
$arraylink=""
$arraylink=_FileListToArray(@ScriptDir & "\","*.link")
For $i=1 To Ubound($arraylink)-1
$name=stringsplit($arraylink[$i],".")
GUICtrlSetData($Combo1,$name[1])
Next
MsgBox(64,"Navigateur " & $version, "La liste : " & $linktosupress & " a été supprimée")
EndIf
EndIf
EndFunc
func charger_combo()
$comboread=GUICtrlRead($combo1)
$filelink= @scriptdir & "\" & $comboread & ".link"
for $i = 7 to 37 step 2
$link = IniRead($filelink,"bouton" & $i , "label","erreur")
GUICtrlSetData($i,$link)
Next
EndFunc
Func SpecialEvents()
Exit
EndFunc
func valider_guiquestion()
GUISetState(@SW_HIDE, $gui_question)
GUISwitch($Form1)
Faislien($flagbutton, $flagbouton, $flag)
;MsgBox(0,"TEST","La case cochée est : " & $flag,2)
EndFunc
; correspond au bouton situé a sa doite qui permet de refaire un lien
func reset_pressed()
$flagbutton=@GUI_CtrlId -1 ; Correspondance avec la variable du bouton
$flagbouton="bouton" & @GUI_CtrlId -1
GUISwitch($gui_question)
GUISetState(@SW_SHOW, $gui_question)
GUISetOnEvent($GUI_EVENT_CLOSE, "LinkCreateEvents")
EndFunc
func libre_pressed()
$flagbutton=@GUI_CtrlId ; Correspondance avec la variable du bouton
$flagbouton="bouton"& @GUI_CtrlId
GUISwitch($gui_question)
GUISetState(@SW_SHOW, $gui_question)
GUISetOnEvent($GUI_EVENT_CLOSE, "LinkCreateEvents")
EndFunc
Func link_pressed()
$flagbutton=@GUI_CtrlId ; Correspondance avec la variable du bouton
$flagbouton="bouton"& @GUI_CtrlId
exec($flagbutton,$flagbouton)
EndFunc
func LinkCreateEvents()
GUISetState(@SW_HIDE, $gui_question)
GUISwitch($Form1)
EndFunc
Func _IsChecked($control) ;Fonction pour voir si la checkbox est cochée
Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
EndFunc
; permet de n'avoir qu'une seule case cochée à la fois
Func check_dossier()
GUICtrlSetState($checkbox_Fichier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_internet,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_nothing,$GUI_UNCHECKED)
$flag= "dossier"
EndFunc
func check_fichier()
GUICtrlSetState($checkbox_dossier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_internet,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_nothing,$GUI_UNCHECKED)
$flag="fichier"
EndFunc
func check_internet()
GUICtrlSetState($checkbox_Fichier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_dossier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_nothing,$GUI_UNCHECKED)
$flag="internet"
EndFunc
func check_nothing()
GUICtrlSetState($checkbox_Fichier,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_internet,$GUI_UNCHECKED)
GUICtrlSetState($checkbox_dossier,$GUI_UNCHECKED)
$flag="Suppression"
EndFunc
Func exec($button,$section); la fonction qui permet de lancer le programme associé au bouton
$label_bouton=IniRead($filelink,$section,"label","")
if $label_bouton="Libre" Then
libre_pressed()
else
$bouton_file=IniRead($filelink,$section,"link","")
ShellExecute($bouton_file)
EndIf
EndFunc
func Faislien($Button,$section,$lien=""); Une fonction qui gère le bouton "..." de création du label sur son copain de gauche $button= le nom de la variable $buttonx, $section le nom de la section "boutonx" dans le fichier ini
if $lien= "fichier" Then
$choose = FileOpenDialog("Selectionner un fichier",@DesktopCommonDir ,"tous les fichiers (*.*)"); gestion de la selection du fichier
if @error <> 0 Then ; marche arrière ! (appui sur cancel)
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
$reponse = InputBox("Nom du lien","Nommez le bouton !","Le nom ici"); quel label aura le raccourcis
if @error = 1 Then ; (appui sur cancel)
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
iniwrite($filelink,$section,"label",$reponse); tout est ok on peut ecrire la valeur dans le fichier de config
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton); et l'afficher
IniWrite($filelink,$section,"link", $choose); on peut ecrire le chemin du fichier dans la configuration
EndIf
$lien=""
EndIf
Elseif $lien="dossier" Then
$choose=FileSelectFolder("Choisessez un dossier", "c:\") ; on fais la même chose avec le dossier
if @error <> 0 Then
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
$reponse = InputBox("Nom du lien","Nommez le bouton !","Le nom ici")
if @error = 1 Then
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
iniwrite($filelink,$section,"label",$reponse)
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
IniWrite($filelink,$section,"link", $choose)
EndIf
EndIf
ElseIf $lien="internet" Then
$choose = InputBox("Lien Internet","Ecrivez ou collez le lien","http://")
if @error <> 0 Then
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
$reponse = InputBox("Nom du lien","Nommez le bouton !","Le nom ici")
if @error = 1 Then
IniRead($filelink,$section,"label","")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
Else
iniwrite($filelink,$section,"label",$reponse)
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
IniWrite($filelink,$section,"link", $choose)
EndIf
EndIf
ElseIf $lien="Suppression" Then
iniwrite($filelink,$section,"label","libre")
$label_bouton=IniRead($filelink,$section,"label","")
GUICtrlSetData($Button, $label_bouton)
IniWrite($filelink,$section,"link", "libre")
EndIf
$lien=""
EndFunc
Func _ChooseColorRGB($iColorRef = 0, $hWndOwnder = 0)
Local $tcc, $tChoose, $color_picked, $iResult
$tChoose = DllStructCreate($tagCHOOSECOLOR)
$tcc = DllStructCreate("int[16]")
$iColorRef = Hex(String($iColorRef), 6)
$iColorRef = '0x' & StringMid($iColorRef, 5, 2) & StringMid($iColorRef, 3, 2) & StringMid($iColorRef, 1, 2)
DllStructSetData($tChoose, "Size", DllStructGetSize($tChoose))
DllStructSetData($tChoose, "hWndOwnder", $hWndOwnder)
DllStructSetData($tChoose, "rgbResult", $iColorRef)
DllStructSetData($tChoose, "CustColors", DllStructGetPtr($tcc))
DllStructSetData($tChoose, "Flags", BitOR($__MISCCONSTANT_CC_ANYCOLOR, $__MISCCONSTANT_CC_FULLOPEN, $__MISCCONSTANT_CC_RGBINIT))
$iResult = DllCall("comdlg32.dll", "long", "ChooseColor", "ptr", DllStructGetPtr($tChoose))
$color_picked = Hex(String(DllStructGetData($tChoose, "rgbResult")), 6)
Return '0x' & StringMid($color_picked, 5, 2) & StringMid($color_picked, 3, 2) & StringMid($color_picked, 1, 2)
EndFunc
While 1
Sleep(10)
WEnd