2012-07-03 13 views
34

'u küçülttüğümde bir pencere uygulamasına sahibim. Başka bir uygulama üzerinde çalışmak için görev çubuğundaki pencere uygulamasını en aza indirgeyken. bir pencere uygulamasından başka bir pencere uygulamasına mesaj göndermek gibi bir uygulamadan başka bir pencere uygulamasınaPencere uygulaması görev çubuğunda turuncu renkte yanıp sönerken

bu yüzden ilk kazanma uygulamam en aza indirildi ve şimdi başka bir win uygulamasını açıp ilk uygulamaya mesaj gönderiyorum ancak ilk uygulama görev çubuğunda. Bu yüzden herhangi bir mesaj benim ilk uygulamayı yakaladığında, o zaman skype veya herhangi bir messenger gibi yanıp sönecek gibi işlev istiyorum.

User32.dll dosyasının "FlashWindowEx" yöntemini denedim. ama şans yok. "Pencere ön plana gelene kadar sürekli olarak Flaş" seçeneği ile denedim. ama şans yok.

örnekle

Teşekkür

benim için çalışıyor
+0

Geliş http://stackoverflow.com/questions/ bakmak flaşlar sadece şeklini değiştirmek için

this.FlashNotification(); 

aramaya gerek bir form üzerinde kullanmak için 8924556/force-window-to-blink-ne-belirli-olayı-in-a-c-sharp-wpf/8929473 # 8929473 hangi Q & A var –

cevap

22

C#: Flash Window in Taskbar via Win32 FlashWindowEx bu sorunu çözmek için yardımcı olun.

Windows API (Win32), User32 kitaplığında FlashWindowEx yöntemine sahiptir; Bu yöntem size (geliştiricinin) bir Pencereyi Flash, kullanıcıya, bazı önemli olayların dikkatini çeken uygulamasında oluştuğunu bildirmesini sağlar. Bu 'un en yaygın kullanımı, kullanıcı odağı uygulamasına geri döndürene kadar pencereyi aydınlatmaktır. Bununla birlikte, pencereyi belirli bir sayıda kez yanıp sönebilir veya ne zaman duracağınıza karar verene kadar yanıp sönmeye devam edebilirsiniz.

FlashWindowEx yönteminin kullanımı, ancak .NET Framework'ün herhangi bir yerinde yerleşik değildir. Erişmek için, .NET'in Platform Invoke (PInvoke) özelliklerini Windows API (Win32) 'a "düşürmek" ve doğrudan çağırmanız gerekir. Ayrıca, Windows API'sindeki diğer birçok işlevsellikle olduğu gibi (doğrudan .NET tarafından açığa alınmaz), FlashWindowEx yöntemi, Windows API ile çalışmaya alışkın değilseniz, kullanma konusunda biraz zor olabilir. AĞ.

Şimdi doğrusu PInvoke veya Win32 FlashWindowEx yönteminin özelliklerini inceleyeceğiz çok derin gitmek yerine, aşağıda kolayca bu yöntemi kullanmak için verir C# basit bir statik sınıftır. Aslında, Windows API'sini (Win32) kullanmak için PInvoke'u nasıl kullanacağınızı açıklamak için gereken bilgisinin birazı vardır, bu yüzden ilerideki bir makalede bunu ele alacağım.

İşte bu statik sınıfının bazı örnek kullanımı: FlashWindowEx yöntemi daha sonra (ve yalnızca üzerinde çalışacak), Windows 2000 veya gerektirdiğini yaklaşık

// One this to note with this example usage code, is the "this" keyword is referring to 
// the current System.Windows.Forms.Form. 

// Flash window until it recieves focus 
FlashWindow.Flash(this); 

// Flash window 5 times 
FlashWindow.Flash(this, 5); 

// Start Flashing "Indefinately" 
FlashWindow.Start(this); 

// Stop the "Indefinate" Flashing 
FlashWindow.Stop(this); 

Unutulmaması gereken bir şey.İşte

C# statik sınıf için kod: aşağıda gösterildiği gibi gösterildiği gibi gerekli başvuruları eklemek için emin olmak, bunu

public static class FlashWindow 
{ 
    [DllImport("user32.dll")] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    private static extern bool FlashWindowEx(ref FLASHWINFO pwfi); 

