The FlashWindow function flashes the specified window one time. This visual color change is done by toggling the window state between active and inactive. The window's caption color reflects this toggling. In addition, the taskbar window button flashes a contrasting color.
Flashing a window means changing the appearance of its caption bar as if the window were changing from inactive to active status, or vice versa. (An inactive caption bar changes to an active caption bar; an active caption bar changes to an inactive caption bar.)
Typically, a window is flashed to inform the user that the window requires attention but that it does not currently have the keyboard focus.
The FlashWindow function flashes the window only once; for repeated flashing, the application should create a system timer.
Repeated flashing requires a timer. The time intervals may vary according to your preference. Delays of 250 milliseconds to 500 milliseconds work well. This next demo causes Window flashing every 300 milliseconds.
' Flashing Window repeatedly using a timerWindowWidth=320WindowHeight=350Button#demo.btn," Stop Flashing ",[StopFlashing], UL,100,50,100,30Open"Flashing Window Caption"forWindowas#demo
#demo "Trapclose [XbyTrap]"
hDemo =hWnd(#demo)Timer300,[FlashCaption]Wait[FlashCaption]CallDLL#user32,"FlashWindow", _
hDemo asuLong, _
1asLong, _
FlashWindow asLongWait[StopFlashing]Timer0Wait[XbyTrap]Timer0Close#demo
End
Conditional Flashing Using a Timer
A practical use of the FlashWindow function is to get the user's attention when the application doesn't have keyboard focus. This final snippet demonstrates the use of flashing when the window is minimized. A timer checks for the iconic state of the window. While the iconic state is 1 (the window has been minimized), the taskbar window button flashes. during an iconic state of 0 (non-minized), no flashing occurs. The first demo uses branch labels as event handlers. The second demo uses subs as event handlers. The use of WAIT inside the CheckIconic Sub prevents the timer from causing the window to lock-up.
' Flashing Window Demo #2a - [BranchLabels] as Event Handlers' Taskbar Window Button flashes whenever window is minizedOpen"Flashes When Minized"forWindowas#demo
#demo "Trapclose [XbyTrap]"
hDemo =hWnd(#demo)Timer300,[CheckIconic]Wait[CheckIconic]
IsIconic = IsIconic(hDemo)If IsIconic <>0ThenCallDLL#user32,"FlashWindow", _
hDemo asuLong, _
1asLong, _
result asLongEndIfWaitFunction IsIconic(hApp)CallDLL#user32,"IsIconic", _
hApp asuLong, _
0asLong, _
IsIconic asLongEndFunction[XbyTrap]Timer0Close#demo
End
If your Liberty BASIC program is working in the background and has encountered a situation where you require user intervention, use the FlashWindow function. Check to see if the handle of your application window matches the return of the GetActiveWindow function. If no match, then set up a timer to flash the window until your application window becomes the active window.
The FlashWindow Function
The FlashWindow function flashes the specified window one time. This visual color change is done by toggling the window state between active and inactive. The window's caption color reflects this toggling. In addition, the taskbar window button flashes a contrasting color.
Flashing a Window
Repeatedly flashing a window grabs the user's attention. From the Microsoft Developer Network (MSDN)
Repeated flashing requires a timer. The time intervals may vary according to your preference. Delays of 250 milliseconds to 500 milliseconds work well. This next demo causes Window flashing every 300 milliseconds.
Conditional Flashing Using a Timer
A practical use of the FlashWindow function is to get the user's attention when the application doesn't have keyboard focus. This final snippet demonstrates the use of flashing when the window is minimized. A timer checks for the iconic state of the window. While the iconic state is 1 (the window has been minimized), the taskbar window button flashes. during an iconic state of 0 (non-minized), no flashing occurs. The first demo uses branch labels as event handlers. The second demo uses subs as event handlers. The use of WAIT inside the CheckIconic Sub prevents the timer from causing the window to lock-up.
Grabbing the User's Attention
If your Liberty BASIC program is working in the background and has encountered a situation where you require user intervention, use the FlashWindow function. Check to see if the handle of your application window matches the return of the GetActiveWindow function. If no match, then set up a timer to flash the window until your application window becomes the active window.