How to set the text blinking?

Posted on 1998-10-15
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 50 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

914 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now