1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#################################################################
# Chargement des Librairies #
#################################################################
[Reflection.Assembly]::LoadWithPartialName("PresentationFramework")
[Reflection.Assembly]::LoadWithPartialName("PresentationCore")
[Reflection.Assembly]::LoadWithPartialName("WindowsBase")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#################################################################
#----------------------------------------------------------------
# Déclaration des variables #
#----------------------------------------------------------------
$ofs = "`r`n"
$tab = @()
$tab += "First.tdb"
$tab += "Second.tdb"
$memo = "Champ vide. Selectionner un repertoire"
#----------------------------------------------------------------
#-----------------------------------------------------------------------------------------
# Affectation du couple tableau + Combobox utilisé pour peupler la DropDownBox dans WPF #
#-----------------------------------------------------------------------------------------
$Dropper=$tab
#-----------------------------------------------------------------------------------------
#----------------------------------------------------------------
#Le code XAML envoyé dans une variable Powershell #
#----------------------------------------------------------------
[xml]$xaml = '
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF Powershell LangChecker" Height="300" Width="560" ResizeMode="NoResize">
<Canvas>
<ComboBox Name="MyDrop" Height="25" Width="200" Canvas.Top="10" Canvas.Left="10" >
</ComboBox>
<TextBox Height="23" HorizontalAlignment="Left" Margin="238,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="213" />
<Button Content="Parcourir" Height="23" HorizontalAlignment="Left" Margin="460,12,0,0" Name="button1" VerticalAlignment="Top" Width="65" />
<TextBox Name="Mytexte" Height="100" Width="520" Canvas.Top="40" Canvas.Left="10"
IsReadOnly="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Foreground="Blue">
Test
</TextBox>
<Button Content="Quitter" Height="23" HorizontalAlignment="Left" Margin="460,230,0,0" Name="buttonQuitter" VerticalAlignment="Top" Width="75" />
</Canvas>
</Window>
'
#--------------------------------------------------------------
#--------------------------------------------------------------
#Déclaration du code XML et de la Forms puis des systems #
#--------------------------------------------------------------
$wpf=(New-Object System.Xml.XmlNodeReader $xaml)
$Form=[Windows.Markup.XamlReader]::Load( $wpf )
$object = New-Object -comObject Shell.Application
$System = New-Object System.Windows.Forms.Form
#--------------------------------------------------------------
#--------------------------------------------------------------
# Les Fonctions
#--------------------------------------------------------------
function Select-Folder($message='Select a folder', $path = 0) {
$folder = $object.BrowseForFolder(0, $message, 0, $path)
if ($folder -ne $null) {
$LabelTextBox1.clear()
$LabelTextBox1.AppendText($folder.self.Path)
executor($folder.self.Path)
}
}
function executeProg()
{
$Output.AppendText($ofs + "Executing Threads !!!")
getSelectedItem
}
function executor($this)
{
$maVar = $this
$Output.AppendText($ofs + (get-ChildItem -recurse $maVar -include *.cpp))
$Output.AppendText($ofs + "Script finished ...")
}
function getSelectedItem()
{
$Output.AppendText($ofs + "Execution success !!!")
Select-Folder
}
#--------------------------------------------------------------
#-------------------------------------------------------------
# Récupération des contrôles WPF dans PowerShell #
#-------------------------------------------------------------
$btndrop = $Form.FindName('MyDrop')
$Output = $Form.FindName('Mytexte')
$GetFolderExist = $Form.FindName('button1')
$LabelTextBox1 = $Form.FindName('textBox1')
$boutonQuitter = $Form.FindName('buttonQuitter')
#-------------------------------------------------------------
#-------------------------------------------------------------
# Boucle sur les fichiers tdb existants #
#-------------------------------------------------------------
foreach ($i in $Dropper)
{
$btnDrop.Items.Add($i)| out-null
}
#-------------------------------------------------------------
#---------------------------------------------------------------
#Ajustons une propriété du contrôle TextBox et GetFolderExist #
#---------------------------------------------------------------
$btnDrop.ToolTip = "Sélectionnez le DropDownBox"
$GetFolderExist.ToolTip = "Select a Folder"
$LabelTextBox1.ToolTip = "Path of folder selected"
$boutonQuitter.ToolTip = "Close the window"
#---------------------------------------------------------------
#---------------------------------------------------------------
# Recupération de l'événement SelectionChanged du contrôle #
#---------------------------------------------------------------
$btnDrop.Add_SelectionChanged({$Output.AppendText($ofs + "Mes interfaces PowerShell !!!")})
$GetFolderExist.Add_Click({executeProg})
$boutonQuitter.Add_Click({$Form.Close()})
#---------------------------------------------------------------
#-------------------------------------------
# The application is starting ...
#-------------------------------------------
$Form.ShowDialog() | out-null
#------------------------------------------- |
Partager