Aviso estilo Messenger

Iniciado por .:Weeds:., 1 Junio 2014, 18:02 PM

0 Miembros y 1 Visitante están viendo este tema.

.:Weeds:.

Bueno, el caso es que estoy creando un chat en vb.net y al recibir un nuevo mensaje he pensado de que el aviso se de como en el messenger, es decir, que se habra la ventana minimizada y parpadeando en la barra de tareas. Alguna información al respecto?

Saludos y gracias.


.:Weeds:.

Ya encontré la respuesta.

Código (vbnet) [Seleccionar]
   <DllImport("user32.dll", EntryPoint:="FlashWindow")> _
    Public Shared Function FlashWindow(ByVal hwnd As Integer, ByVal bInvert As Integer) As Integer
    End Function


Saludos.


Eleкtro

#2
En mi opinión, lo suyo sería usar la alternativa FlashWindowEx(tended) para tener un mayor control sobre como actua el flash y su personalización xD.

Ejemplo de uso, para flashear el icono de la barra de tareas hasta que la ventana se vuelva activa:
Código (vbnet) [Seleccionar]
Me.FlashWindow(Me.Handle, FlashFlags.TaskBar Or FlashFlags.Until_Foreground)

Te dejo el código completo que escribí, por si te sirve:

Código (vbnet) [Seleccionar]
    ''' <summary>
    ''' Flashes the specified window.
    ''' It does not change the active state of the window.
    ''' For more info see here:
    ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms679347%28v=vs.85%29.aspx
    ''' </summary>
    ''' <param name="pwfi">A pointer to a FLASHWINFO structure.</param>
    ''' <returns>
    ''' The return value specifies the window's state before the call to the FlashWindowEx function.
    ''' If the window caption was drawn as active before the call, the return value is nonzero.
    ''' Otherwise, the return value is zero.
    ''' </returns>
    <System.Runtime.InteropServices.DllImport("user32.dll")>
    Private Shared Function FlashWindowEx(
            ByRef pwfi As FLASHWINFO
    ) As <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
    End Function

    ''' <summary>
    ''' Contains the flash status for a window and the number of times the system should flash the window.
    ''' For more info see here:
    ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms679348%28v=vs.85%29.aspx
    ''' </summary>
    <System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>
    Public Structure FLASHWINFO

        ''' <summary>
        ''' The size of the structure, in bytes.
        ''' </summary>
        Public cbSize As UInteger

        ''' <summary>
        ''' A handle to the window to be flashed.
        ''' The window can be either opened or minimized.
        ''' </summary>
        Public hwnd As IntPtr

        ''' <summary>
        ''' The flash status.
        ''' </summary>
        Public dwFlags As FlashFlags

        ''' <summary>
        ''' The number of times to flash the window.
        ''' </summary>
        Public uCount As UInteger

        ''' <summary>
        ''' The rate at which the window is to be flashed, in milliseconds.
        ''' If dwTimeout is zero, the function uses the default cursor blink rate.
        ''' </summary>
        Public dwTimeout As UInteger

    End Structure

    ''' <summary>
    ''' Contains the flash status for a window.
    ''' </summary>
    <System.ComponentModel.Description("Enum used as 'FlashFlags' parameter in 'FlashWindow' function.")>
    <Flags>
    Public Enum FlashFlags As Integer

        ''' <summary>
        ''' Stop flashing.
        ''' The system restores the window to its original state.
        ''' </summary>   
        [Stop] = 0I

        ''' <summary>
        ''' Flash the window caption.
        ''' </summary>
        Caption = 1I

        ''' <summary>
        ''' Flash the taskbar button.
        ''' </summary>
        TaskBar = 2I

        ''' <summary>
        ''' Flash both the window caption and taskbar button.
        ''' This is equivalent to setting the 'Caption Or TaskBar' flags.
        ''' </summary>
        All = 3I

        ''' <summary>
        ''' Flash continuously, until the 'Stop' flag is set.
        ''' </summary>
        Until_Stop = 4I

        ''' <summary>
        ''' Flash continuously until the window comes to the foreground.
        ''' </summary>
        Until_Foreground = 12I

    End Enum

    ''' <summary>
    ''' Flashes the specified window.
    ''' It does not change the active state of the window.
    ''' </summary>
    ''' <param name="Handle">
    ''' Indicates the handle to the window to flash.
    ''' </param>
    ''' <param name="FlashFlags">
    ''' Indicates the flash flags.
    ''' </param>
    ''' <param name="FlashCount">
    ''' Indicates the number of times to flash the window.
    ''' </param>
    ''' <param name="FlashDelay">
    ''' Indicates the rate at which the window is to be flashed, in milliseconds.
    ''' If dwTimeout is zero, the function uses the default cursor blink rate.
    ''' </param>
    ''' <returns>
    ''' The return value specifies the window's state before the call to the FlashWindowEx function.
    ''' If the window caption was drawn as active before the call, the return value is nonzero.
    ''' Otherwise, the return value is zero.
    ''' </returns>
    Public Function FlashWindow(ByVal [Handle] As IntPtr,
                                ByVal FlashFlags As FlashFlags,
                                Optional ByVal FlashCount As UInteger = UInteger.MaxValue,
                                Optional ByVal FlashDelay As UInteger = 0UI) As Boolean

        Dim fInfo As New FLASHWINFO()

        With fInfo

            .cbSize = Convert.ToUInt32(System.Runtime.InteropServices.Marshal.SizeOf(fInfo))
            .hwnd = [Handle]
            .dwFlags = FlashFlags
            .uCount = FlashCount
            .dwTimeout = FlashDelay

        End With

        Return FlashWindowEx(fInfo)

    End Function


Saludos