How to set the text blinking?

Posted on 1998-10-15
Medium Priority
Last Modified: 2010-05-18
I want to set the text on my dialog blinking?
How to do it, please help!
I'm not using MFC, but WIN32 SDK.
Question by:softyan
  • 2

Accepted Solution

Answers2000 earned 200 total points
ID: 1253550
Unfortunately there isn't a "flashing" attribute for dialog text under Windows.  This means you have to flash it yourself.

Also unfortunately the FlashWindow API (if you heard of it) is no help.  It simply flashes the window caption.  Assuming you mean a control on the dialog - e.g. a static.  This is no help either.

Okay - here are the steps:
1. Add a static UINT to your dialog which is the Timer Id

static UINT uTimerId = 0 ;

2. Use the SetTimer API call to create a Timer.  Do this  in WM_INITDIALOG.

uTimerId = SetTimer( hDlg, 1, 1000 /* Time in Millisecs */, NULL ) ;

3. Before closing your dialog kill the timer, (e.g. before calling EndDialog in response to the OK button)

if ( uTimerId != 0 )
  KillTimer( hDlg, uTimerId ) ;

4. Process the WM_TIMER message sent to your dialog and causing flashing here.

case WM_TIMER:
  /* Flashing code */

5. What is flashing code - I'll assume you just want to make the a control appear/reappear.  If yes - try this

HWND hWndItem = GetDlgItem( hDlg, ID_CONTROL ) ; /* ID_CONTROL = the id of the control - e.g. a static - to link
if ( IsWindowVisible(hWndItem) )
   ShowWindow(  hWndItem, SW_HIDE ) ;
} else
   ShowWindow( hWndItem, SW_SHOW ) ;

If you don't like #5 change the code to cause whatever kind of flashing you want


Author Comment

ID: 1253551
Can i ask u a question?
Your suggestion is great, but how if i want to change the colour of the static text?
I will increase the point to 70 if u can give me a guide!

Expert Comment

ID: 1253552
You can't increase the pts - as you've already accepted it!

To change the color process the WM_CTLCOLORSTATIC message

To make it flash:
- use my code above

- add variables to dlg proc :-
 static COLORREF m_crText[2] ;
 static COLORREF m_crBack[2] ;
 static HBRUSH m_brush[2] ;
 int m_nWhichColor = 0 ;

m_crText[0] = RGB(255,0,0) ; // red text
m_crText[1] = RGB(0,0,255) ; // blue text
m_crBack[0] = RGB(255,255,255) ; // white background
m_crBack[1] = RGB(0,255,0) ; // green background
m_brush[0] = ::CreateSolidBrush( m_crBack[0] ) ;
m_brush[1] = ::CreateSolidBrush( m_crBack[1] ) ;
m_nWhichColor = 0 ;

- when dialog exits
::DeleteObject( m_brush[0] ) ;
::DeleteObject( m_brush[1] ) ;

- modify step #5 of my original answer

m_nWhichColor ^= 1 ; // flip between 1 and 0
HWND hWndItem = GetDlgItem( hDlg, ID_CONTROL ) ; /* ID_CONTROL = the id of the control - e.g. a static - to link
::InvalidateRect( hWndItem, NULL, FALSE ) ;
::UpdateWindow( hWndItem ) ;

- for WM_CTLCOLORSTATIC, do something like:

HWND hWndItem = GetDlgItem( hDlg, ID_CONTROL ) ;

if ( hWndItem == ((HWND)lParam) )
  pDC->SetTextColor( m_crText[m_nWhichColor] ) ;
  pDC->SetBkColor( m_crBack[m_nWhichColor] ) ;
  return m_brush[m_nWhichColor] ;
// otherwise call DefWndProc

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question