Real Software Forums
http://forums.realsoftware.com/

blink\flash a text in a console application
http://forums.realsoftware.com/viewtopic.php?f=6&t=41958
Page 1 of 1

Author:  spacewalker [ Mon Dec 26, 2011 12:14 pm ]
Post subject:  blink\flash a text in a console application

Hi,

is there a way to blink (flash) a text in a console application?

I've tried to use API call SetConsoleTextAttribute with the constant COMMON_LVB_REVERSE_VIDEO ... but no success

I use XP and Win7

Heinz

Author:  Wayneg@axisdirect.co.nz [ Mon Jan 30, 2012 7:23 pm ]
Post subject:  Re: blink\flash a text in a console application

You could try something like this (Place in app.run event). Only works on the last displayed line though.

[code]
[code]Dim b As Boolean
Dim s As String = "Hello World"

While True
stdout.Write chr(13) ' Moves the cursor back to the beginning of the line
If b Then
stdout.Write " " ' Needs to be at least as long as s
Else
stdout.Write s
End If
b = not b ' toggles b
DoEvents(500) ' Sleeps the app for 500ms
Wend[/code]
[/code]

Author:  charonn0 [ Mon Jan 30, 2012 11:59 pm ]
Post subject:  Re: blink\flash a text in a console application

One way to do this is to use a timer that alternates between writing your message and then clearing it.

I will assume that since you say you've tried SetConsoleTextAttribute that you know how to get a handle to the console's output buffer. So something like this:

Declare Function SetConsoleCursorPosition Lib "Kernel32" (cHandle As Integer, info As COORD) As Boolean
Dim info As New MemoryBlock(4)
info.UInt16(0) = 0 //The X coordinate of the cursor
info.UInt16(2) = 0 //The Y coordinate of the cursor
Call SetConsoleCursorPosition(StdOutHandle, coords) Then //StdOutHandle is the output buffer's handle


Using the timer, first write your message to the console. Then, on the second time your timer fires, move the cursor's X coordinate to 0 (the beginning of the line) and print a space for each character in your message, overwriting it with blanks, and then move the cursor back to the beginning of the line. On the third time around print the message again. Repeat, alternately clearing and writing your message.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/