Outils pour utilisateurs

Outils du site


lang:csharp:ihm:commun

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
lang:csharp:ihm:commun [2016/11/21 18:20] – Création avec "Affiche un MessageBox sans bloquer la suite du process" rootlang:csharp:ihm:commun [2020/04/26 23:27] (Version actuelle) – Conversion de <note> vers <WRAP> root
Ligne 1: Ligne 1:
 +[[lang:csharp:ihm:commun:custom|Personnaliser un composant]]
 +
 =====Affiche un MessageBox sans bloquer la suite du process===== =====Affiche un MessageBox sans bloquer la suite du process=====
 Vive le thread tout simplement. Facilement adaptable à n'importe quelle autre action. Vive le thread tout simplement. Facilement adaptable à n'importe quelle autre action.
Ligne 5: Ligne 7:
 { {
   MessageBox.Show("Je ne bloque pas.", "Titre", MessageBoxButtons.OK, MessageBoxIcon.Warning);   MessageBox.Show("Je ne bloque pas.", "Titre", MessageBoxButtons.OK, MessageBoxIcon.Warning);
-})).Start();+} 
 +)).Start();
 </code> </code>
 +
 +Pour forcer la MessageBox à rester au dessus de l'application, il faut ajouter le paramètre ''MB_TOPMOST'' :
 +
 +<code csharp>
 +MessageBox.Show("Je ne bloque pas.", "Titre", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);
 +</code>
 +
 +[[https://stackoverflow.com/questions/24010280/messagebox-on-top-of-splashscreen|messagebox on top of splashscreen]] {{ :lang:csharp:ihm:commun:c_-_messagebox_on_top_of_splashscreen_-_stack_overflow_2020-04-26_11_24_57_pm_.html |Archive du 03/06/2014 le 26/04/2020}}
 +
 +=====Barre de progression dans la barre des tâches=====
 +<file java TaskbarProgress.java>
 +using System;
 +using System.Runtime.InteropServices;
 +
 +public static class TaskbarProgress
 +{
 +  public enum TaskbarStates
 +  {
 +    NoProgress = 0,
 +    Indeterminate = 0x1,
 +    Normal = 0x2,
 +    Error = 0x4,
 +    Paused = 0x8
 +  }
 +
 +  [ComImport()]
 +  [Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
 +  [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
 +  private interface ITaskbarList3
 +  {
 +    // ITaskbarList
 +    [PreserveSig]
 +    void HrInit();
 +    [PreserveSig]
 +    void AddTab(IntPtr hwnd);
 +    [PreserveSig]
 +    void DeleteTab(IntPtr hwnd);
 +    [PreserveSig]
 +    void ActivateTab(IntPtr hwnd);
 +    [PreserveSig]
 +    void SetActiveAlt(IntPtr hwnd);
 +
 +    // ITaskbarList2
 +    [PreserveSig]
 +    void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
 +
 +    // ITaskbarList3
 +    [PreserveSig]
 +    void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
 +    [PreserveSig]
 +    void SetProgressState(IntPtr hwnd, TaskbarStates state);
 +  }
 +
 +  [Guid("56FDF344-FD6D-11d0-958A-006097C9A090")]
 +  [ClassInterface(ClassInterfaceType.None)]
 +  [ComImport()]
 +  private class TaskbarInstance
 +  {
 +  }
 +
 +  private static ITaskbarList3 taskbarInstance = (ITaskbarList3)new TaskbarInstance();
 +
 +  public static void SetState(IntPtr windowHandle, TaskbarStates taskbarState)
 +  {
 +    taskbarInstance.SetProgressState(windowHandle, taskbarState);
 +  }
 +
 +  public static void SetValue(IntPtr windowHandle, double progressValue, double progressMax)
 +  {
 +    taskbarInstance.SetProgressValue(windowHandle, (ulong)progressValue, (ulong)progressMax);
 +  }
 +}
 +</file>
 +et son utilisation
 +<code java>
 +private static bool taskbarSupported = Environment.OSVersion.Version >= new Version(6, 1);
 +
 +if (taskbarSupported)
 +{
 +  // Utilisation
 +  TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Normal);
 +  TaskbarProgress.SetValue(Handle, toolStripProgressBar1.Value, toolStripProgressBar1.Maximum);
 +
 +  // Désactivation
 +  TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress);
 +}
 +</code>
 +
 +[[https://stackoverflow.com/questions/1295890/windows-7-progress-bar-in-taskbar-in-c|Windows 7 progress bar in taskbar in C#?]] {{ :lang:csharp:ihm:commun:windows_7_progress_bar_in_taskbar_in_c_-_stack_overflow_2020-04-26_11_26_40_pm_.html |Archive du 18/08/2009 le 26/04/2020}}
 +
 +<WRAP center round important 60%>
 +Il n'est pas possible d'utiliser ''taskbarSupported'' depuis la classe ''TaskbarProgress'' (comme l'exemple de ''StackOverFlow'' le fait).
 +
 +Si un élément de cette classe est exécuté, le constructeur privé l'est aussi à cause de la variable ''static'', ce qui entraîne une exception de type ''TypeInitializationException'' sous Windows XP et sous Windows Vista.
 +</WRAP>
 +
lang/csharp/ihm/commun.1479748834.txt.gz · Dernière modification : 2016/11/21 18:20 de root