Make the taskbar app icon flash on Windows

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Make the taskbar app icon flash on Windows

Post by Tourist Trap »

Hi,

I recently needed to monitor my WIFI which was not stable (due to, supposedly, the load on the network while people were under quarantine in France).
When you loose the network, that's quite silent on windows, so I needed something flashy like the app icon blinking. I used vb.net for the network event, but here is the winapi function that makes the icon flash:

Code: Select all

'adapted from https://stackoverflow.com/questions/23565087/how-to-flash-blink-taskbar-icon-in-vb-net

#include "windows.bi"


'get your window's handle
dim as HANDLE hwndThisWindow = GetForegroundWindow()

'this will make it flash once
FlashWindow(hwndThisWindow, true)

'to make it flash more do as follow in order to use FlashWindowEx:
Enum FlashWindowFlags
    ' 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

var FlashTitleBar = true
var FlashTray = true
var FlashCount = 5

Dim fwi As FLASHWINFO
With fwi
    .hwnd = hwndThisWindow
    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(SizeOf(fwi))
End With

'this will flash 5 times
FlashWindowEx(@fwi)


getKey()
Thanks.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Make the taskbar app icon flash on Windows

Post by dodicat »

It flashes five times.
success.
I have never used vb.net.
Is it an event driven interpreter/compiler like the other windows vb's (5/6)?
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Make the taskbar app icon flash on Windows

Post by Tourist Trap »

dodicat wrote:It flashes five times.
success.
I have never used vb.net.
Is it an event driven interpreter/compiler like the other windows vb's (5/6)?
Hi dodi,

thanks for testing. About vb.net it's what comes shipped with Visual Studio (you can grab the 'community edition' as they call it for free and without any registration for 1 month, then would have to register in order to keep using it) . This is Microsoft stuff so the advantage is that it is well fitted for Windows.

That's not quite like VB6 (it's much more complicated), but for one aspect the windows forms are avaiable and easy to draw as usual. That's why I use it myself, since textboxes, directory browsers and so on are quickly added. So that may simply save time when you don't have much .

VB.net is compiled to the common langage runtime (clr), which is common to C# and other languages shipped with Visual Studio, that has the advantage of making the .net languages compatible each others, you can melt modules from different ones of them(which I neved did, but why not...).

Second thing is that this is an "all-is-object" language. Even the Integer type is embedded in a class, with various methods like toString() and so on.
There is not much pointer support. Nor it is usual at first to use things like the windows api, because there will be in general a embedded equivalent version of all of this (though potentially less efficient).

The thing that can be great is when you don't see too much how you would deal with something and it is avaiable in the form of an object already designed for it. For instance for the network event, I just had to add this to the code: "AddHandler NetworkChange.NetworkAddressChanged, AddressOf AddressChangedCallback" in order to deal with the event. In the callback is where I make stuff blink and all. The class is the NetworkChange that is inherited from NetworkInformation that comes in a dll shipped with VS.

Of course it is possible to get the same result in FB, and in general it will be faster I'm pretty sure for it has less overhead. But it relies on the winApi anyway. However I don't know if it would be possible to use some of the vb.net dlls in FB. I think not due to the 'CLR' fence, but I'm not quite clear about this at all.
Post Reply