    [StructLayout(LayoutKind.Sequential)] 
    private struct FLASHWINFO 
    { 
     /// <summary> 
     /// The size of the structure in bytes. 
     /// </summary> 
     public uint cbSize; 
     /// <summary> 
     /// A Handle to the Window to be Flashed. The window can be either opened or minimized. 
     /// </summary> 
     public IntPtr hwnd; 
     /// <summary> 
     /// The Flash Status. 
     /// </summary> 
     public uint dwFlags; 
     /// <summary> 
     /// The number of times to Flash the window. 
     /// </summary> 
     public uint uCount; 
     /// <summary> 
     /// The rate at which the Window is to be flashed, in milliseconds. If Zero, the function uses the default cursor blink rate. 
     /// </summary> 
     public uint dwTimeout; 
    } 

    /// <summary> 
    /// Stop flashing. The system restores the window to its original stae. 
    /// </summary> 
    public const uint FLASHW_STOP = 0; 

    /// <summary> 
    /// Flash the window caption. 
    /// </summary> 
    public const uint FLASHW_CAPTION = 1; 

    /// <summary> 
    /// Flash the taskbar button. 
    /// </summary> 
    public const uint FLASHW_TRAY = 2; 

    /// <summary> 
    /// Flash both the window caption and taskbar button. 
    /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags. 
    /// </summary> 
    public const uint FLASHW_ALL = 3; 

    /// <summary> 
    /// Flash continuously, until the FLASHW_STOP flag is set. 
    /// </summary> 
    public const uint FLASHW_TIMER = 4; 

    /// <summary> 
    /// Flash continuously until the window comes to the foreground. 
    /// </summary> 
    public const uint FLASHW_TIMERNOFG = 12; 


    /// <summary> 
    /// Flash the spacified Window (Form) until it recieves focus. 
    /// </summary> 
    /// <param name="form">The Form (Window) to Flash.</param> 
    /// <returns></returns> 
    public static bool Flash(System.Windows.Forms.Form form) 
    { 
     // Make sure we're running under Windows 2000 or later 
     if (Win2000OrLater) 
     { 
      FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL | FLASHW_TIMERNOFG, uint.MaxValue, 0); 
      return FlashWindowEx(ref fi); 
     } 
     return false; 
    } 

    private static FLASHWINFO Create_FLASHWINFO(IntPtr handle, uint flags, uint count, uint timeout) 
    { 
     FLASHWINFO fi = new FLASHWINFO(); 
     fi.cbSize = Convert.ToUInt32(Marshal.SizeOf(fi)); 
     fi.hwnd = handle; 
     fi.dwFlags = flags; 
     fi.uCount = count; 
     fi.dwTimeout = timeout; 
     return fi; 
    } 

    /// <summary> 
    /// Flash the specified Window (form) for the specified number of times 
    /// </summary> 
    /// <param name="form">The Form (Window) to Flash.</param> 
    /// <param name="count">The number of times to Flash.</param> 
    /// <returns></returns> 
    public static bool Flash(System.Windows.Forms.Form form, uint count) 
    { 
     if (Win2000OrLater) 
     { 
      FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, count, 0); 
      return FlashWindowEx(ref fi); 
     } 
     return false; 
    } 

    /// <summary> 
    /// Start Flashing the specified Window (form) 
    /// </summary> 
    /// <param name="form">The Form (Window) to Flash.</param> 
    /// <returns></returns> 
    public static bool Start(System.Windows.Forms.Form form) 
    { 
     if (Win2000OrLater) 
     { 
      FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_ALL, uint.MaxValue, 0); 
      return FlashWindowEx(ref fi); 
     } 
     return false; 
    } 

    /// <summary> 
    /// Stop Flashing the specified Window (form) 
    /// </summary> 
    /// <param name="form"></param> 
    /// <returns></returns> 
    public static bool Stop(System.Windows.Forms.Form form) 
    { 
     if (Win2000OrLater) 
     { 
      FLASHWINFO fi = Create_FLASHWINFO(form.Handle, FLASHW_STOP, uint.MaxValue, 0); 
      return FlashWindowEx(ref fi); 
     } 
     return false; 
    } 

    /// <summary> 
    /// A boolean value indicating whether the application is running on Windows 2000 or later. 
    /// </summary> 
    private static bool Win2000OrLater 
    { 
     get { return System.Environment.OSVersion.Version.Major >= 5; } 
    } 
} 
+0

var Ben yöntem-uzantıları olarak kullanılırsa daha büyük olacağını inanıyorum – Jack

26

