Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

Wallpaper.cs

Description du code

Wallpaper.cs est un fichier du projet PhotoBrol.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/photobrol/.

Projet PhotoBrol :

Editeur d'images en CSharp.

Code source ou contenu du fichier

  1. // Wallpaper.cs - Une classe pour afficher un fond d'écran sous Windows
  2. // Conçue et réalisée par Gulix
  3. // Contact : gulix33xp@yahoo.fr - http://gulix.free.fr
  4. // Pour plus d'informations, lire le fichier d'informations fourni avec la classe
  5.  
  6.  
  7. using System;
  8. using System.Drawing;
  9. using System.Collections;
  10. using System.ComponentModel;
  11. using System.Windows.Forms;
  12. using System.Runtime.InteropServices;
  13. using System.IO;
  14. using System.Data;
  15. using Microsoft.Win32;
  16.  
  17. public class Wallpaper
  18. {
  19. // Variables et Fonctions nécessaires à l'affichage du Wallpaper
  20. const int SPI_SETDESKWALLPAPER = 20;
  21. const int SPIF_UPDATEINIFILE = 0x01;
  22. const int SPIF_SENDWININICHANGE = 0x02;
  23. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  24. static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
  25. [DllImport("user32.dll")]
  26. public static extern void SetSysColors(int elementCount, int[] colorNames, int[] colorValues);
  27.  
  28. // Enumération permettant de fixer le style d'affichage
  29. public enum Affichage
  30. {
  31. centrer,
  32. mosaïque,
  33. etirer,
  34. ajuster
  35. }
  36.  
  37. // On déclare les membres
  38. private string nomfichier;
  39. private Affichage affichage; // Style d'affichage
  40. private System.Drawing.Color couleurFond; // Couleur de fond du bureau
  41.  
  42. // Constructeur de la classe Wallpaper
  43. public Wallpaper(string fichier, Affichage affich, Color fond)
  44. {
  45. this.nomfichier = fichier;
  46. this.affichage = affich;
  47. this.couleurFond = fond;
  48. }
  49.  
  50. // GetNomCourt
  51. // permet de retrouver le nom du fichier, sans son chemin complet
  52. public string GetNomCourt()
  53. {
  54. string[] split;
  55. char[] separateur ={ '\\' };
  56. int max;
  57. split = this.nomfichier.Split(separateur);
  58. max = split.GetUpperBound(0);
  59. return split[max];
  60. }
  61.  
  62. // GetRepertoire
  63. // permet de retrouver le repertoire contenant l'image
  64. public string GetRepertoire()
  65. {
  66. string[] split;
  67. string[] join;
  68. char[] separateur ={ '\\' };
  69. int max;
  70. split = this.nomfichier.Split(separateur);
  71. max = split.GetUpperBound(0);
  72. join = new string[max];
  73. for (int i = 0; i < (max); i++)
  74. {
  75. join[i] = split[i];
  76. }
  77. return String.Join("\\", join) + "\\";
  78. }
  79.  
  80.  
  81. // GetImageHauteur
  82. // permet d'obtenir la hauteur du fichier image, en pixels
  83. public int GetImageHauteur()
  84. {
  85. int retour = 0;
  86. try
  87. {
  88. Image image = new Bitmap(this.nomfichier);
  89. retour = image.Height;
  90. }
  91. catch
  92. {
  93. retour = -1;
  94. }
  95. return retour;
  96. }
  97.  
  98. // GetImageLargeur
  99. // permet d'obtenir la largeur du fichier image, en pixels
  100. public int GetImageLargeur()
  101. {
  102. int retour = 0;
  103. try
  104. {
  105. Image image = new Bitmap(this.nomfichier);
  106. retour = image.Width;
  107. }
  108. catch
  109. {
  110. retour = -1;
  111. }
  112. return retour;
  113. }
  114.  
  115. /// <summary>
  116. /// Modify wallpaper and desktop's background color
  117. /// </summary>
  118. /// <returns>True if no problems occurs</returns>
  119. public bool Afficher()
  120. {
  121. try
  122. {
  123. // On recopie l'image dans les fichiers temporaires au format bitmap
  124. System.Drawing.Image image;
  125. if (this.affichage == Affichage.ajuster)
  126. {
  127. image = System.Drawing.Image.FromFile(this.Ajustement());
  128. }
  129. else
  130. {
  131. image = System.Drawing.Image.FromFile(this.GetRepertoire() + this.GetNomCourt());
  132. }
  133. string fichierTemporaire = Path.Combine(Path.GetTempPath(), "wallpaper.bmp");
  134. image.Save(fichierTemporaire, System.Drawing.Imaging.ImageFormat.Bmp);
  135.  
  136. // On modifie le style d'affichage dans la base de registre
  137. RegistryKey cle = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
  138. if (this.affichage == Affichage.etirer)
  139. {
  140. cle.SetValue(@"WallpaperStyle", 2.ToString());
  141. cle.SetValue(@"TileWallpaper", 0.ToString());
  142. }
  143.  
  144. if (this.affichage == Affichage.centrer)
  145. {
  146. cle.SetValue(@"WallpaperStyle", 1.ToString());
  147. cle.SetValue(@"TileWallpaper", 0.ToString());
  148. }
  149.  
  150. if (this.affichage == Affichage.mosaïque)
  151. {
  152. cle.SetValue(@"WallpaperStyle", 1.ToString());
  153. cle.SetValue(@"TileWallpaper", 1.ToString());
  154. }
  155.  
  156. if (this.affichage == Affichage.ajuster)
  157. {
  158. cle.SetValue(@"WallpaperStyle", 1.ToString());
  159. cle.SetValue(@"TileWallpaper", 0.ToString());
  160. }
  161.  
  162. // On utilise les fonctions de la DLL user32 pour afficher le wallpaper
  163. SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, fichierTemporaire, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
  164. int[] elementArray = { 1 };
  165. int[] elementValues = { ColorTranslator.ToWin32(this.GetCouleurFond()) };
  166. // et modifier la couleur de fond du bureau
  167. SetSysColors(1, elementArray, elementValues);
  168. return true;
  169. }
  170. catch
  171. {
  172. return false;
  173. }
  174. }
  175.  
  176. // GetEcranLargeur
  177. // permet d'obtenir la largeur de l'écran
  178. public static int GetEcranLargeur()
  179. {
  180. return System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
  181. }
  182.  
  183. // GetEcranHauteur
  184. // permet d'obtenir la hauteur de l'écran
  185. public static int GetEcranHauteur()
  186. {
  187. return System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
  188. }
  189.  
  190. // Ajustement
  191. // Réalise l'ajustement de l'image si nécessaire
  192. // retourne le chemin vers le fichier ajusté
  193. private string Ajustement()
  194. {
  195. string fichierRetour;
  196. if ((this.GetImageHauteur() <= GetEcranHauteur()) && (this.GetImageLargeur() <= GetEcranLargeur()))
  197. {
  198. // Pas d'ajustement nécessaire, on retourne le nom du fichier original
  199. fichierRetour = this.nomfichier;
  200. }
  201. else
  202. {
  203. // On calcule les nouvelles dimensions
  204. double ratio = ((double)GetEcranHauteur()) / ((double)this.GetImageHauteur());
  205. if (ratio > (((double)GetEcranLargeur()) / ((double)this.GetImageLargeur())))
  206. {
  207. ratio = ((double)GetEcranLargeur()) / ((double)this.GetImageLargeur());
  208. }
  209. int nouvelleLargeur = (int)(((double)this.GetImageLargeur()) * ratio);
  210. int nouvelleHauteur = (int)(((double)this.GetImageHauteur()) * ratio);
  211.  
  212. // On crée le support de la nouvelle image
  213. System.Drawing.Size tailleAjuster = new Size(nouvelleLargeur, nouvelleHauteur);
  214. System.Drawing.Image imageAjuster = null;
  215.  
  216. // On crée la nouvelle image à partir de l'original, et de la nouvelle taille
  217. imageAjuster = new Bitmap(Image.FromFile(this.nomfichier), tailleAjuster);
  218. imageAjuster.Save(Path.Combine(Path.GetTempPath(), "ajuster.bmp"), System.Drawing.Imaging.ImageFormat.Bmp);
  219. imageAjuster.Dispose();
  220. fichierRetour = Path.Combine(Path.GetTempPath(), "ajuster.bmp");
  221. }
  222. return fichierRetour;
  223. }
  224.  
  225. // Méthodes d'accès aux paramètres
  226. // permet de limiter l'accès aux paramètres
  227. public Affichage GetAffichage()
  228. {
  229. return this.affichage;
  230. }
  231. public void SetAffichage(Affichage aff)
  232. {
  233. this.affichage = aff;
  234. }
  235. public Color GetCouleurFond()
  236. {
  237. return this.couleurFond;
  238. }
  239. public void SetCouleurFond(Color col)
  240. {
  241. this.couleurFond = col;
  242. }
  243.  
  244. public override string ToString()
  245. {
  246. return this.GetNomCourt();
  247. }
  248.  
  249. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/photobrol/model/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1714322595 28/04/2024 18:43:15
| _filters0 octets1541007171 31/10/2018 18:32:51
| _math0 octets1541007171 31/10/2018 18:32:51
| _Image0 octets1541007171 31/10/2018 18:32:51
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/photobrol/model/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csWallpaper.cs8.86 Ko31/10/2018 18:32:23-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 30/10/2009, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/cs-photobrol-source-rf-model/Wallpaper.cs.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.