2011-02-03 19 views
9


Kullanıcının çeşitli formları açmasına izin veren bir programım var. Belirli bir hat (örneğin: 30 saniye geçtikten sonra), odağı çalmadan, olayı tetikleyen Form üzerinde kullanıcı dikkati çekmem gerekiyor. ZatenOdağı çalmadan kullanıcı dikkatini çekin

f.TopMost = true; 

ile üstte formu almak ama bunun için bazı alternatif uygulamak istiyorum. Çerçevenin sınır rengini değiştirmek neredeyse imkansız bir görev gibi göründüğünden (bu çözüm en iyisi olurdu), birinin odaklanmadan dikkat çekmesi konusunda bir fikri var mı?

cevap

19

Seçenek A: Windows API'sinden FlashWindowEx kullanmanız gerekir. Bu, .NET'te mevcut değildir, bu yüzden PInvoke kullanmanız gerekir.

Seçenek B: Sistem tepsisinden bir balon ucu kullanın. Bu, .NET'te yerleşiktir, ancak uygulamanızın istemeyebileceğiniz bir bildirim simgesi kullanmasını gerektirir. Burada daha fazla bilgi: http://pinvoke.net/default.aspx/user32.FlashWindowEx

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

kullanıcı tanımlı türler:

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

pInvoke.net iyi örnek vardır: İşte

http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.showballoontip.aspx Seçenek A nasıl kullanılacağı için örnektir

Notlar:

//Stop flashing. The system restores the window to its original state. 
public const UInt32 FLASHW_STOP = 0; 
//Flash the window caption. 
public const UInt32 FLASHW_CAPTION = 1; 
//Flash the taskbar button. 
public const UInt32 FLASHW_TRAY = 2; 
//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 FLASHW_STOP flag is set. 
public const UInt32 FLASHW_TIMER = 4; 
//Flash continuously until the window comes to the foreground. 
public const UInt32 FLASHW_TIMERNOFG = 12; 

İpuçları & Hileler:

Lütfen biraz ekleyin!

Örnek Kod:

/// <summary> 
/// Flashes a window 
/// </summary> 
/// <param name="hWnd">The handle to the window to flash</param> 
/// <returns>whether or not the window needed flashing</returns> 
public static bool FlashWindowEx(IntPtr hWnd) 
{ 
    FLASHWINFO fInfo = new FLASHWINFO(); 

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

    return FlashWindowEx(ref fInfo); 
} 

... İşte


/// Minor adjust to the code above 
/// <summary> 
/// Flashes a window until the window comes to the foreground 
/// Receives the form that will flash 
/// </summary> 
/// <param name="hWnd">The handle to the window to flash</param> 
/// <returns>whether or not the window needed flashing</returns> 
public static bool FlashWindowEx(Form frm) 
{ 
     IntPtr hWnd = frm.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); 
} 
resmi Microsoft örnektir: Windows 7'de http://msdn.microsoft.com/en-us/library/ms679347(v=vs.85).aspx

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

    [StructLayout(LayoutKind.Sequential)] 
    public 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 FlashWindowFlags dwFlags; //uint 
     /// <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; 
    } 


    public enum FlashWindowFlags : uint 
    { 
     /// <summary> 
     /// Stop flashing. The system restores the window to its original state. 
     /// </summary> 
     FLASHW_STOP = 0, 

     /// <summary> 
     /// Flash the window caption. 
     /// </summary> 
     FLASHW_CAPTION = 1, 

     /// <summary> 
     /// Flash the taskbar button. 
     /// </summary> 
     FLASHW_TRAY = 2, 

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

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

     /// <summary> 
     /// Flash continuously until the window comes to the foreground. 
     /// </summary> 
     FLASHW_TIMERNOFG = 12 
    } 


    public static bool FlashWindow(IntPtr hWnd, 
            FlashWindowFlags fOptions, 
            uint FlashCount, 
            uint FlashRate) 
    { 
     if(IntPtr.Zero != hWnd) 
     { 
      FLASHWINFO fi = new FLASHWINFO(); 
      fi.cbSize = (uint)Marshal.SizeOf(typeof(FLASHWINFO)); 
      fi.dwFlags = fOptions; 
      fi.uCount = FlashCount; 
      fi.dwTimeout = FlashRate; 
      fi.hwnd = hWnd; 

      return FlashWindowEx(ref fi); 
     } 
     return false; 
    } 

    public static bool StopFlashingWindow(IntPtr hWnd) 
    { 
     if(IntPtr.Zero != hWnd) 
     { 
      FLASHWINFO fi = new FLASHWINFO(); 
      fi.cbSize = (uint)Marshal.SizeOf(typeof(FLASHWINFO)); 
      fi.dwFlags = (uint)FlashWindowFlags.FLASHW_STOP; 
      fi.hwnd = hWnd; 

      return FlashWindowEx(ref fi); 
     } 
     return false; 
    } 
+0

'NotifyIcon' kullanma hakkında iyi çağrı! –

+0

Önemli: Windows 7'de bazı kullanıcılar bunu çalışmıyor olarak bildirmişlerdir. Bazı araştırmalardan sonra, uygulamanızın birden fazla penceresi varsa ve bu pencereden başka bir pencereyi yanıp söndürürken bu pencerelerden herhangi biri etkinse, bunun işe yaramayacağını anladım. Sadece programınızdaki tüm pencereler etkin değilse çalışır. İlk senaryoda sıkışmışsanız, eski api FlashWindow kullanın: http://pinvoke.net/default.aspx/user32/FlashWindow.html – tunafish24

7

, bir ilerleme çubuğu bir form onun görevinde temsil edilir r düğmesi; Bunu kaldırabilirsin. Ayrıca yeni mesaj aldığınızda IM programlarının yaptığı gibi görev çubuğu düğmesini vurgulamanın da bir yolu olmalı.

+0

Sadece yanıp söner yerine görev çubuğu düğmesine nasıl vurgulanacağını görmek isterim ... Bunu yapan iyi kod örnekleri bulmada sorun yaşıyorum. –