using System.Runtime.InteropServices; 
using Microsoft.Win32; 

// To support flashing. 
[DllImport("user32.dll")] 
[return: MarshalAs(UnmanagedType.Bool)] 
static extern bool FlashWindowEx(ref FLASHWINFO pwfi); 

//Flash both the window caption and taskbar button. 
//This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags. 
public const UInt32 FLASHW_ALL = 3; 

// Flash continuously until the window comes to the foreground. 
public const UInt32 FLASHW_TIMERNOFG = 12; 

[StructLayout(LayoutKind.Sequential)] 
public struct FLASHWINFO 
{ 
    public UInt32 cbSize; 
    public IntPtr hwnd; 
    public UInt32 dwFlags; 
    public UInt32 uCount; 
    public UInt32 dwTimeout; 
} 

// Do the flashing - this does not involve a raincoat. 
public static bool FlashWindowEx(Form form) 
{ 
    IntPtr hWnd = form.Handle; 
    FLASHWINFO fInfo = new FLASHWINFO(); 

    fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); 
    fInfo.hwnd = hWnd; 
    fInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG; 
    fInfo.uCount = UInt32.MaxValue; 
    fInfo.dwTimeout = 0; 

    return FlashWindowEx(ref fInfo); 
} 

Bu öğeleri içermesi gerekir ihtiyacın var.

Umarım bu yardımcı olur.

+2

Form sınıfa böyle denedim ama işe yaramadı, pencere 7 os var. – Hardik

+0

Bu, Windows 7 için çalışır. Bazı referanslar eklemeniz gerekir. Bakınız ... – MoonKnight

+0

Bu şekilde denedim ama çalışmıyor, ben pencere 7 işletim sistemi kullandım. Turuncu renk yanıp söner ancak uygulama içinde bir mesaj kutusu vardır. – Hardik

1

Bunu yapmanın çok daha kolay bir yolunu buldum! Eğer böyle bir durum için kullanıyorsanız.

.NET 4.0, C#, sadece ilk satırı o minimize değil emin olur

this.WindowState = FormWindowState.Normal; 
this.Activate(); 

kullanırsanız, ikinci satır da odak yapar. Tam olarak neden emin değilim (bunlardan biri bunu yapmaz), ancak birleştirilmiş, bu formdan bir MessageBox gösterirseniz, program görev çubuğunda turuncu yanıp söner!

+6

WindowState ve Activate() değiştirerek görev çubuğunu yanıp sönen bir şey yok. –

+1

Bu görev çubuğunda yanıp sönmez, ancak pencere diğer tüm açık pencerelerin üstünde açılır. yanıp sönen ile aynı değil, başka bir alternatif. – JOW

1

Bu sorunun oldukça eski olduğunu biliyorum, ancak MoonKnight cevabına dayanarak, bazılarının yararlı bulabileceği bir iyileştirme yaptım. Bir Form uzantısına dönüştürdüm.

public static class ExtensionMethods 
{ 
    // To support flashing. 
    [DllImport("user32.dll", CallingConvention = CallingConvention.Cdecl)] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    private static extern bool FlashWindowEx(ref FLASHWINFO pwfi); 

    //Flash both the window caption and taskbar button. 
    //This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags. 
    private const uint FLASHW_ALL = 3; 

    // Flash continuously until the window comes to the foreground. 
    private const uint FLASHW_TIMERNOFG = 12; 

    [StructLayout(LayoutKind.Sequential)] 
    private struct FLASHWINFO 
    { 
     public uint cbSize; 
     public IntPtr hwnd; 
     public uint dwFlags; 
     public uint uCount; 
     public uint dwTimeout; 
    } 

    /// <summary> 
    /// Send form taskbar notification, the Window will flash until get's focus 
    /// <remarks> 
    /// This method allows to Flash a Window, signifying to the user that some major event occurred within the application that requires their attention. 
    /// </remarks> 
    /// </summary> 
    /// <param name="form"></param> 
    /// <returns></returns> 
    public static bool FlashNotification(this Form form) 
    { 
     IntPtr hWnd = form.Handle; 
     FLASHWINFO fInfo = new FLASHWINFO(); 

     fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); 
     fInfo.hwnd = hWnd; 
     fInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG; 
     fInfo.uCount = uint.MaxValue; 
     fInfo.dwTimeout = 0; 

     return FlashWindowEx(ref fInfo); 
    } 
} 

sadece this table

İlgili konular