NEWS

Hướng dẫn tạo hiệu ứng nhấp nháy ứng dụng dưới taskbar (flash and blink in taskbar) VB.NET

Hướng dẫn tạo hiệu ứng nhấp nháy ứng dụng dưới taskbar (flash and blink in taskbar) VB.NET
Đăng bởi: Thảo Meo - Lượt xem: 11638 09:09:30, 16/01/2017C#   In bài viết

Hôm nay, mình xin hướng dẫn các bạn làm hiệu ứng nhấp nháy ứng dụng dưới thanh taskbar (flash and blink)

Ví dụ: bạn nào đã từng dùng Yahoo, các bạn sẽ thấy khi có tin nhắn đến, thì của sổ chat ở dưới taskbar của chúng ta nhấp nháy hình màu cam. 

- Đầu tiên, các bạn thiết kế form có giao diện như hình bên dưới:

flash_and_blink_taskbar

- Bài viết này rất đơn giản bạn chỉ cần sử dụng hàm API của window

Bước 1: Đầu tiên các bạn tạo một class với tên là WindowApi với nội dung như sau

Public Class WindowsApi
    Private Declare Function FlashWindowEx Lib "User32" (ByRef fwInfo As FLASHWINFO) As Boolean

    Public Enum FlashWindowFlags As UInt32
        ' Stop flashing. The system restores the window to its original state.
        FLASHW_STOP = 0
        ' Flash the window caption.
        FLASHW_CAPTION = 1
        ' Flash the taskbar button.
        FLASHW_TRAY = 2
        ' Flash both the window caption and taskbar button.
        ' This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
        FLASHW_ALL = 3
        ' Flash continuously, until the FLASHW_STOP flag is set.
        FLASHW_TIMER = 4
        ' Flash continuously until the window comes to the foreground.
        FLASHW_TIMERNOFG = 12
    End Enum

    Public Structure FLASHWINFO
        Public cbSize As UInt32
        Public hwnd As IntPtr
        Public dwFlags As FlashWindowFlags
        Public uCount As UInt32
        Public dwTimeout As UInt32
    End Structure

    Public Shared Function FlashWindow(ByRef handle As IntPtr, ByVal FlashTitleBar As Boolean, ByVal FlashTray As Boolean, ByVal FlashCount As Integer) As Boolean
        If handle = Nothing Then Return False

        Try
            Dim fwi As New FLASHWINFO
            With fwi
                .hwnd = handle
                If FlashTitleBar Then .dwFlags = .dwFlags Or FlashWindowFlags.FLASHW_CAPTION
                If FlashTray Then .dwFlags = .dwFlags Or FlashWindowFlags.FLASHW_TRAY
                .uCount = CUInt(FlashCount)
                If FlashCount = 0 Then .dwFlags = .dwFlags Or FlashWindowFlags.FLASHW_TIMERNOFG
                .dwTimeout = 0 ' Use the default cursor blink rate.
                .cbSize = CUInt(System.Runtime.InteropServices.Marshal.SizeOf(fwi))
            End With

            Return FlashWindowEx(fwi)
        Catch
            Return False
        End Try
    End Function
End Class

Bước 2: Viết sự kiện cho nút thực hiện

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim res = WindowsApi.FlashWindow(Process.GetCurrentProcess().MainWindowHandle, True, True, 3)
    End Sub

XEM VIDEO DEMO

CHÚC CÁC BẠN THÀNH CÔNG!

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

Hướng dẫn tạo hiệu ứng nhấp nháy ứng dụng dưới taskbar (flash and blink in taskbar) VB.NET
Đăng bởi: Thảo Meo - Lượt xem: 11638 09:09:30, 16/01/2017C#   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.